Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Jimmer1980 on July 06, 2022, 03:54:43 PM

Title: Carry over player & health to next scene
Post by: Jimmer1980 on July 06, 2022, 03:54:43 PM
Hi everyone, so I’ve searched forums & the web , but I can’t seem to find a solution to my particular problem. I have a playmaker health system linked to my player prefab , all is working well , but as soon as I change scenes I cannot work out how to reconnect my health manager to the player without using do not destroy on load , which causes duplicates, I’ve also tried additive / async loading also additional after the initial death on the second scene my Npcs just ignore the player ? this is a vr project, using playmaker / emerald ai & vrif… apologies if my description is a little vague . Is there an action I can use in the second scene or first , to simply carry the two onto the next scene ? Any help would be appreciated.

Title: Re: Carry over player & health to next scene
Post by: ch1ky3n on July 06, 2022, 04:49:11 PM
is your health management system a prefab as well ?
if so, then it shouldn't be any problem.

Try to make a prefab of everything, so when you are faced with an empty scene and when you drop all the prefabs, it all works together.

Not a pretty solution, but you could register Your player to Global Variable,
Thus, your health manager could refer you at any point in any scene.

Best of Luck




Title: Re: Carry over player & health to next scene
Post by: curb47 on July 08, 2022, 04:35:20 AM
You ought to create a GameManagerObject, and make it a singleton with Don't Destroy on Load, and use it to store all variables when loading new scenes.

For things that manage stuff like controllers, variables etc make it a singleton, what that means is that there will be only one instance of that script/object active at all times. There is a singleton action on the Ecosystem.

The game manager serves as a 'bridge' between scenes, and a starting point for all variables being set. ie - when you play your game, you get all your objects that require variables to 'get' the variables from the GameManager, then 'set' the variables on the FSMs, then when you load a new scene, get all your FSMs to 're-set' the variables back on the GameManager before loading the new scene. When the new scene loads, the same steps are followed - get all the FSMs to 'get' the variables from the GameManager etc etc.

The game manager is never destroyed, and carries variables from one scene to another. It's a really handy thing, because as your game develops, you'll find yourself wanting to carry more than just Health from one scene to another. Once you get your head around it, it's super easy to transfer any variable, and actually opens up creative options because you're not restricted.

I've just had a quick look at my GameManagerObject in the game I'm building and it currently carries 61 variables from scene to scene, including Health, Inventory, Tech-tree progress, weapons, fuel, shields, shield efficiency, etc etc etc etc.

Check out this video... I'm not sure if he has the Singleton action included, I've only just skimmed through it, but yeah, singleton is important.



Make a GameManagerObject
(https://i.postimg.cc/1XphFWsC/gmo1.jpg)

A really simple FSM to set it up...
(https://i.postimg.cc/8C3q08CX/gmo2.jpg)

Most importantly, the object 'gets itself' and stores itself as a variable (GameObject) and this variable is set to Global.
(https://i.postimg.cc/sXhtFnQj/gmo3.jpg)

(https://i.postimg.cc/c1TPp868/gmo4.jpg)

Title: Re: Carry over player & health to next scene
Post by: Jimmer1980 on July 10, 2022, 02:03:12 PM
Fantastic, thanks for the reply’s, I’ll give it a go and let you know 😜👍