Forum rules - please read before posting.

Remember Visibility: SpriteRenderer state resets if GameObject is being deactivated and reactivated?

[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:

  • while the Visibility on start is set to ON and the SpriteRenderer is DISABLED: the SpriteRenderer becomes ENABLED
  • while the Visibility on start is set to OFF and the SpriteRenderer is ENABLED: the SpriteRenderer becomes DISABLED

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!

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:

    • One GameObject holds their "idle" animations, when you're not talking to them
    • The other holds their conversations-related animations and lipsync

    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?

  • edited July 2022

    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.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.