I’m currently about two thirds of the way through the Block Blaster section in Unity 2D. I’m having some issues with my prefab canvas! At the moment I have a start screen and a game over screen. Obviously I want a couple of buttons on each of these for starting and quitting the game. However, when I add buttons to the scene and next them under the Game Status > Game Canvas hierarchy, the buttons are applied to all scenes!
I’m not applying the buttons to either the Game Status or Game Canvas prefabs, they’re still greyed out which I thought meant they were unique changes to that instance of the Canvas, in that scene. I’ll post a couple of pictures to show what I mean
The only solution I have found so far is to create a second Canvas in each scene, but I don’t know if this is a proper solution and/or good practice. Hope you can help!
In your first screenshot, you are in the prefab mode. I can see that because the title says “Game Status”. In your second screenshot, it says “Start Menu”. That’s the scene mode. Since the Game Status game object is blue, it is connected to a prefab. If you make changed to the prefab, these changes get automatically assigned to the Game Status game object in the scene.
If you have a Game Status game object in each scene and if those game objects are connected with the “Game Status” prefab, the changes in the “Game Status” prefab get applied to all aforementioned “Game Status” game objects in the scenes.
Maybe it does not make sense to create a prefab in this case because you want to create different GUIs. A prefab is supposed to make your life easier. If you have to change a lot in the game object which is connected to the prefab, a new prefab for this game object or no game object might make sense.
To disconnect the game object from the prefab, click the right mouse button on the game object, then on “Unpack Prefab Completely”. Bear in mind that the game object cannot get reconnected.
Making a different prefab is definitely a helpful idea. I followed the lessons exactly and discovered this issue, could it be worth suggesting the use of a separate prefab for the Start Game and Game Over scenes in the course?
Just to clarify, are the changes applied even though I’m not clicking ‘Apply All’ on the prefab objects?
If you change a game object in the Hierarchy and click on “Apply all”, the connected prefab will get changes, and the prefab will update the game objects which are linked with it and its fields respectively.
If you change something directly in the prefab, all game objects that are linked to the respective fields of the prefab get updated. The difference between prefabs and game objects is crucial.
It is, we implemented it so that the score carries over from level to level
Then as far as I know, this has nothing to do with prefab issues.
Game Status is a singleton so it will remain in play and carry over to the next levels. Your canvas and all it’s buttons are children of Game Status and will carry over with it.
That’s a useful summary
So if I don’t click on Apply All after altering an object nested under a prefab in one scene, it won’t propagate the changes to the same prefab in other scenes?
I typically don’t have canvases that go from level to level, personally. I imagine there are lots of ways to doing these things, but yes, I often have multiple canvases in my scene and have a “Canvas Manager” that activates them and deactivates them as appropriate.
If you want, you can even put those extra buttons you made on a separate canvas that only appears on that screen and just have both canvases working at the same time, but only one carries over with the singleton when the next scene is loaded.