I’m working on an app that requires objects to be clicked on then a UI panel updates to show properties of that object as well as buttons and sliders relating to that object. I can’t find a good way to do this.
I have tried a few things, but neither seem efficient:
When an object is selected, show a preset of options relating to that type of object, then remove all UI Listeners, set the values (of sliders and dropdowns) to that object’s info, then add the listeners back, and done.
Each object has an inactive UI element showing all of its properties/options, and they get enabled/disabled depending on which object is selected.
Number 2 is much simpler overall–less chance of errors, and easier to save and load the values, but it potentially ends up with a lot of inactive UI elements. This might be a non-issue, but I dunno.
Has anyone else done a system like this (think a very basic inspector but at runtime) and would be willing to share?
The most stable and convenient way is to have everything instantiated and subscribed from game start, that’s how it’s done in project I work right now. There is no need to dynamically remove or unsubscribe from anything.
@Kurt-Dekker
Oh phew, I was nervous that it was a really dumb way of doing it, lol.
I didn’t think about using Destroy/Instantiate, thank you for the suggestion!
@Lekret
The objects I am using are imported at runtime, so it’s not possible to have that set up that way. But I’m glad to hear that other people are doing similar things!
Definitely better when things scale unbounded, like you are downloading AssetBundles that go into this thing.
But stick with the basics, enable / disable, as @Lekret backs me up there. It will keep it super-simple.
ALSO : do NOT rely on the enable / disable being saved at any given point. ALWAYS enable and disable 100% of the things when you Start(), and when the things change. That way you can’t screw up the game by inadvertently saving something disabled or enabled.
ALSO : for almost everything, you do NOT necessarily want the .enable property. Everything above that I wrote means .SetActive(true/false) on the root GameObject itself.
Thank you for the info, it’s super helpful.
I actually meant using SetActive on the gameObject itself, instead of enabling components. I’m mainly saving the values of UI elements (sliders, etc), not the bool active/enabled state of the components/objects