[Unity 2021.3.5f1 - AC v1.75.5]
Hi Chris!
I admit this is probably not much of a big deal for me, but I don't think it ever happened to me before the latest update (or the last couple updates).
This happens in every scene I enter for the first time.
Take a GameObject with a SpriteRenderer and a Remember Visibility script attached to it.
If I deactivate and reactivate the entire GameObject:
But - and this is how I remember always being like or, in other words, the one I "expect" - if I am reentering the scene from either a different scene or from loading a save game, if I deactivate and reactivate the GameObject, the state of the SpriteRenderer doesn't change in either of the above cases.
I know that enabling\disabling GameObjects altogether is bad practice and I should probably just work with SpriteRenderers, but I was wondering whether this was intended behaviour or not.
Thanks a lot!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Recreated. I'll need to give it some thought - can you recall when your expected behaviour was how it did behave?
I remember it would always work the way it works now when you re-enter or load a scene. In other words the state of the SpriteRenderer would not be reset when switching the GameObject off and on again.
In a lot of scenes we have characters whom you can talk with. For each character I usually have 2 GameObjects that I switch between:
So when a conversation starts I switch off the one I use for their "idle" animations and turn on the one I use for conversations and when conversation is over I do the opposite.
Have you tried swapping out their Animator Controller asset instead of the whole GameObject?
Unfortunately that wouldn't be an option for me, now. Or rather... I think I would have to swap out a bunch of different Components, probably 🤔
For those specific animations I'm using a custom-ish system in conjunction with PowerSprite Animator, which doesn't rely on using Mecanim in a "traditional" way.
The easiest workaround I can think of, right now, would be to just make sure I always check for the SpriteRenderer state when I turn off and on the GameObjects and set it accordingly.