I am trying to abstract my GUI out so I don’t have to have a spaghetti of GameObject references flung around all my GUI buttons. I’ve created a ScriptableObject that stores the information about a menu, including a GameObject[ ] which is all of the GUI panels that need to be activated. My mode switcher will just iterate over the array of the current mode and disable them, and then iterate over the array of the new mode and enable them.
The problem is, I cannot seem to get the Inspector to accept dragging my game objects onto the created asset, even if I specify an array size and get empty rows. Is there no way to embed GameObjects inside ScriptableObject .assets? I can’t imagine why not, since they both fall under Unity’s serialization…
IF your gameobjects are only serialized to the scene then you cant drag them onto prefab fields or file system assets. This is because prefabs and file system objects persist across multiple scenes. So if a scene other than the scene your game objects were serialized in is loaded, the prefabs/file system objects would loose those references.
Oh, that’s true…I had forgotten that because my current project is rather small and only one scene. What I ended up doing was creating a script with the reference holders I needed, and putting a copy of that script on each menu with a method to switch between them. It’s not as nice and compartmentalized, but it functions.
Why don’t you just make each menu a prefab? Then load each respectfully when needed? If you have your asset already created you can totally do that. Thats what I did with having certain menus pop up when it detects an iOS vs standalone. I needed this for the virtual joystick and keyboard config settings. No need to display a keyboard option when on an iOS device and no need to display a virtual joystick on a computer.
That sounds great for most projects, but this one in particular is so menu-driven (and the menus are so lightweight anyway) that it makes more sense to leave them resident and retaining their state. The basic flow of the game is “set stuff up in menus, then do a run of the dungeon” and repeat, and most of the time the runs will be of only a few minutes. Each of the menus has a role in configuring the next run, and it would take a lot of unnecessary scripting to restore each menu’s state each time it’s brought up when I expect it to be brought up so frequently.
For my next project, though, I’ll definitely do menu prefabs, since that would solve my original problem nicely.