#archived-code-general

1 messages ยท Page 390 of 1

latent latch
#

Are we sure we're not talking about trying to rotate this via AngleAxis?

#

Rotating a quaternion directly does not define the up axis

leaden ice
#

Working for me

#

Oh wait

#

I see it when x is 90

#

I think you're just experiencing gimbal lock

#

This is the problem with the euler<>quaternion conversion and gimbal lock basically

bitter quarry
#

is there a way to represent rotation without Quaternion or to have something be converted to it?

leaden ice
#

I usually just use an empty GameObject

#

You can just use a Vector3 too

#

for euler angles

bitter quarry
#

true. looks the same in the inspector

latent latch
#

If you're doing 3D, I suggest just learning AngleAxis and running that in OnValidate

#

If you're running into gimble

leaden ice
#

Basically yeah the problem is the conversion from eulers -> Quaternion -> eulers that the inspector does for quaternions

#

Since euler angles aren't unique

bitter quarry
#

ill try to use a Vector3 and see how it goes

latent latch
#

^ Can convert it to onvalidate but was using to automate it for some testing

bitter quarry
#

its okay, using a Vector3 and passing it into Quaternion.Euler worked

#

thanks for helping :>

hardy pasture
#

How to set animations on the character from C# components(2D)?

cosmic rain
hardy pasture
#

It's the default Animation, Animator and Animation Clip classes

#

Sprite animations

#

But I can't find how I can switch the state from outside

#

Like there is no function like SetState("Idle") to force the state back to idle

hexed pecan
#

In the very doc you just linked

#

I usually use parameters and transitions though

hardy pasture
#

Thank you

#

Yeah I missed it and was confused how to do it then

hardy pasture
#

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - https://www.patreon.com/sasquatchbgames
Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH

In this Unity tutorial, We'll use, from the ground up, the State Machine programming pattern to setup some simple logic for o...

โ–ถ Play video
#

To avoid the parameters/flags and checks hell

#

And just play the animation when character enters the state

vestal arch
#

wdym, there's not really a hell for that

hexed pecan
#

Are you using state machine behaviours?

hardy pasture
vestal arch
#

at the most direct, basic level, you could send a trigger for changing state, so you can use the animator tree to manage transitions correctly

#

having a state machine is a separate idea from using transitions in the animator
you can do both, one or the other, or neither

hexed pecan
worthy shadow
#

How can I have a public property (as opposed to a field) exposed in the inspector?

hardy pasture
knotty sun
vestal arch
#

(you can ctrl+z in the message box to restore your message)

hardy pasture
hexed pecan
#

That is up to you

#

If the animator provides all the functionality that you need for state machine then sure

stable geyser
#

Hey all, general programming question here geared at C#. Let's say you have a base class with a virtual method that returns a bool on whether it was successful. Then I inherit from that class and override that method, using the original base method's logic, but wanting to add onto it additional failure scenarios in the override method. What is the best way to determine if the base method succeeded before I bother processing the child method's logic?

chilly surge
#

Check the return value of the base method.

stable geyser
#

Oh? Sorry how do you do that?

vestal arch
#

an if

stable geyser
#

Oh I see. if(base.Foo()) // Do something

#

Thank you ๐Ÿ™‚

broken nest
#

public override bool DoTheThing()
{
bool parentDidTheThing = base.DoTheThing();
bool childDidTheThing = stuffToDo <= stuffDone;
return parentDidTheThing && childDidTheThing;
}

vestal arch
#

well, you would check for a failure in the base method before doing any of your own logic

broken nest
#

You might, if the only thing the method does is check. If you want it to do some stuff anyway, and the return whether or not it's done, you might want to run it regardless of whether the base method failed

stable geyser
#

I don't know why I was struggling with that so much lol. I feel silly now it was a rather simple and obvious solution, but for whatever reason it didn't occur to me and when I googled it people were saying it can't be done and I was like...no way

indigo verge
#

Thought for later that just struck me like lightning;

I wonder if there would be any major downsides to just... Using bones to drive animated behaviors.

Like, having a "Gun Bone" that just floats over in the corner, and when its Y Value is set to 1, a held gun fires.

#

Am I crazy, or is that a thing that people do

heady iris
#

This sounds like something you'd rig up in Blender

#

But it does not make any sense when you can just write code

#

If you want something to happen at a specific point in an animation, that's what animation events are for

wheat spruce
#

I love how concise you can make C#, going from

if(Input.GetMouseButton(0))
{
  if(MenuEvents.SelectedBrush == 0)
  {
    brushState = 1f;
  }
  else if(MenuEvents.SelectedBrush == 1)
  {
    brushState = -1f;
  }
}
else
{
  brushState = 0f;
}```to
```cs
float brushState = Input.GetMouseButton(0) ? (MenuEvents.SelectedBrush == 0 ? 1f : -1f) : 0f;```
#

I always wonder how far C# can actually be pushed to make stuff short like that

heady iris
#

You can get a little too clever..

#
        public override Vector3? Destination => brain.entity.TryGetPerception(target, out var perception)
            ? perception.DispersedLocation
            : null;
wheat spruce
#

oh absolutely

heady iris
#

I'm thinking about turning this back into a multi-statement property

#

it's a long boy

hardy pasture
#

After pushing and then cloning the project, when I open it in new place with the same editor, I get a

Assets\Scripts\CharacterMovement.cs(21,12): error CS0246: The type or namespace name 'InputActionReference' could not be found (are you missing a using directive or an assembly reference?)
heady iris
#

You can check in the package manager window

hardy pasture
#

Apparently, it didn't. How do I make it get installed automatically then?

heady iris
#

What version control system are you using? Git?

hardy pasture
#

Yes

wheat spruce
#

the first thing I discovered like that, was how you can write strings like

$"The dice rolled {diceValue}, you have {goldAmount} in the bank"``` instead of the much (imo) uglier ```cs
"The dice rolled " + diceValue + ", you have " + goldAmount + " in the bank"```
heady iris
#

did you put the entire Packages folder into your .gitignore?

#

It sounds like the package manifest is not being version controlled

heady iris
#

It's significantly tidier

#
$"Oh god it broke: {oopsPercentage:P0}"
wheat spruce
#

mhmm, its saved me a lot of headache over the years

#

it was only when I looked at a mess of "blah blah" + value + "blah" + value + "blah" + value + "blah blah blah" I was sure you could write it better

#

it was only when I saw some C++ code which had a very odd way of writing strings, that got me thinking

vestal arch
#

sprintf?

heady iris
#

yum

heady iris
somber tapir
#

Is there a way to expand a TMP_Dropdown via code?

heady iris
#

I was just digging around in the source code last night

#

Let's see...

wheat spruce
#

its something like "you have %x gold and %d health", x:goldValue, d:healthValue, but thats definitley incorrectly written

vestal arch
#

(format strings are pretty common, and even interpolated strings like in python or c# have format-string-like format specifiers)

#

yep that's a format string

heady iris
#

Here it is.

#

Just call Show() on it

wheat spruce
#

I think C# has a something similar where the parameters come after a string, ive never needed to write strings that way though

heady iris
#

This gets called by OnSubmit and OnPointerClick, both of which are ways to open the dropdown

heady iris
#

well, an array of parameters -- it uses the params keyword

vestal arch
#
char buf[51];
snprintf(buf, 50, "you have %d gold and %d health", goldValue, healthValue);
heady iris
#

mmmm, snprintf

#

even more letters

wheat spruce
#

whats the use case for it?

heady iris
vestal arch
#

i really love/hate c's thing with method pfxs/sfxs lmao

heady iris
#

String interpolation demands that the format string be a compile-time constant

#

I'm pretty sure that everything compiles into a String.Format call eventually, too

chilly surge
wheat spruce
#

There should be a "collection of little tricks and fancy features that make life a little easier" for C#, there's a lot of little things that I've found over the years and even now I still occasionally learn something new

hardy pasture
heady iris
#

That might be talking about NuGet packages

hardy pasture
#

What does that mean. Nuget packages restore? But how would it know which to restore?

heady iris
#

when I search up "package restore", I get lots of people talking about NuGet

#

which is an unrelated package manager for C# packages

#

I use "NuGet for Unity", so I have some assemblies in my project provided by it

#

I have that specific folder ignored, but not every folder named Packages

vestal arch
heady iris
#

yeag

#

/Packages is also where you put "embedded" packages

#

you can copy things out of the library's package cache to embed them in your project so you can make changes

wheat spruce
#

Whats NuGet for Unity?

#

I get what the name means

heady iris
#

I actually know very little about NuGet beyond using it to grab some libraries

wheat spruce
#

ooh, it runs in the editor

heady iris
#

also, one little suggestion for the .gitignore

wheat spruce
heady iris
#

I also include:

*mono_crash*.json
*mono_crash*.blob

.DS_Store
*.blend1
*autosave*.spp
#

The first two are for crash logs

#

and then you've got good ol' DS_Store and some autosave files

hardy pasture
#

That should fix it

vestal arch
#

oh that's weird, i swear it used to include .DS_Store

heady iris
#

I also exclude the file that includes my steam password kekw

warm kite
#

When I create a server build of my game, run it, then press Ctrl + C or close the console window, will Unity still perform its cleanup (like OnDestroy) like it would when I close the window in a client build?

heady iris
#

SIGINT is pretty gentle. I'd expect it to shut down normally

wet moss
#

Hi, I'm new here. Where do I ask for help with writing code? There's something I need help with in my project

wet moss
#

Thanks

warm kite
#

Okay, thanks for the quick replies!

heady iris
#
[RuntimeInitializeOnLoadMethod]
static void Test() {
  Application.quitting += () => Debug.Log("Quitting!");
}
wet moss
#

I'm currently working on my PlayerController for a 2D platformer and I'm trying to make an acceleration/deceleration movement style similar to classic Sonic. I have the acceleration part down but the tutorial I followed didn't go into deceleration. How do I show my code?

thin aurora
#

Though you seem to override something so maybe that's not possible...

tawny elkBOT
heady iris
#

The important thing is that it doesn't cause a change in state

#

That would be very surprising

thin aurora
#

Very true

#

Just that properties are generally not assumes to be complex in any way

#

Or depending on other data apart from simple data

warm kite
wet moss
# thin aurora !code

Thank you! Here's the relevant code

    [SerializeField] float jumpForce;
    public float accelerationSpeed;
    float moveSpeed = 0f;
    float maxSpeed = 1000f;
    float HorizontalInput;
    Rigidbody2D rb;

void Update()
 {
     HorizontalInput = Input.GetAxis("Horizontal");
     
     if (HorizontalInput != 0f && moveSpeed <= maxSpeed) 
     {
         moveSpeed += Time.deltaTime * accelerationSpeed;
     }

     if (HorizontalInput == 0f) 
     { 
         moveSpeed = 0f;
     }
 }

 private void FixedUpdate()
 {
     rb.velocity = new Vector2(moveSpeed * HorizontalInput * Time.deltaTime, rb.velocity.y);
 }```
robust dome
#

i think AddForce should give you the movement you are looking for

vestal arch
#

if you want to decelerate at the same rate, you could just do moveSpeed -= for the opposite effect as the the acceleration

robust dome
#

although i dontยดt recommend using Addforce every frame.

vestal arch
#

if you want a different rate, you could do the same with a separate coefficient

wet moss
vestal arch
#

wdym by that?

leaden ice
heady iris
#

well, you wouldn't use AddForce(rb.velocity) or something

wet moss
#

let me check again

heady iris
#

You'd apply a steady amount of force in each fixed update.

leaden ice
vestal arch
#

alternatively, you could achieve the effect with physics; use AddForce to apply acceleration, and then let linear drag/friction handle deceleration

leaden ice
#

it's just saying "Is horizontal input not zero? If so, accelerate to the right"

#

So even if you hold left here, you will go right

vestal arch
leaden ice
#

that's... weird

vestal arch
#

which wouldn't work for controller input, but for button input it works even though it doesn't make sense semantically

wet moss
vestal arch
#

no, when you go left the value is between -1 and 0. -1 is just the maximum magnitude

leaden ice
robust dome
#

yeahi guess he is doing this so he can use it inside FixedUpdate

heady iris
#

The problem is that if you switch from left to right, you'll keep your move speed

robust dome
#

which is totally fine

heady iris
#

Consider the following

#
float target = maxSpeed * HorizontalInput;
float maxDelta = Time.deltaTime * accelerationSpeed
moveSpeed = Mathf.MoveTowards(moveSpeed, target, maxDelta);
vestal arch
#

instead of keeping a moveSpeed, you should keep a moveVelocity and let opposite inputs decelerate and then accelerate in the opposite direction

heady iris
#

You can also store a velocity, yes

leaden ice
#

or really just accelerate in the direction of input

#

which is the same

heady iris
#

(well, I'm also storing a velocity -- note how moveSpeed in my code can be both negative and positive! I'm just storing the X velocity)

wet moss
# leaden ice that doesn't make sense

I tried it again, the problem is that it seems like the moveSpeed is being decreased at the same rate as it increases when the button is being held so the result is that the speed doesn't hit 0 nearly fast enough

leaden ice
#

you'll need a bunch of if statements

#

I will say Input.GetAxis in this kind of code is a problem, because it's adding an unaccounted-for extra layer of "acceleration" into all of this

vestal arch
leaden ice
#

You should use GetAxisRaw

wet moss
#

Here's what I did

        
        if (HorizontalInput != 0f && moveSpeed <= maxSpeed) 
        {
            moveSpeed += Time.deltaTime * accelerationSpeed;
        }

        if (HorizontalInput == 0f) 
        {
            moveSpeed -= Time.deltaTime * (accelerationSpeed * 2.5f);
            if (moveSpeed < 0f) moveSpeed = 0f;
        }

        if (Input.GetKeyDown(KeyCode.Space) && (isOnGround))
        {
            rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
        }```
Right now my character just kinda stops, no momentum is carried over
leaden ice
#

surely you omitted something

wet moss
#

Sorry I didn't share everything

{
    rb.velocity = new Vector2(moveSpeed * HorizontalInput * Time.deltaTime, rb.velocity.y);
}```
The parts I shared previously are specifically under Update. Sorry, I'm still new to this whole code sharing thing so I didn't think those parts were relevant
leaden ice
#

Using GetAxis was the ONLY reason you had any acceleration at all

#

If HorizontalInput here is 0... well you're multiplying by 0

#

make sense?

vestal arch
wet moss
#

Yup that's still the same as before

leaden ice
wet moss
#

Ooooooh that makes sense yeah

#

Because GetAxisRaw goes directly from 0 to either 1 or -1 so now when I let go of the button the velocity just becomes 0 instantly

leaden ice
#

this all seems overcomplicated. Couldn't you just do something like

float hVel;
float maxSpeed = 5;
float accelerationSpeed = 4;

void Update() {
  float targetSpeed = Input.GetAxisRaw("Horizontal") * maxSpeed;
  hVel = Mathf.MoveTowards(hVel, targetSpeed, accelerationSpeed * Time.deltaTime);
  rb.linearVelocityX = hVel;
}```
wet moss
#

What does Mathf do? I haven't learned that yet

leaden ice
#

Mathf is a class that contains a bunch of math utility functions

#

it doesn't "do" anything

heady iris
#

I use MoveTowards quite frequently

wet moss
#

I think I understand now

#

Thank you

leaden ice
#

the only thing left to do is vary which accelerationSPeed you feed into MoveTowards based on whether the target direction is aligned with or opposed to the current horizontal velocity

wet moss
#

That sounds easy enough

river kelp
#

Are you guys pooling your audio sources in your sound managers?

#

Or is the benefit miniscule compared to just making and destroying audio sources for sfx

hexed pecan
#

I recommend pooling anything that is a UnityEngine.Object and enabled/disabled frequently

river kelp
#

That does make sense I suppose. But then how do you know if a sound is finished so you can put it back in the pool?

hexed pecan
#

@river kelp The simplest way would be to make a coroutine/awaitable, but a more performant way would probably be to keep track of all the playing AudioSources in your sound manager

river kelp
#

And then intermittently check if they are still playing?

hexed pecan
#

I wish AudioSource had events like OnStop :/

river kelp
#

Or, do I even need to "return them to the pool" in that sense?

hexed pecan
river kelp
#

Could I just use the isPlaying

#

to find the next open object in the pool?

hexed pecan
#

I haven't implemented it, just throwing ideas. I normally use FMOD

hexed pecan
#

Using the Playables API to play audio might be something to look into ๐Ÿ‘€

river kelp
#

Hmm. I haven't looked into stuff like FMOD, how much hassle is it compared to the value?

#

Assuming sound is fairly important to my game, would you recommend taking the time to implement FMOD over making my own custom sound manager?

#

(Also, FMOD is free, right?)

hexed pecan
#

I can't really give a good comparison because I have used FMOD instead of the default audio for as long as i remember

hexed pecan
hot ledge
#

Currently trying to make a string for a TMP UGUI component that highlights some lines conditionally. For some reason, this spits out Input string was not in a correct format

testimonyContents += $"{(pageIndex == Convert.ToInt32(selectedPlant[4])? "<#FFFF00>" : "")}<u>{ts.speaker[pageIndex]}:</u><space=1.5em>{ts.dialogue[pageIndex]}";```

But for some reason this works fine. ```C#
testimonyContents += $"<#FFFF00><u>{ts.speaker[pageIndex]}:</u><space=1.5em>{ts.dialogue[pageIndex]}";```
river kelp
hexed pecan
#

I'd say try it out ๐Ÿคทโ€โ™‚๏ธ It's pretty intuitive especially if you have used DAWs

#

And you can control pretty much everything from C#

river kelp
#

I've been burned by very excessively advanced/generic asset store assets before, with lots of feature bloat etc. Do you think that applies to FMOD?

trim schooner
#

no

#

FMOD isn't an "asset store asset". It's a "proper" piece of middleware, with an asset store asset

river kelp
#

Yes, but that doesn't really answer my concern

trim schooner
#

it's professional middleware, it's one of the two go to sound solutions for games

river kelp
#

I guess I'll give it a shot, thanks

leaden ice
trim schooner
#

Haven't used it, same as you. Just been aware of it for years - @hexed pecan is the many to ask.

wicked scroll
#

it decouples sound design from the game itself

#

so you expose events and parameters and then your sound designer can react to those in fmod studio and your game uses that data to do sound stuff

leaden ice
wicked scroll
#

unity's core stuff doesn't do much more than 'play this sound', but fmod has support for stuff like blending dynamic sounds based on parameters in realtime

river kelp
#

That does kind of sound like a lot of work to set up though

#

How easy is it to just "play sound"

wicked scroll
#

it comes with some components that bridge their stuff into unity

wicked scroll
#

that's an advantage if you have a sound designer who can be in charge of that stuff

#

and if you need dynamic audio

#

pletny of games are just playing 1) some music and 2) oneshot sound effects, so you probably don't need it

river kelp
#

Despite having no sound designer I've kind of painted myself into a position where I have to become one

leaden ice
#

Indie game devs have to wear so many hats

wicked scroll
#

but there are a lot of little things with sound design that you end up layering in, like limiting a particular sound when it's triggering too much (or replacing it with a different one), or ducking particular sounds in favor of others, etc. that it's nice to have supported already for when you need them

river kelp
#

So my choices are really code and make a sound manager myself

#

Or include one like FMOD. I was just dipping my toe into it when I came here for advice

wicked scroll
#

if you are just starting off, I'd just make a little class to manage sounds and let you play them

river kelp
#

No like, I was past that and just getting into the "This isn't working I need a proper sound manager" so I was just starting the code for that

wicked scroll
#

what would make it 'proper'

river kelp
#

Well now I have a bunch of components with direct references to audio clips in the prefabs and awkward code referencing one of several audio sources on each object

wicked scroll
#

you should probably centralize it

hexed bough
#

How can i increase the fps of my game for android? the fps is fine on IOS and web but on android it's very less.
its a webgl 3D game

river kelp
#

As opposed to a pooled sound manager I can ask to "PlaySoundAtLocation("thump1", transform.position)" or whatever

hexed pecan
#

One of the benefits of FMOD is not needing gameobjects to play audio

river kelp
#

Yeah that's what I was starting on

hexed pecan
#

Better performance overall afaik

wicked scroll
#

that seems fine to me for starting out

hexed pecan
#

Good UI for editing automation/modulation curves

leaden ice
wicked scroll
#

you'll find things that you want and over time can decide if you need something full-fledged or should just progressively add the little things you need

river kelp
leaden ice
#

What's the learning curve like for FMOD

river kelp
#

Like, random footsteps type stuff

wicked scroll
#

yeah, I mean if you're already needing that, go for it

river kelp
wicked scroll
#

but none of that is so complex that it would take long to do your own version and that would probably be valuable

hexed bough
wicked scroll
#

and certainly faster than learning fmod

wicked scroll
hexed pecan
wicked scroll
#

it seems pretty easy to get started but like anything fully featured, there's a lot of stuff in there that can be overwhelming

hexed pecan
#

I still keep discovering new features tho

river kelp
#

Like layering audio reasonably

#

I miss the audiograph...

leaden ice
west lotus
#

I have more than a few hours in audacity and fmode still confuses me

hexed pecan
#

You control stuff with parameters similiar to unity's animator

#

And any knob can be linked to a parameter or a curve

river kelp
#

How much clutter will I get in my version control? And will other developers also need it to run the game?

hexed pecan
#

I do remember getting some feedback in a school project about cluttering the project with FMOD files years ago lol

river kelp
#

Like will I need to teach my artist how to work with this too or

hexed pecan
#

But that was just my poor folder management

hexed pecan
river kelp
#

No

#

I'm just wondering if he needs to install and run this to run Unity if I start using FMOD on my end

wicked scroll
river kelp
#

Like, what's the requirement for other developers to run a project with FMOD in it. Maybe I'm confusing what Fmod is?

wicked scroll
#

but only sort of, they can use the existing stuff from within unity if the events are already setup

hexed pecan
#

Oh they don't need standalone FMOD just to work on the unity project

river kelp
#

So they just need the package, basically?

hexed pecan
#

You build banks out of FMOD into your assets folder

#

Yeah the project needs the package/plugin

river kelp
#

And FMOD comes with components for playing sound and whatnot?

#

So essentially for non-sound designer devs it's just a replacement set for the audiosource / audio listener type stuff

hexed pecan
#

Yes, most of the unity components have their FMOD equivalents

#

Although I usually just do everything from C#, except for the listener component ofc

river kelp
#

Sorry for taking up so much of your time here, you've been very helpful, but could you perhaps show me a line for what playing a simple sound effect would be like?

#

Using FMOD?

hexed pecan
#

Or create an instance with CreateInstance and do whatever you want with the event

river kelp
#

eventReference here being a reference to something that, on the FMOD side, plays sound?

#

For example a FireGun event

wicked scroll
river kelp
#

right

#

And then I configure these events and tie them to sound in FMOD studio

#

which creates a "bank" in my project

wicked scroll
#

in the inspector, you have components like this

#

and you can select the event from a dropdown cause it's linked to fmod and knows which ones you've made

river kelp
#

so I don't actually need FMOD studio to run the game

wicked scroll
#

as well as adjust parameters

#

no, of course not

#

fmod studio is a tool for making your game

#

once the game is compiled, none of this matters

hexed pecan
river kelp
#

Sure it wasn't a question it was just like, mentally going through what I have learned

#

the exported "bank" in my game is why I don't need fmod studio, is what I meant

#

Thanks for the help guys I'll dive into this and see what I can do with it

wheat spruce
#

Is there any real harm in having a class not derive from monobehavior, when the class is still making use of the Unity namespaces?

public class RectShape
{
    (GameObject A, GameObject B) _handleObjects;
    public GameObject HandleObjectA => _handleObjects.A;
    public GameObject HandleObjectB => _handleObjects.B;

    public Vector3 HandleA_Position => _handleObjects.A.transform.position;
    public Vector3 HandleB_Position => _handleObjects.B.transform.position;

    public Vector2 Size => new(0f, 0f);
    public Vector2 Center => new(0f, 0f);

    RectShape(Vector3 a, Vector3 b)
    {
        GameObject handleA = new("HandleA");
        handleA.transform.position = a;

        GameObject handleB = new("HandleB");
        handleB.transform.position = b;
        
        _handleObjects = (handleA, handleB);
    }

    public static RectShape Construct(Vector3 a, Vector3 b)
    {
        RectShape newRectangle = new(a, b);
        return newRectangle;
    }
}```I doubt it actually matters, but still
leaden ice
wheat spruce
#

cool, I figured that was the case. The code runs fine, I just wasnt sure if Unity had a specific expectation with the class

heady iris
#

This is something I took a hot minute to figure out

#

You only care about Unity when you need Unity to do stuff for you, like letting you attach components to objects

#

You can do tons of stuff that has absolutely nothing to do with Unity at all

indigo tree
wheat spruce
#

components require MB dont they?,

vestal arch
wheat spruce
#

ah, got it

heady iris
#

Indeed -- or it might show up in an asset somewhere, like a ScriptableObject-derived class

#

or you might want to serialize it with JsonUtility!

wheat spruce
heady iris
#

Yeah.

#

I ascribed a lot of "magic" to Unity

#

e.g. when you destroy a unity object, it now equals null

#

but that ain't a null reference!

#

Unity can't somehow change the contents of your variable

wheat spruce
#

Its why its so important to learn the language before attempting to use the engine (even though thats exactly what I did ๐Ÿ˜… )

latent latch
#

Imagine not knowing how to use constructors because you're too used to Unity's instantiation concepts

wheat spruce
#

I think that was a problem for me

#

I know I had a lot of trouble trying to do certain things because if unity provided a method that wasnt quite right, what else are you meant to do?

#

funny to think that constructors once probably felt like some really advanced and complicated thing

#

one "oh you can do that huh" moment was learning that youre able to put multiple classes in the same file

heady iris
#

you can also put one class in multiple files!

#

partial classes are a bit weird

#

I tried using them once because I had a horrific uber-class that was way too big

#

I then realized I needed to break that thing up completely

wheat spruce
#

partials seem like a great idea with a lot of uses, but in reality they arent that great and have very limited usecases when they'd be worth it

heady iris
#

I managed to chop the class into five pieces. I then had FIVE files that I couldn't find anything in!

#

Even worse than one file I couldn't find anything in

#

Now I have an Entity class and lots and lots of little modules to add features

wheat spruce
#

I think when you see that Unity always makes the file name match the class, not realising it only does that because a template file, that might be why I assumed its one file per class

#

its only actually specific situations where the class and file name have to match, right?

#

scriptable objects or something break if theres a mismatch, that sounds right

heady iris
#

They don't have to match anymore

#

It was a rule for a long time

#

However, you can't have more than one MonoBehaviour/ScriptableObject per file

#

Unity doesn't care about the name of the class or the contents of the file. It just knows that a component corresponds to a specific MonoScript

#

and MonoScript is the type of asset you get when you import a .cs file

wheat spruce
#

I wonder what they were doing for it to be a rule

heady iris
#

It does prevent a little bit of weirdness.

#

The "Add Component" menu uses the asset name, but the inspector uses the class name

wheat spruce
#

Yeah, especially if its one MB class per file, if the name doesnt match the class, it would suggest somethings broken

eager tundra
#

partial classes are a common trap for newcomers, usually your classes are too big because they're holding many responsibilites and turning it into multiple partials wont solve anything

#

they do have some pretty cool use cases though, like Unity uses for DOTS code generation

heady iris
#

yeah, they make sense for codegen

#

otherwise you're just rearranging deck chairs on the Titanic

wheat spruce
#

partials feel like magic the first time you use them

#

the novelty that you can write the same class in 2 locations, without you needing to have the same code written out in both

#

#region is another thing that I dont actually know if its good or not

trim schooner
#

if you have a need for regions in your code, your code is probably too long and/ or poorly organised

eager tundra
#

never seen a good use case for that, it's usually either trying to hide messy code or giving you irrelevant information that could be derived from other sources

wheat spruce
trim schooner
#

The 'clean code' book says to avoid them, IIRC

heady iris
#

Yeah, that's my feeling

#

I have one big use for them: I put all of my debug-only stuff at the end of my classes

#

because I have fields that keep track of stuff like "show X in the debug overlay"

#

they're noisy and don't really matter anywhere else

little meadow
#

the one true rule is that there are no strict rules ๐Ÿ˜›
so it's best to understand why something is good/bad, instead of just knowing good/bad, because bad things can be good in some cases

wheat spruce
#

my usual reason to use them is when I just want to divide stuff out into little chunks, when I dont feel the need to actually segment the code itself up.

or a constructor might go through 3 different steps, a lot of the time I'll just make 3 regions and even if they only have a few lines each, at the time it seems like a useful thing

eager tundra
# heady iris e.g.

in that case you could probably use a preprocessor directive and get conditional compilation for free

wheat spruce
#

to me, theyre more like a fancy way to comment stuff out, into a section that I can collapse

#

group stuff up, add a nice heading, and now I can collapse that whole group in a function and the region name itself is like a comment

heady iris
eager tundra
#

you can have custom directives though

somber nacelle
#

sure, but if you're defining symbols that will never not be defined just for organization, then you've just reinvented regions

eager tundra
#

indeed

heady iris
#

#if GAME_EXISTS

little meadow
#

the anticipation is killing me! ๐Ÿ˜„

late lion
#

I can't recall a time where I've been reading through someone else's code and been glad it has regions. It usually feels like it clashes with my own mental map of the class and hides things.

heady iris
#

I'm still struggling to lay out my larger classes

#

e.g. my Entity class

late lion
#

It doesn't help that Rider automatically collapses all regions by default.

little meadow
#

wait, why is Entity large?

heady iris
#

Almost all actual game logic lives outside of Entity, but there's a fair bit of bookkeeping in there

#

Actually, this class isn't one that's giving me too much trouble. It's pretty clearly organized

little meadow
#

how many lines of code?

heady iris
#

700, ignoring the very verbose IMGUI-based debug view

little meadow
#

that is a bit on the high end, but hey... perhaps the splines or some other parts can be extracted to a module (or a "component" of sorts)
but some classes are just a bit larger sometimes, and splitting them doesn't really make anything better (especially splitting to partial classes ๐Ÿ˜„ )

heady iris
#

Yeah, there's very little game logic in this thing

#

It mostly just keeps track of the entity's modules and calls methods on them at the appropriate times

#

It is responsible for tracking everything the entity has perceived.

#

I've been pulling more and more stuff out of it. It used to control a NavMeshAgent

#

now i don't require an agent at all

little meadow
#

nice, small gradual improvements are โค๏ธ

heady iris
#

I was using the navmesh for both moving around and some extra things, like finding a valid location to exist in

#

now that's abstracted into a Pather

#

...starting with NavMeshPather, of course ๐Ÿ˜‰

little meadow
#

๐Ÿ˜„ ๐Ÿ‘

heady iris
#

My Player and Monster classes used to be like 2-3 thousand lines long

#

I have way, way more code now, but it's much more spread-out

hexed bough
#

can URP can fps drop on android?

vagrant blade
#

That question doesn't make sense. Anything can "fps drop" on Android.

#

The more you do, the more effort the device requires to do that thing, and if all the things combined are too much for the device, of course it will slow down.

hexed bough
#

it works fine on ios and web. but i see a lot of fps drop on android alone

#

that too on a bit low end device

vagrant blade
#

Well, you can only profile it to find out why

worn oasis
#

Hey guys, I have a projectile (NetObj + rigidbody + spherical trigger collider) I am spawning in the scene and using FixedUpdate I am moving it through the air to hit another gameObject (NetObj, rigidbody + box trigger collider) both extrapolate interpolation and their Collision Detection is set to Continuous Speculative. Additionally, I set the timestep to 0.1.

Despite all these changes, in some instances, both the projectile and the box do not detect the collision. What am I doing wrong and how could I fix it?

leaden ice
#

Best to do your own manual SphereCast I would think

worn oasis
leaden ice
#

You're starting a new coroutine every frame

somber nacelle
leaden ice
gleaming orbit
#

ooh

worn oasis
somber nacelle
gleaming orbit
#

ooh

lean sail
worn oasis
lean sail
worn oasis
still gust
#

Hey, i want to create some sort of climbing, but in a way where you can just walk along any surface, so think you can walk on floors walls ceilings and meshes but when you're in freefall you'd fall to the ground. Can anyone explain or break down what kind of steps I would need to take to accomplish this? I'm sort of stuck on how I would create this system with edge cases like sharp corners or the curved sides of a ball where a simple raycast down wouldn't really work.

leaden ice
worn oasis
heady iris
#

so, for example, it should not make you fall by doing velocity.y -= Time.deltaTime * 10;

#

note that the built-in CharacterController component doesn't let you rotate it, which could be an obstacle

still gust
# heady iris note that the built-in `CharacterController` component doesn't let you rotate it...

right now I have a state machine running the movement, for the falling state I have the character rotate to be upwards from the ground, and falling in that direction. and for the climbing I just put it into the regular movement state since thats whats happening really. I have a raycast downwards that detects the hit normal to rotate the player. But i'm not sure what to do from there and like you said I had much trouble with the charactercontroller so i ended up removing it.

heady iris
#

So you can properly move around on a plane at any orientation right now?

still gust
#

right now i have it rotating but idk how to move it tbh, my idea was to use Transform method to move it somehow according to the hit.point

heady iris
#

You can construct a rotation out of a forward vector and an up vector

#
var rot = Quaternion.LookRotation(player.transform.forward, hit.normal);
var worldForward = rot * Vector3.forward;
#

e.g.

#

This would misbehave if you somehow wound up aligning the player's forward vector with the normal vector of the ground

hexed bough
warm badger
#

Hi, how can I achieve something like the following image says?

cosmic rain
warm badger
#

sorry, i couldn't understand, can you clarify a bit?....suppose p is player and it moves around the whole world...but there is a curve or path...and the green object will be clamped to that path only but will also follow the player along the path only...

hardy pasture
#

How to get game object from inside of Animator behavior script?

cosmic rain
hardy pasture
#

It doesn't say anything

#

So where in the docs does it say how to do it?

cosmic rain
cosmic rain
hardy pasture
#

I know I can do animator.GetComponent but I want to find the parent game object of the animator and it doesn't say how to that in any of the pages that you said it does.

cosmic rain
cosmic rain
hardy pasture
# cosmic rain It says it all. Have a look at the code sample on the page. And the specific met...

Have a look at the code sample on the page

using UnityEngine;

public class AttackBehaviour : StateMachineBehaviour
{
    public GameObject particle;
    public float radius;
    public float power;

    protected GameObject clone;

    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        clone = Instantiate(particle, animator.rootPosition, Quaternion.identity) as GameObject;
        Rigidbody rb = clone.GetComponent<Rigidbody>();
        rb.AddExplosionForce(power, animator.rootPosition, radius, 3.0f);
    }

    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Destroy(clone);
    }

    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Debug.Log("On Attack Update ");
    }

    override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Debug.Log("On Attack Move ");
    }

    override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Debug.Log("On Attack IK ");
    }
}

The code example shows how it creates a new game objects and gets its' component but doesn't show how to get the parent game object of the animator and then its' components.

cosmic rain
#

It does show you that you can get the animator. An animator is a component, and as any component it has references to the GameObject and it's transform.

#

Look at the inherited properties of the Animator class

#

Then, there's also GetCompinentInParent, so you can make it just animator.GetComponentInParent<Type>()

#

Check the docs. It's all in there.

hardy pasture
#

I also googled on how to do it and found multiple threads on the forum without an actual answer.

#

The closest thing that was recommended was animator.GetComponent but I doubt it gets the components on the parent game object, more like attached components to the animator.

cosmic rain
hardy pasture
#

What about just animator.gameObject?

cosmic rain
#

That's the GameObject the animator is attached to, not it's parent.

hardy pasture
#

Yeah, that's what I want: to get the game object of the mono behavior and the animator.
So like Animator is a component on a game object, and so I want to get the game object.

warm badger
cosmic rain
hardy pasture
warm badger
#

actually i will make a path for a audiosource to follow along the river while keeping the player aligned on the specified path...for example, the sphere should be in the red dot

hexed pecan
#

I.e. the gameobject that the component is attached to

cosmic rain
cosmic rain
#

Ah

#

I looked at the video again. Okay. I get the issue I think. So the ball needs to be on the same y position(in screen space) as the cube?

warm badger
hexed pecan
#

Red = A, Green = B, Blue = C, White = Result

#

This works:```cs
Vector3 ProjectAndKeepY(Vector3 a, Vector3 b, Vector3 c)
{
var ac = c - a;
var ab = b - a;

    var yAB = b.y - a.y;
    var yAC = c.y - a.y;

    // Percentage along Y
    float t = yAC / yAB;
    return Vector3.Lerp(a, b, t); 
}```
#

You calculate the percentage that C lies between A and B, but only on the Y axis

#

Then you use that percentage to lerp between A and B

#

There's your result

#

To clarify - A & B are the line points and C is the position you want to snap to the line

warm badger
slim trail
#

hello

#

someone know why I don't see anything on my inspector

cosmic rain
slim trail
#

oh

#

I just reloaded project and it works

strong night
#

Hey there! I'm trying to implement changing map in my game and I think unity is taking the piss at this point.

I have a bunch of objects on my map and what I want to do it first move the objects parent into a _toDestroy variable and rename it to "ToDestroy" And then reset the _objects to a new "Objects" Gameobject to get the new sets of objects:

private GameObject _objects;
        private GameObject _toDestroy;
        private Dictionary<string, GameObject> _objectsDict;
        
        public void ResetObjects()
        {
            
            _objectsDict = new Dictionary<string, GameObject>();
            
            if (_objects != null)
            {
                Debug.Log("Reset");
                _toDestroy = _objects;
                _toDestroy.name = "ToDestroy";
                _toDestroy.SetActive(false);
            }
            
            _objects = new GameObject("Objects");

        }

And then, after the map is generated, I send an event to clean up the old objects:

public void DestroyOldObjects(EventArgs args)
        {
            if (_toDestroy != null)
            {
                Debug.Log("Destroying old map");
                Destroy(_toDestroy);
                _toDestroy = null;
            }
        }

HOWEVER. Some dark magic happens here. The _toDestroy rename doesn't reflect AT ALL on the hierarchy, so does the change of active. BUT if I check using SceneManager.GetActiveScene().GetRootGameObjects() it appears and has the name.

Also the Destroy literally has no effect at all. All the objects are still on the game.

Everything is done async using CoRoutines and Events.

One thing to note is that some code is also removing the whole TileGrid and this time, the Destroy works. So the issue is really this particular GameObject....

Any idea? This is driving me crazy

thick terrace
strong night
#

Object is initialy create like: _objects = new GameObject("Objects");

It's used as an empty gameobject to contain all the dynamically added objects on the map.

It is not a prefab however all its children are technically instanciated prefabs. Could it explain that?

#

By context param, what do you mean? Just doing `Debug.Log("My object" + _toDestroy) ?

spring basin
#

@strong night does it work when you have only 2 objects?

#

like create the first instance -> then call ResetObjects() -> delete old instance -> and see the new instance

strong night
#

That's what's meant to happen. But I do end up with 2 Objects at the end because the actions I do on the original objects have no effect

narrow sapphire
strong night
#

So I'm making a 2d topdown game with random map generation and map to map travel. The idea is that when I move from 1 map to the other, I destroy everything and rebuild everything. So basically destroy the tileGrid and the objects on the map and load the new map

#

The tileGrid is successfuly destroyed but the objects on the map keep persisting

narrow sapphire
#

ok so

#

is there a reason ur not just using scenes for this?

strong night
#

That was my initial approach, changing the coordinates on my world for my player and its approximate arrival coordinates on the map itself and reload the scene to consumer those, but it was super flaky, so I thought I'd try that way

#

And other than the objects persisting for some dodgy reason, everything else works so it sounded like a good idea lol

narrow sapphire
#

wym flaky

#

scenes is definitely how I'd personally go about this I think

#

kind of what they're designed for

#

but if you're adamant doing this way

#

how about using prefabs instead of moving over a bunch of objects from one parent to another?

strong night
#

So the objects themselves are original prefabs (the ones in the parent)
I'm not looking into moving them, I'm hot swapping maps. So map 1 has a bunch of trees scattered around the place and map 2 will have trees to be different numbers, coordinates etc...

So when moving from map 1 to map 2, the content of map 1 needs to be wiped and leave place for map 2

#

But the Trees are prefabs

#

I might give another go at the scene as it'll probably be more robust if I get it to work. I've been doing a lot of experimenting since I tried it, so maybe it'll make more sense now to me

narrow sapphire
#

well from that description it's like a perfect usecase to just readd the scene and unload the old one

#

you can use a scene like a prefab of ur entire map

#

and just have ur random placement logic happen whenever the scene is loaded

strong night
#

Hmm interesting. Yeah I'll give it another go

narrow sapphire
#

no need to do this parent swapping voodoo

#

more trouble than its worth I think

strong night
#

Oh but that's what I'm trying to do

#

I destroy the parent with all of its content

#

And create a new one

#

IT just happens that Unity isn't doing the Destroy at all

#

The "swapping" from Objects to ToDestroy is just to allow creating new objects under a new parent while the Destroy happens as Destroy is a bit more async

narrow sapphire
#

ah sure thought it was something else from ur original description

#

but i doubt the issue is like... something wrong with destroy

#

probably some issue with the coroutines instead

strong night
#

Maybe... I'll try the scene way so hopefully it won't be a problem I have to deal with lol

narrow sapphire
#

I definitely don't think its worth the performance of using non main thread just to destroy a bunch of stuff; especially since it sounds like something that doesn't happen very often

#

scene loading and unloading is 'async' so you'll get the same kind of gameplay fluidity

strong night
#

Yeah, funnily enough, most of my code was very compatible with scene loading. It works out of the box lol! Thanks for the advices ๐Ÿ˜„

zealous lagoon
#

Hello, trying to make an attribute for hiding variables based on values of other variables. It works (kind of), but it completely resets indendation, so nested properties render all the way to the left. I don't modify EditorGUI.indentLevel at all, so no idea how this happens. Any tips?

EDIT: I tried printing EditorGUI.indentLevel, it's always zero. I don't know why or how.

#

Okay I was able to fix it by setting the indent level myself by counting the amount of periods in the property path. Still no clue why indentLevel was zero, isn't it meant to be handled automatically by default?

static matrix
#

how can I adjust the crinkliness or seek sun of a tree from a script?

#

this is what the "tree" looks like, i'd like to dynamically change the crinkliness of the middle portion

warm cosmos
#

if anybody knows much about this stuff - I am rendering from a camera to a RenderTexture, which has square dimensions (see screenshot). If the camera viewport is not square, does it just try to render the maximum square size centered on the middle of the camera viewport?

#

I'm pretty sure this is the case... what do I want is to have a visual indication, perhaps like a red square on the camera view that outlines the part that will get rendered to the RenderTexture.

#

if that's possible please let me know

#

something like this maybe?

#

or maybe that's stupid and I should output the render target to a different camera..

narrow sapphire
#

Make a gizmo

#

There is a cube one prolly fine for 2D as well

stone arch
#

Hi, i need urgent help in building an apk for my game. please lmk if you can help <3

warm badger
#

i have a script that simply changes one color property of a shader of a referenced material...I am using addressables to load and unload one scene where the object with that material is.... suppose scene 1 holds the object with the material and scene 0 holds the script to change shader value....Now:

scenerio 1 -> changer script in scene 0 and material is referenced in that scene...scene 1 is loaded on button pressed

scenerio 2 -> changer script in scene 1 and material is referenced in that scene...scene 1 is loaded on button pressed...

in scenerio 1, shader property doesn't change, script works but shader property doesn't change...
in case of scenerio 2, shader property changes

mainly, when i reference my material in the scene where the object is, script works fine...
but when material is referenced in another scene and then the scene with the object is loaded, shader properties doesn't change...

can anyone help please?

warm badger
thin aurora
stone arch
leaden ice
warm badger
warm badger
# leaden ice Without you sharing specific details and specific code, it's impossible to answe...
    public Material mat;
    public Color colorToSet;
    public Color colorToSet_01;

    public AssetReference sceneRef;
    public AsyncOperationHandle<SceneInstance> handle;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            handle = sceneRef.LoadSceneAsync(LoadSceneMode.Additive);
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            mat.SetColor("_Value", colorToSet);
            Debug.Log(mat.GetColor("_Value"));
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            mat.SetColor("_Value", colorToSet_01);
            Debug.Log(mat.GetColor("_Value"));
        }
    }
warm badger
leaden ice
warm badger
robust dome
#

Spacejocks

weak cargo
#

That channel was tucked away, I missed it, thanks @robust dome

robust dome
#

you are welcome friend

heady iris
#

If you have a direct reference to an asset and you also load it via Addressables, you'll wind up with two different assets in the built game

#

This will not happen in the editor.

warm badger
heady iris
#

I ran into this problem while working on my game's settings system. Each setting is a ScriptableObject asset. I was using Addressables to easily load all of them when the game started

#

Everything broke because the Addressable version of the assets were unrelated to the non-Addressable version

heady iris
heady iris
#

In my case, I just stopped using Addressables -- it was basically equivalent to putting everything in a Resources folder

#

I was not actually using any of the system's features beyond "give me all assets!"

heady iris
heady iris
#

As I understand it, a common pattern is to have a single non-Addressable scene whose sole job is to load up an Addressable scene

warm badger
#

one thing, how can I access the material properties when referencing that material to assetReference?

finite olive
#

does someone know if its possible to do android/pc communication over usb?

heady iris
heady iris
sharp topaz
#

hey i'm a level designer working on a project.... and there is something I don't understand. Dev is insisting on loading entire levels as prefabs instead of using scenes... is there... any good reason to do this? It seems like it breaks all kinds of dependancies and introduces merge issues when people update sub-components of the prefabs. But I don't know enough about code to form a counter argument, and none of them want to explain to me why they want to do it this way.

heady iris
#

Well, you'll have identical issues with scenes!

#

Nested prefabs should help you avoid such conflicts, though. Suppose I have this for an enemy:

#
  • Enemy (Prefab)
    • Body
    • Weapon (Prefab)
#

I can change the Weapon prefab while someone else is messing with the enemy's Body object

sharp topaz
#

yeah but I mean..... the entire level is a prefab... probe data and lightmaps dont work... though we haven't decided on using that.

heady iris
#

oh yeah, that's going to be uh

#

๐Ÿ’ฅ

#

I've never really looked into trying to put "scene data" into prefabs like that

#

Cross-scene references are a bit annoying to handle, so instantiating a giant "level prefab" could be mildly more convenient

#

normally, you have to wait for the scene to activate, then try to find the objects you need in it

versed loom
#

why is my scale messed up after i call this function

public static void SetParentT(this Transform target, Transform parent)
        {
            var targetScale = target.localScale;
            
            target.parent = parent;
            target.localScale = targetScale;
        }```
because if i just drag it the editor as the child it works (last image)
sharp topaz
#

my barely educated guess is to allow the UI to live in a single instance and not have to hand data back and forth constantly

#

cause aparently thats a common frustration

#

but i really don't know :/

heady iris
sharp topaz
#

I saw that in favor of prefabs, and memory issues as an argument against level prefabs, but the source is like... no data reddit posts

heady iris
#

In another game, I additively load a "UI scene" at game start and then never unload it

#

That's roughly equivalent

heady iris
#

You're setting your local scale back to its original value

#

If your old parent's scale was [1,1,1] and your new parent's scale is [2,2,2], your local scale will get halved

#

If you then reset your local scale to its original value, your apparent size will double

versed loom
heady iris
#

The new parent's local scale is [1,1,1]

#

But perhaps it has a parent of its own!

#

The values you see in the inspector are the local position/rotation/scale

soft shard
deft kindle
#

My script is enabled but does not work and idk why it gave me the DEBUG called LightTool script started!

rigid island
leaden ice
rigid island
#

๐Ÿ˜ฎ

leaden ice
#

Jinx

deft kindle
leaden ice
deft kindle
rigid island
leaden ice
deft kindle
leaden ice
deft kindle
rigid island
#

you have to find out where its "failing" in your function, if its running at all

leaden ice
deft kindle
deft kindle
leaden ice
rigid island
#

likely this is getting disabled or gameobject is at some point

deft kindle
leaden ice
#

Also make sure the game isn't getting paused

deft kindle
leaden ice
leaden ice
deft kindle
deft kindle
rigid island
#

is this gameobject or parent being set to not active ?

deft kindle
rigid island
#

oh btw this doesn't work on unity objects Camera.main? the ?

rigid island
deft kindle
deft kindle
heady iris
heady iris
rigid island
# deft kindle yea its enabled

ok. this is where the script is?
are you actually clicking in your game view twice to make sure you're like inside the game view?

deft kindle
leaden ice
#

Do other keys work

#

Like GetKeyDown(KeyCode.A)

deft kindle
leaden ice
#

So just a mouse issue?

#

What kind of mouse are you using

deft kindle
leaden ice
#

And did Unity recompile

deft kindle
leaden ice
#

Did Unity recompile? Do you have auto refresh off?

deft kindle
heady iris
#

type some garbage into your code editor and save it. does unity produce an error?

#

if so, then it is, indeed, seeing your new code

deft kindle
#

Script works fine just not update

somber nacelle
#

have you tried removing the garbage on the line above Update?

heady iris
#

That means that this behaviour is getting disabled (or its object is getting deactivated).

heady iris
somber nacelle
#

ah my bad

heady iris
#

I wanted to make sure Unity was actually seeing the changes

deft kindle
heady iris
#

You can check by logging something in OnEnable or OnDisable

deft kindle
#

it Enables and disables QUICKLY

finite olive
heady iris
deft kindle
heady iris
#

You must have an error in your tool-selection code

leaden ice
#

That's what USB is for

#

Communication

safe zinc
#

Does converting ASCII fbx resources to Binary can save space? Or Unity already converts them at build time?

heady iris
#

Unity converts everything into its own internal formats as part of the import process

#

The file format is irrelevant

#

This talks about how that whole system works. Neat read.

heady iris
#

That sounds scary

safe zinc
#

Ok, I thought you choose the type of format you compress into, like in bitmaps, but I guess it use it's own propriety format?

heady iris
#

I dunno how models work

warm kite
#

How do I remove Unity's own logging like:

No texture data is available to upload.

...from the console window in a server build?

rigid island
#

i think somewhere in project settings

leaden ice
warm kite
warm kite
rigid island
heady iris
#

The log file might have a stacktrace to look at

#

Could help you figure out why that's getting logged, at least

warm kite
heady iris
#

Ah, all of that stuff that falls out during startup?

#

I wonder if you can make the console window clear itself

#

I don't know of a way to suppress those logs, though.

warm kite
rigid island
#

maybe something to do with command line arguments and some option to turn verbose

marsh wadi
#

I tried to get instrumentation-based profiling to work with Superluminal, but after adding the Superluminal DLL and calling SuperluminalPerf.BeginEvent("foo") and .EndEvent(), they don't show up regardless

It does work when adding the superluminal DLL in a separate C# project (through nuget) whose DLL was included in unity, but this is not that useful

Did anyone get that to work?

warm kite
waxen burrow
#

I am on a project where I need to log player position, head rotation, etc. most importantly I need to log collisions. I only want to log a collision on first contact. (Basically onColliderEnter) the issue is that our player uses a character controller and from my understanding that doesnโ€™t pair well with a rigid body.

Will I have to maintain a hash of all the collisions?

#

Or is there a much better/cleaner approach

knotty sun
#

Character Controller has it's own collision event

heady iris
#

what are you thinkig of "hashing" here, exactly?

#

I'm confused by "maintain a hash of all the collisions"

waxen burrow
#

There could be multiple collisions at the same time, so every time charactercontrollerhit is called, it will attempt to add the object (or characteristic of it) to a hashset. If the item is already in the hash it it gets ignored, else log it. Then using โ€˜oncontrollerexitโ€™, remove from hash

leaden ice
heady iris
#

a character controller is not going to produce the normal collision events when it tries to move into a solid object

leaden ice
#

it even exposes a handy GetState() function to grab the state whenever you want.

heady iris
#

It never actually overlaps with the obstacles. That's the entire point -- it figures out a new position that's not inside of a collider

leaden ice
waxen burrow
heady iris
#

If you need to keep track of which things you've hit, you'd want to keep track of a collection of Colliders

short quiver
#

I'm iterating upon a state machine, where each state subclasses CharacterState, and a CharacterStateFactory tracks all possible character states so that, when checking if a state should be updated, a given CharacterState checks some conditions and, if applicable, returns the relevant state from CharacterStateFactory . I'm doing a lot of prototyping right now, and so I'm finding it very tedious to:

  • define a character class
  • tell the factory about the new class
    Is there any pattern that I can use to have the factory implicitly know about all of the CharacterState classes I create?
    As I'm writing this out, I'm considering to just replace my Factory with a Dictionary managed by the Character. Upon checking for a new state, I can see if the Dictionary already contains an instance of the specified CharacterState, and if not, I can instantiate an object of the specified type and add it to the dictionary. I guess the problem with this implementation is that I can't preinitialize the states because I don't know what all of the applicable ones are, which is why it would be nice to know all of the classes beforehand.
eager tundra
modern creek
#

If I'm kicking off an animation with SetTrigger(string id) .. is there an easy way to yield in a coroutine until that state is complete? Or is there maybe an easier way to embed an animation in a coroutine?

heady iris
#

you could use a StateMachineBehaviour here

#

that lets you run code in response to a state entering or exiting

#

it's a little awkward because this is on the animator controller asset, so it can't reference objects in your prefab or in the scene

modern creek
#

hm.. digging into the docs

#

Animator doesn't have an exposed state machine..?

eager tundra
#

I've used this code a while ago, you can probably adjust it slightly if you need use a trigger instead of state name or evaluate the duration of a different layer

    public static IEnumerator PlayAndAndWait (this Animator animator, string stateName)
    {
        animator.Play(stateName);
        yield return null;
        yield return new WaitForSeconds(animator.GetClipDuration(
        yield return null;
    }

    public static float GetClipDuration (this Animator animator, int layerIndex)
    {
        AnimatorClipInfo[] currentClipInfo = animator.GetCurrentAnimatorClipInfo(layerIndex);

        if (currentClipInfo.Length == 0)
        {
            Debug.LogError($"Animator is not playing! {animator.gameObject.name}");
            return 0;
        }

        AnimationClip currentClip = currentClipInfo[0].clip;

        return currentClip.length;
    }
modern creek
#

I could do something janky like while (animator.state != "myTriggerAnimationName") but seems bad?

eager tundra
#

that also works

modern creek
#

hm, that's .. better, perhaps

#

Just skimming the docs of Animator, I'm surprised there isn't a play animation (as a coroutine)

eager tundra
#

it's probably better because you're avoiding the WaitForSeconds allocation, depending on the frequency that it's going to be called

#

but unfortunately the animator API sucks

modern creek
#

I don't care about that :p

#

can you only get the clip info if it's currently playing? I'm also worried if the animation doesn't start on the same frame as I set the trigger - I don't know when animations start when you set trigger

#

(in update)

heady iris
modern creek
#

I wanna KISS - I pretty much just wanna be able to do something like:

        public IEnumerator InteractCoroutine(Vector3 target, Action interactDoneCallback)
        {
            EntityMesh.transform.LookAt(target);
            EntityAnimator.SetTrigger("Interact");
            yield return null; // pause until animation is done here
            interactDoneCallback?.Invoke();
        }
#

ideally something that's one line on that yield would be great

eager tundra
#

it's pretty old code, but I think it was necessary for the animation to properly start

modern creek
#

oh, to ensure the trigger is consumed and the clip[0] is the correct clip?

eager tundra
#

most likely yes

heady iris
#

i presume it has to wait until the animation update (which occurs after the Update loop)

eager tundra
#

just saw that the code is not even compiling ๐Ÿ˜‚ sorry about that

modern creek
#

yeah - i'd have to dig through the docs but i imagine setting the trigger in update might not put the animation into that state immediately - maybe next frame, maybe later in the frame's lifecycle, etc

eager tundra
#

shouldn't be too hard to fix

heady iris
#

use a StateMachineBehaviour. it does exactly what you want here -- although you will have to set one up for each animation state you're interested in the entering and exiting of

#

I'd have to fuss around to make an example because I don't use Mecanim very much in actual game dev -- just for VRChat nonsense ๐Ÿ˜›

modern creek
#

i still have to tie the animations to those states manually, right?

#

I also don't know exactly how clips blend and how that'd affect it all.. like during a clip blend, which animation is considered playing (probably the "before" animation? guessing before looking)

heady iris
#

This would not have anything to do with the actual animation clips -- or, more generally, motions

modern creek
#

Yeah, I'm reading it.. I don't see how I'd tie an FSM to the animator easily though?

#

Like.. if I'm understanding this right, I'm going to need to listen to what clip is currently playing in Update, and if it's different than the FSM thinks, change the state? (and subscribe externally to whatever I need - OnStateExit probably?)

heady iris
#

You would add a StateMachineBehaviour to whatever states are entered when you set the "Interact" trigger. They'd raise an event in OnStateExit.

public class NotifyOnExit : StateMachineBehaviour {
    [SerializeField] private string label;
    public event System.Action<string> OnExit;

    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        OnExit?.Invoke(label);
    }
}

A lot like animation events, but it's dealing with an animation state, rather than a specific animation clip.

You could subscribe to all of these pretty easily:

foreach (var notify in animator.GetBehaviours<NotifyOnExit>()) {
    notify.OnExit += HandleExit;
}

where HandleExit takes a string and decides what to do based on that

modern creek
#
        public IEnumerator InteractCoroutine(Vector3 target, Action interactDoneCallback)
        {
            EntityMesh.transform.LookAt(target);
            EntityAnimator.SetTrigger("Interact");
            yield return null;
            AnimatorClipInfo[] _clipInfo = EntityAnimator.GetCurrentAnimatorClipInfo(0);
            float currentLength = _clipInfo[0].clip.length;
            yield return new WaitForSeconds(currentLength);
            interactDoneCallback?.Invoke();
        }

this is where I'm at now.. seems fine?

heady iris
#

So, if you configured your interaction animations to all send a message named "Interact Over", you could respond to that

modern creek
#

I'm not sure I need all the FSM stuff since I compose my animations through coroutines currently

#

(ie, I don't need to create "starts" and subscribes to "ends")

heady iris
#

if something prevents the animation state from ever entering, this will erroneously decide that the interaction completed properly anyway, too

#

(after a time period that depends on what state you happen to be in)

modern creek
#

Yeah, understood

heady iris
#

So it'll mostly work

modern creek
#

This works pretty well as a quick and dirty solution for me - the story beat here is hard coded so there's nothing else going on in the game

#

the "interact" animation is that mouse doing the hand plant and looking around.. then i return control to the camera which unzooms

leaden ice
#

The state machine behavior callbacks give you a reference to the Animator component in the scene

modern creek
#

hm.. i have a reference to the renderers (and animators attached to them) in another way, but .. I don't know if I like how my objects are composed currently

rigid island
modern creek
#

thanks.. lots to do still (as always)

#

the end result of stuffing the clip "wait" in the renderer coroutine is that I can compose this shot with code like this:

        private IEnumerator Story1BBeatCoroutine(Action callback)
        {
            // Save zoom clicks
            _zoomClicksDuringSpecialAnimation = _currentZoomClicks;
            // Track target
            OnTrackTargetRequested(InterfaceManager.CommanderRenderer.gameObject);
            // Zoom
            _currentZoomClicks = 0f;
            yield return new WaitForSeconds(CameraZoomTime);
            // Small pause before animation
            yield return new WaitForSeconds(0.25f);
            yield return InterfaceManager.CommanderRenderer.InteractCoroutine(InterfaceManager.LookAtCameraVector, null);
            // Zoom out
            _currentZoomClicks = _zoomClicksDuringSpecialAnimation;
            yield return new WaitForSeconds(CameraZoomTime);
            callback?.Invoke();
        }
#

instead of setting a callback on the renderer's state change back to idle (then continuing)

#

I don't like how that kind of code (embedded lambdas) looks.. just a personal preference

#
blahblahblah.OnStateExit = () => {
  blahblahblah.DoMoreStuff();
};

or whatever the syntax is.. I just sorta hate it :p

latent latch
#

Feels like something the animator timeline would be good for, no?

heady iris
#

You can also provide a named function if you want

#

Of course, this could also just be a place to use animation events

modern creek
#

yeah, I dabbled a little bit with timeline but .. it didn't play nicely with cinemachine for what I'm doing

#

I really have the camera movement/ui dialed in how I want it.. I did some timeline prototypes but it didn't feel great

#

I might still come back to it for some shots that need more .. uh.. moving parts. Doing it in code isn't great, but it's good enough for now, and allows me to maybe embed "story beat" camera shots and pauses into configuration content

lucid brook
#

Does anyone know why my look sensitivity increases with lower frames rates. I used Deltatime but that didn't seem to fix it at least not when I'm using a mouse. on a controller it works as you would expect.

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerLook : MonoBehaviour
{
    [SerializeField] private InputActionReference look = null;
    private Vector2 lookInputValue;

    [SerializeField] private float mouseSensitivity = 25f;
    [SerializeField] private float controllerSensitivity = 200f;
    private float xRotation;
    private Transform playerBody;

    private void Awake()
    {
        playerBody = this.transform.parent;

        Cursor.lockState = CursorLockMode.Locked;
    }

    private void Update()
    {
        lookInputValue = look.action.ReadValue<Vector2>();

        float sensitivity;

        if (ActiveDeviceManager.instance.activeDevice == ActiveDeviceManager.ActiveDevice.MouseKeyboard)
            sensitivity = mouseSensitivity;
        else
            sensitivity = controllerSensitivity;

        float lookX = lookInputValue.x * sensitivity * Time.deltaTime;
        float lookY = lookInputValue.y * sensitivity * Time.deltaTime;

        xRotation -= lookY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        this.transform.localRotation = Quaternion.Euler(xRotation, 0, 0) ;
        playerBody.Rotate(Vector3.up * lookX);
    }
}
somber nacelle
ivory smelt
#

what the hell is this sorcery

cosmic rain
#

Move it to the disk root or somewhere near it and try again.

ivory smelt
#

been working like that my whole life, I think its because I had to restart my pc b4 and the project was booting up

#

but lemme try

#

never fucking mind, somehow it was a command line argument specifying port and ip ๐Ÿ˜

#

it worked an hour ago tho

#

thanks anyways ๐Ÿ‘

#

no clue how that worked

lucid brook
#

Only thing is not my mouseSensitivity is at like 0.1 and my controllerSensitivity still at 200 for similar feel on both but that's not really an issue lol

frigid laurel
#

hey guys im having so much trouble trying to setup a project for Unity ML

tawny elkBOT
#

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #๐Ÿ”Žโ”ƒfind-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696

frigid laurel
somber nacelle
#

you'd have better odds of someone helping if you post your question in the correct channel and with some actual details

frigid laurel
#

my bad boss

outer otter
#

is there a way to debug code that fails 1/5 times testing the same thing? fsr Im saving data to a file: a string, vector3, and another string using JSON. It saves just fine, so far ive been able to save the file successfully 100%, and debug it to know the transform is being applied. yet the objects still get instantiated at 0,0,0 some times. Also, im not sure if it also deals with the weird place issue. ill post a vid and code

#

nvmd i cant even send a 20 second vid in 480

cosmic rain
#

Adding more debugs and trying to reproduce the issue. Then looking through the logs to see where it went wrong.

outer otter
#

heres a really close snippit

cosmic rain
#

Conditional breakpoints are also an option.

heady iris
#

Are you using Rigidbodies with interpolation enabled?

outer otter
#

the debug you see there is the actual game object data, not the serialized class data, so i dont know wtf is happenin

#

yes

#

that shouldnt reset the objects location tho right?

heady iris
#

Set Rigidbody.position, not just the transform's position

outer otter
#

thats a thing?

heady iris
#

When you have interpolation enabled, the Rigidbody will set the transform position every frame

#

This will cause it to lose whatever position you assigned

#

You need to directly tell the rigidbody where it needs to be

outer otter
#

that could be whats causing the other handling issue

heady iris
#

(you could also set the transform's position as well, so that it's immediately in the right spot)

outer otter
#

is that in the fixedupdate method?

heady iris
#

You'd want to do this during instantiation

outer otter
#

i see

heady iris
#

You may need to use GetComponent to fetch the rigidbody (or add a reference to it on whatever component type you're referencing the prefab as)

#
public class MyPrefab : MonoBehaviour {
  public int whatever;
  public Rigidbody rb;
}
#

I very rarely reference prefabs as GameObject!

cosmic rain
#

Technically, setting transform position, should invalidate rb interpolation imho. But the thinking is correct: there are many systems that might try to move your object if you go against them.

outer otter
#

saving and loading is real tricky, i got it setup for the most part, just these weird quirks

#

ill try it and report back

heady iris
#

Alternatively, you can call Physics.SyncTransforms() after instantiation. This is necessary if the collider needs to be in the correct location immediately

#

I've seen problems in the past where people instantiate and position objects, then immediately try to do a physics query

cosmic rain
#

Ah, physics queries would definitely lie in that case, yes.

heady iris
#

The physics system does immediately know about the new collider and rigidbody, but if you then set the transform's position afterwards, it won't notice that change until the next physics update

outer otter
#

so rb.position =
transform.position =
then Physics.Sync

heady iris
#

The last bit is only needed if you want the collider to be correct immediately

outer otter
#

wouldnt hurt right?

heady iris
#

If it can wait, I'd just set the two positions

outer otter
#

okay

heady iris
#

It'll be a slight performance hit, nominally

#

It could be a problem if you spawn tons of objects

heady iris
#

I don't know exactly when the rigidbody winds up updating the transform's position, hence the second point

outer otter
#

i might have done better factoring than i thought ๐Ÿ˜ฎ i only had to add one line lol

#

lets see if it works

#

idk if spamming a load script has anything to do with this but there the culprit is down there

#

it did better this time tho i have to say

#

you can see its serialized data applied to the monobehavior, but the gameobjects transform gets reset somehow

#

another test to load, quit, load quit and it happened maybe the 3rd time again

cosmic rain
outer otter
#

the pot object is the unique one, all objects that will be saved and or picked up will have these pertaining to them.

#

ive tried removing the handle script completely, same issue. it also does the same 'blip' when placing items. it feels like a plague, ill try and catch it one sec

cosmic rain
#

I'm not sure I understand the issue correctly. What exactly is happening in that video? And what(when/where) goes wtong

outer otter
#

the test is me picking up and placing the object, repetitively to get it in length for a video, but randomly it seems like the place transform never gets applied, but the grab handle gets nulled and the player drops it. Debug log in the dropped script would tell me if its coded to drop on purpose

#

but both issues seem like randomly nulled out transformations or something, that or the raycast is getting fubar'ed somehow. it just seems like timing than a written problem

#

i think its fixed on both ends.
TryGetComponent(out Rb rb){
rb.position

not rb.transform.position lol

white olive
#

What happens if you call GC.Collect in Unity with the parameter compacting as true? Since I read Unity's GC does not compact

worldly hull
#

how to make all existing disabled gameobjects take in this script in editor mode ?

[ExecuteInEditMode]
class temp : MonoBehaviour
{
    private void Awake()
    {
        languageChangeText script = GetComponent<languageChangeText>();

        script.FontSize = new FontSizeDictionary()
        {
            { LanguageDataScript.LanguageCodeRes.ENG, script.enFontSize },
            { LanguageDataScript.LanguageCodeRes.CHT, script.tcFontSize },
            { LanguageDataScript.LanguageCodeRes.CHS, script.scFontSize }
        };
        DestroyImmediate(this);
    }
}```
#

i know disabled cannot take in this script because they are not active, but i dont want to make them active either

#

they should be disabled in prefab mode

vestal arch
#

you could just have it grab all those gameObjects

worldly hull
#

aight

vestal arch
#

uh if they're part of prefabs just modify the prefab

#

oh wait the instances have different settings don't they, nvm

worldly hull
#

in fact i just think of a new way for it

#
[ExecuteInEditMode]
class temp : MonoBehaviour
{
    private void Awake()
    {
        class[] allValidObj = GetComponentsInChildren<class>(true);

        foreach (languageChangeText element in allValidObj)
        {
            element.FontSize = new FontSizeDictionary()
            {
                { enum.ENG, script.enFontSize },
                { enum.CHT, script.tcFontSize },
                { enum.CHS, script.scFontSize }
            };
        }
    }
}```
#

the root of any prefabs will always be active anyway ๐Ÿ’ฉ

vestal arch
#

why not use GetComponentsInChildren<languageChangeText>(true)

#

what's with the class there

worldly hull
#

i just used it

#

oh they are languageChangeText, i shorten them because its too long lol

vestal arch
#

wdym too long

#

oh did it hit the discord limit?

worldly hull
#

i dont want anyone feels painful lol

vestal arch
#

i mean, that's just dependant on your screen size and zoom and whether you have the member list open

#

i think showing the actual code would be better than... that invalid code

worldly hull
#

its damn tedious bruh

#

even with scripts

last hemlock
#

does anyone know of a way to "undo" StaticBatchingUtility.Combine

#

like i can imagine a script like, storing what the data was before combine on meshfilters and meshrenderers, and resetting that

#

just wondering if anyone's tried and/or know of such a script already existing someplace

last hemlock
#

my theory appears to work anyway, a little bit hard to know if i've overlooked something but it does look correct

#

all i had to do was cache what mesh a meshfilter had originally, and reset that when I wanted to "uncombine" something

fair imp
#

hi guys, i tried opening this project in unity 2021.3.6f1, it keeps giving me an error as shown. how do i fix this ? retry just gives the same thing, continue opens the editor but the whole map is pink and there are multiple errors

leaden ice
leaden ice
#

You need to update Unity to the latest version of Unity 2021.3

#

That would be 2021.3.46f1

fair imp
#

okay ig ill just delete my current version and update to latest

#

what is the latest version

#

sorry havent done unity in years now

leaden ice
#

Read my message

fair imp
#

thx

leaden ice
#

Anyway it'll show up in the hub

radiant marten
#

if I have two colliders on a single object and I am trying to watch for when the player enters the only total combined collider shape(in this case like a T shape), what's the best way to handle this?

Right now I have it store the game object when OnTriggerEnter() is called and forget it when OnTriggerExit() occurs, but it still triggers sometimes when walking through the points where the two box colliders overlap

vestal arch
#

if they're for the same thing, why not use a single polygoncollider?

heady iris
#

Consider counting how many colliders you're overlapping

#

Add one when you enter, subtract one when you leave

heady iris
#

You could use a mesh collider, I suppose, but you'd need to make a mesh!

radiant marten
vestal arch
#

oh whoops

#

nah i shouldve noticed that, mb

heady iris
#

You could also use OnTriggerStay -- set a flag to false in FixedUpdate, then set it to true if anything is overlapping

radiant marten
hardy pasture
#

Is there a way to initialize the states in the state machine once with the owning gameObject and the components that the state will use?

#

This doesn't work:

    public override void OnStateMachineEnter(Animator Animator, int StateMachinePathHash) {
        base.OnStateMachineEnter(Animator, StateMachinePathHash);
        GameObject = Animator.gameObject;
        if (!GameObject)
            Debug.Log("Game Object is null!");
        CharacterComponent = GameObject.GetComponent<CharacterComponent>();
        this.RigidBody2D = GameObject.GetComponent<Rigidbody2D>();
        this.Animator = Animator;
    }
#

Animator.gameObject is null when it enters the state machine.

#
    public override void OnStateUpdate(Animator Animator, AnimatorStateInfo StateInfo, int LayerIndex) {
        CharacterComponent = Animator.gameObject.GetComponent<CharacterComponent>();
    }

This works and it will do for now, but this looks like it doesn't have good performance. I think I'll be able to move this to the OnStateEnter:

    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    public override void OnStateEnter(Animator Animator, AnimatorStateInfo StateInfo, int LayerIndex) {
        CharacterComponent = Animator.gameObject.GetComponent<CharacterComponent>();
    }

Which is better, but I'll still need to initialize the variables on each state enter, which is still not great for performance.

#

@hexed pecan can you please help if you don't mind the ping

#

I thought, animator's gameObject wouldn't be null when OnStateMachineEnter is called.
How do I initialize all the variables once when state machine enters?

proud gust
#

hi i have public array string, i want to pass arabic texts but when i pass string it like seperate each words and like make ewwish and not understandable. how to fix that

heady iris
#

I do not understand what the problem is. You'll need to show an example.

proud gust
#

correct word is

#

ุงู„ุณู„ุงู… ุนู„ูŠูƒู… ูˆุฑุญู…ุฉ ุงู„ู„ู‡

robust dome
#

you need rtl dawood

#

in tmp it is an option you can enable but i don know about the inspector fields

heady iris
#

It looks like Unity 6 finally has proper RTL text support in UI Toolkit (which is the system used for the inspector, by default)

#

but it has to be turned on by the creator of the UI; I don't know if the inspector does that

#

It looks wrong when I paste that example into the inspector in my Unity 6 project. Darn.

modern creek
#

What do these errors mean?

knotty sun
#

Network error at a guess

modern creek
#

A bit of googling says it's ... something messed up with unity, cause unknown. Potentially related to cache/appdata log file size, but mine seem reasonable (a few GB). I also have the cache on a windows drive pool, so maybe something is broken under the hood there

#

It seems to have gone away though. ๐Ÿคทโ€โ™‚๏ธ

#

I have a series of entities in my game that inherit from an abstract gameobject. I'd like to staple some particle effects to all the prefab entities. There's no prefab associated with the abstract GO, unfortunately. Is there a way to do this without linking each and every prefab?

IE:

public abstract class EntityRenderer : MonoBehaviour
{
  // stuff like:
  [SerializeField] private ParticleSystem CastHealParticleSystemPrefab; // x 20
}

public class ScoutRenderer : EntityRenderer { } // x 20

There's a ScoutRenderer prefab, but I have to link the scout to the heal prefab. If I have to link these all one by one, it's gonna be a pain in the butt.

steady moat
#

There is also reset

latent latch
#

Worth the time in making some prefab variants if you're going to be editing the base

dapper schooner
#

anyone have any issues with accessing the camera on an ios device? Attempting to access the camera and display is via a webtexture but just getting a black screen.

heady iris
#

The first thing that comes to mind is a permission issue

thorny hinge
#

Hi everyone!

I'm working on a 2D game with endless enemy hordes, currently capped at 200 enemies on-screen, but I plan to increase it or even remove the limit for an endless mode. I'm implementing health bars for enemies and considering using world-space canvases.

However, I'm concerned about potential performance issues with so many health bars. Are there any better alternatives to using world-space canvases to handle enemy health bars efficiently? Any ideas or suggestions would be really helpful!

heady iris
#

For huge numbers of enemies, I'd consider writing a little shader that renders a healthbar on a single quad

#

I did that for these meters -- not for performance's sake, but because it made it easier to get the exact look I wanted

#

(shh, i didn't steal these from Splinter Cell)

#

these are rendering with a normal Image in a Canvas, mind you

#

Before you do anything, though, profile it (:

#

compare a few things:

  • Many canvases with one bar each
  • One canvas with all the bars
latent latch
#

Each canvas is a drawcall so those tutorials are a meme

#

Most performant way is doing it single material shader using UVs to control the quad's texture gradient

#

or by doing it through vertex colors if you don't want to use a gradient

modern creek
# thorny hinge Hi everyone! I'm working on a 2D game with endless enemy hordes, currently capp...

Any time a canvas is dirtied - ie, anything on the canvas changes - the entire canvas has to be rebuilt. Normally the advice is "don't be concerned about performance optimization prematurely" but if you're using health bars and have any sort of layout managers to render them, then you're gonna be rebuilding your canvas every single frame, and this will probably be pretty expensive - enough to notice an FPS drop with very little going on.

Make each enemy have it's own canvas, so you don't have to rebuild all canvases each time anyone's health changes. Instead, the canvases for each enemy can happily redraw and not be rebuilt unless they need to.

As far as world space canvases (versus screen canvases) - it's fine. You're better off using the world space canvases so you don't have to do tricky math to convert world space coordinates to screen space coords - but be aware of z-order/ layer drawing. You'll want to ensure your canvases are in a separate (higher) layer than your game so that enemies don't cover up other enemies health bars - unless that's what you want.

heady iris
#

good point on using one big canvas

latent latch
#

Yeah that's the way, but I'm not too sure about those instancing calls for URP. I think those options are usually provided within the material itself

#

No wait that's correct if you're not changing the mesh data itself

hardy pasture
#

Will calling GetComponent get me the components on the gameObject?

#

Or on the Animator component itself?

#

Thanks, I'll just use GetComponent on the Animator.