playMaker

Author Topic: Game Manager loaded into new scene  (Read 867 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Game Manager loaded into new scene
« on: December 14, 2020, 03:00:17 AM »
Hiya, been a little while. I hope you're all well.

Due to intense work commitments I've not touched my game for a few weeks, but now I'm back on it and picking up from where I left off...

The last thing I asked about was carrying variables from one scene to another, using 'Don't Destroy on Load', and it all worked out perfectly...

https://hutonggames.com/playmakerforum/index.php?topic=22928.0

Continuing the same theme, I've hit another brick wall (story of my game-dev life!) . I have 2 scenes -  1) the main gameplay which is basically a spaceship whizzing around shooting stuff, and 2) when you're docked in the Mother ship which is more about resource management and upgrading weapons etc.

I have a 'Don't Destroy on Load' Game Manager defined in scene 1), which carries all the variables I need into scene 2).

My question is probably a total n00b thing,- When I'm in editor mode, and setting up the UI, etc for inside Mother Ship (scene 2), how can I use all the variable values and names from the Game Manager if it doesn't exist in the Hierarchy of the scene?

Make sense?

Thanks in advance.

J.

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Game Manager loaded into new scene
« Reply #1 on: December 14, 2020, 07:15:48 AM »
You mean when entering Play Mode in the editor I presume?

Option 1: Make sure you always have a Game Manger in every scene.
Option 2: Make sure you always load scene 1 before scene 2 even in the editor.

I think it really depends on how you've setup the structure of your game, I tend to just have an instance of my Game Manager in the hierarchy of every scene.

Does scene 2 depend on variable values on the Game Manger that are set in scene 1?

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Game Manager loaded into new scene
« Reply #2 on: December 14, 2020, 07:57:40 AM »
Hi LordHorus,

I think I've sorted it out now. I was looking for a way to get the Game Manager into scene 2, not in Play Mode, but in edit mode; you know, setting UI sliders and stats based on variables saved to the Game Manager in scene 1.

"Does scene 2 depend on variable values on the Game Manger that are set in scene 1?" - Yes, exactly. The whole of scene 2 depends on the variables set in scene 1. Scene 2 is made up entirely of GUI, where you can transfer resources, upgrade weapons and utilities etc.




djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Game Manager loaded into new scene
« Reply #3 on: December 14, 2020, 08:23:24 AM »
Hi.
The Gameobject that will be set as Don't destroy on load, you can store in a global.
this way you can reference that object.

in our game we have a separate scene that is loaded from intro and also player is a separate scene.

in editor you can open multiple scenes (drag and drop a scene in the current open scene.
If i need to setup several variables i usually drag the target object in the action, then on the action, select the fsm and variable.
Then i replace the target object with the global for that target.
this way there is less chance for typo's.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Game Manager loaded into new scene
« Reply #4 on: December 14, 2020, 09:31:47 AM »
Hi djaydino,

Yes, that sounds like a good work-around. I've been dragging different scenes into the editor for other functions, and have recently been breaking my game down into different Scenes and using load Additive Scene. It's a really efficient way of working!

For this particular 'problem' (it's not really a problem, it's just my lack of experience) I just made a prefab of my Game Manager object, and dragged that into Scene 2 in order to get the variables correct, then deleted the prefab from the scene. Upon starting the game in Scene1, and entering the Mothership-Scene 2, it all works fine and the variables do what they are meant to.

I've probably done it the long way, but it's worked out.

Thanks.