B
B
bad22vk2022-01-09 00:37:39
User interface
bad22vk, 2022-01-09 00:37:39

Unity dontdestroyonload how should it interact with the UI on the stage?

Good afternoon everyone!
Found the dontdestroyonload method to save the GameObject between scenes.
But Button != GameObject. Accordingly, I cannot apply it to a button in my UI.

The problem is that the button has a caroutine and doesn't work after being clicked for a while.
And in order to save this position, you need not to destroy the object when changing the scene.
I couldn't find anything other than dontdestroyonload , and I can't apply it to Button either.
Save-help!!!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Ente, 2022-01-09
@bad22vk

Dontdestroyonload is essentially a crutch, it is better to use multiple scenes, dynamically loading and unloading them. You can pull the UI into a separate scene and always keep it active, since any game can have hundreds of levels and locations, but the UI will always be the same for them.

F
freeExec, 2022-01-09
@freeExec

1) Any object on the stage is a GameObject, even a button.
2) dontdestroyonload only works on root objects, and your button is at least in the canvas

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question