Forum rules - please read before posting.

Remembering UI Elements

I'm trying to create a basic map system (as a menu) with Unity UI, which would show locked (red) and unlocked (green) doors displayed as simple images. When unlocking a door for example, I will use the hide/show UI element action respectively (hide the red door, show the green door).

Is there a "remember" component (similar to remember mesh renderer etc) that I could apply to the UI elements? The only way to do it that I can think of, is to make every door state a global variable that is checked each time the map menu is opened - this is what I am trying to avoid.

Comments

  • Custom Remember components are possible if necessary (tutorial here), but you should be able to get by with Remember Animator.

    Is it possible to combine the green/red doors into a single white door, and then affect its colour in the Image component? If so, you could attach an Animator that changes it to green/red through animation. The Remember Animator component can then be used to save the animation playback state.

  • Ah yeah I never thought of using the Animator. The thing is though, this map is supposed to be accessible from any scene - if the component is added to the UI prefab rather than in-scene, would saving still work properly?

    I'm also unsure how to structure the animator, would every door need it's own animator, or just one on the main canvas with each door on a separate layer, with it's state altered via an e.g locked parameter?

  • if the component is added to the UI prefab rather than in-scene, would saving still work properly?

    I'd certainly like for that to be the case. I'll look into this.

    would every door need it's own animator, or just one on the main canvas with each door on a separate layer, with it's state altered via an e.g locked parameter?

    I was thinking of one Animator per door - that way, you can have each rely on the same Animator Controller asset.

    What should be the case already, however, is that a custom Remember component attached to the Menu's Canvas root should save/load correctly. It should be possible to have a script handle both the saving/loading, as well as the locking/unlocking of doors during gameplay.

    How are you currently handling this? Personally, I would have gone down the Global Variable per-door route, so that the locked state of a door in the scene can be synced with that of the map.

  • Currently the door lock states are (mostly) local variables, this is why I was thinking of just having the images save would be quicker. Since that would require a new script however, it would probably be quicker - in my case at least, to just convert them all to globals as per the original idea.

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.