Forum rules - please read before posting.

Button States Not Being Saved

I've got a scene where certain UI button sprites change, depending on certain situations in the game.

I'm changing these sprites via Actionlists by using Object: Call Event and using sprite.Sprite to change the button image, and using the same method to disable the button by changing the button's 'interact' boolean. This all works great.

However, when the game is saved, the button sprite updates and its enabled/disabled states are not saved, ie. when the save game is loaded, the button's original sprite returns and the button is interactable again. Everything else in the game saves at it should.

They all have Constant IDs so I'm a little confused. Any idea why this is happening?

I'm on Unity 2021.3.19f and AC 1.77.0.

Comments

  • edited May 2023

    A Constant ID component merely provides a reference for the object its attached to. It doesn't save any specific data about that object.

    To save the sprites and enabled/disabled states of a UI Button component, you'd need to write a custom Remember script that can serialize and deserialize this data. A tutorial can be found here.

    However, this would be very tricky given that you'd need to save sprite changes.

    A much easier approach would be to instead use an Animator component to control these properties with a pair of animations, e.g. "On" and "Off". Instead of using Object: Call event, you'd instead use Object: Animate to control the animation playback - and, in turn, the Button's properties.

    Saving these states would then be a case of attaching the Remember Animator component, which would save and restore the state of the Animator.

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.