How to prefab a complex object like an UI without losing individual child prefabs like buttons etc.?

In my game I’m now at a point where I want multiple scenes and I also want to start preparing it for multiplayer. Currently I have a complex UI which is supposed to be tied to the player, and later each individual player. I want to turn it into a prefab so I can instantiate it at will, but I have dozens upon dozens of individual prefabs within the UI such as buttons, labels, panels, sliders etc. I don’t want to lose their prefab connections because then I would have to edit them individually later on.

Basically how do I work around the lack of nested prefabs? :stuck_out_tongue:

I’ve done similar things before, but then I made it such that the main prefab instantiates all child prefabs at runtime, but with UI this is not ideal because then I can’t work on it anymore?

Any tips or alternative approaches to this? I’ve never worked with multiple scenes before and the only multiplayer games I have made have been based on simple tutorials so this is a first for me. :confused:

EDIT: There wasn’t enough room to change the thread title, but I feel like I found a good solution to my problem. Look at my last reply for what it was.

I don’t really follow. Have you looked at additive scene loading?

Look at Inventory Master for an example of runtime UI

Heh, I received Inventory Master for free at one point through the Level 11 program, but there was nothing of value in there in my opinion. Just another asset that tries to do everything, but does nothing properly. And I don’t see how it handles any of the things I want, it’s just a hard coded mess. I actually wanted a proper inventory for this game, but every single inventory asset out there is just rubbish in my opinion so I made my own.

Additive scene loading is just loading another scene on top of my current scene? I tried that and I ended up with my dungeon on top of my town. And it still doesn’t help in any way with my issue the way I see it.

My problem is this. I have this structure for my UI:

- Canvas
-- Panel
--- Title
--- Button
--- Slider
--- Etc.
-- Panel
--- Title
--- Button
--- Slider
--- Etc.
-- Etc.

Title, Button, Slider are prefabs. If I turn the entire Canvas into a prefab I lose the prefab connections for every single prefab beneath it.

And if I don’t turn the Canvas into a prefab then how would I create 1 canvas per player in a multiplayer game?

I think I may have found a workaround though. I’ve created a “Workshop” scene where I have the “raw” hierarchy for my Canvas. And then I duplicated that Canvas and turned the duplicate into a prefab that I can instantiate in my game scenes. That allows me to instantiate my UI at will, and if I want to edit it I open the Workshop scene where I still have the unmodified UI. Then I make my changes to it there and just duplicate it again and overwrite the prefab.

It’s an extra step, but I imagine that’s how people do it? It seems like a solid workflow.

But now I have 300 errors to fix because instantiating everything at runtime meant all the existing code broke because it can’t find the game objects anymore. :stuck_out_tongue: Will update this when I can get things working again and share my experience with doing it this way.

If anyone has alternative approaches to this I would love to hear them.

I’m talking about this, its free https://www.assetstore.unity3d.com/en/#!/content/26310

Also I mean additive loading for the UI so you can keep all your interdependent references

I’m not sure why you’d have a canvas for every player in the game, each client just needs one canvas for their user interface.

Yes, that’s the one, I’m pretty sure it costed money before. The reviews on it leads me to believe I’m correct. But either way it’s rubbish and it doesn’t help me here. :stuck_out_tongue:

Hmm, now I get what you’re saying. I went back to the last multiplayer tutorial I did and the canvas is actually present in the scene at all times. It was so long ago I forgot how it was done. Multiplayer is still far from my top priority, but then I know that at least, thanks. :slight_smile:

Either way, a good workaround for the lack of nested prefabs seems to be the way I’m trying to do it now at least, but we’ll see.

If you read Unity’s guide you’ll see they recommend using multiple canvases.

Gah, should never have mentioned UI, canvas or multiplayer. Thread derailed. :stuck_out_tongue:

The post was intended to be about finding a good workaround for the lack of nested prefabs. Like I said I’m currently trying to keep all raw game objects in a separate scene and I only prefab duplicates of the raw game objects. Seems like it’s working fine and it’s not that much more of a hassle, but I was curious if anyone else had any other approaches or alternatives to the same problem, which I imagine is a problem everyone using Unity comes across sooner or later.

Sick! Okay, I’m starting to get the hang of this now. :smile:

I feel like the number one rule for game development in Unity should be:

It feels like if you have that down then you can easily do local multiplayer, online multiplayer or anything you want later on, and it’s not harder than the alternative, it’s just different. Rule number two is tied to rule number one and it is:

Realizing these two things and refactoring around them made it possible for me to add the Network Lobby asset to my game and have it work instantly. I knew this refactor was coming at some point because I started this project quick and dirty, but I wasn’t expecting to have to tackle it this early, but now my game is hopefully a lot more robust.

But now I need to figure out how to do scene changes in a multiplayer game. Can one player be in the town scene while another player is in the dungeon scene and can they go back and fourth between the scenes? Time will tell. :stuck_out_tongue:

I’m marking this as solved because the answer to my original question seems to be what I’m doing at the moment. Just keep all your unprefab’ed objects in a separate construction/workshop scene where you work on them and then just duplicate them when you want to create or update a complex prefab containing a lot of child prefabs.