playMaker

Author Topic: GUI with prefabs and multiple levels  (Read 4059 times)

tam

  • Playmaker Newbie
  • *
  • Posts: 11
GUI with prefabs and multiple levels
« on: March 14, 2013, 02:04:36 PM »
Hi all,

I'm trying to make a multiple level game which shows health and points in gui text.

This works fine when I have pick ups / managers / gui in the hierarchy, but not when I put this stuff into prefabs (which seems to be a Unity issue).

So how would I go about having a health and points system that will work across multiple scenes? If I leave everything in the hierarchy and load level additive then I'll have many copies of the same assets, and if I load level without additive then I'll lose progress between levels.

I realise this sort of question has been asked before, but I searched and read the existing similar threads and didn't find an answer. There must be a technique I'm just not getting my head around that can solve this.

Thanks for your help,
Tam.
« Last Edit: March 14, 2013, 05:04:21 PM by tam »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GUI with prefabs and multiple levels
« Reply #1 on: March 14, 2013, 02:22:51 PM »
You'll probably get a nice detailed response to this.. but since I don't know the answer as I haven't addressed scene changes before I'll just mention that there is a Don't Destroy On Load action that may be helpful.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

tam

  • Playmaker Newbie
  • *
  • Posts: 11
Re: GUI with prefabs and multiple levels
« Reply #2 on: March 14, 2013, 05:04:05 PM »
Thanks for the quick reply, Lane.

The Don't Destroy on Load wouldn't work in this instance.
For example, I have an exit platform which has a trigger which I want to talk to a GUI text and display a message like "Press E to Exit". This exit is a prefab as it needs to have the same functionality in all levels, but I need to place it in different places in each level. So the Don't Destroy on Load wouldn't work because the exit would remain in the same place.

I intend for my game to have 10 to 12 levels so copy and pasting PlayMaker functionality isn't really a good solution either as this would take me a lot of time.

I feel like there must be a clever way around this problem, but I'm not sure what it is. Hopefully someone on this forum has solves this problem and can share some insight.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: GUI with prefabs and multiple levels
« Reply #3 on: March 15, 2013, 12:04:20 AM »
Well, I think it might be worth looking into setting up a set of actions to start at the beginning.... So, how i'd probably try is to take an object, add in a new state and make that the start state and in that one i'd have it collect all the data in the scene it needs to work from.

So, the way i'd try would be to make the start state have a string of actions in it to collect the appropriate data. so, if it needs to access the player data, tell it to do a find and filter kinda thing... or if it needs to find the player camera and you don't want to hard-wire it in, there is an action to get the main camera and from there you can do get parent/child actions if it's nested somewhere.

what you'd probably benefit from is not hard, but it takes time to get into the groove and isn't the easiest to explain via text.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: GUI with prefabs and multiple levels
« Reply #4 on: March 15, 2013, 07:18:30 AM »
Wasn't there a more solid way to do this by saving the data into a text file? I wonder how mobile/web deployments use cookies to store player data across a lot of game sessions.

Seems like I remember reading something about it last year around here..
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

tam

  • Playmaker Newbie
  • *
  • Posts: 11
Re: GUI with prefabs and multiple levels
« Reply #5 on: March 15, 2013, 10:26:30 AM »
This setting up state sounds like it'd work out for what I'm trying to do.
What would I look into to find a tutorial for this? Initialise state?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: GUI with prefabs and multiple levels
« Reply #6 on: May 14, 2013, 01:19:15 PM »
Hi,

For this, dontdestroyOnLoad is the way to go, mixed with a custom management for not having duplicate gameObjects if each of your scene features the same prefab. Let me explain a bit.

 If you are developing several different scenes, you need to run them separatly, which means, they need to run out of the blue, and so you will have to have your health bar prefab on each scene.

 when you load these scene within your actualy game, then you will get a conflict between the currnet health bar and the one coming from the scene you will load.

 to solve this, each prefab that needs to exists only once, need to have some custom checks to destroy themselves if they exists already.

Global var is perfect for this, have a global bool flag for each of these prefab, if false, you live and set that to true, if false, you destroy yourself.

This also will likely call for some special initalizer coming from these prefabs. Again global var will come hand here as well, else simply fire some custom gloval events when your prefab is ready, (  and only when it checked it was not redundant, for example after you received the built in event "LEVEL LOADED")

bye,

 Jean