playMaker

Author Topic: Prefabs and variables [SOLVED]  (Read 2662 times)

failtruck

  • Playmaker Newbie
  • *
  • Posts: 6
Prefabs and variables [SOLVED]
« on: March 18, 2013, 07:57:49 AM »
Hi,

I've been working with Playmaker for a few weeks now and loving it, but I have a quick question about the best practice for prefabs and variables.

In my scene at the moment I have a NGUI gui and bunch of bad guys.  When I make the badguys dead (via a large axe) they should drop sweet sweet loot.  The loot is a gameobject with a trigger collider that controls a GUI windows that says "press E to pickup", then when you press E its adds a value to your gold amount then it destroys itself.  When the object is in the scene on its own it works fine, but when its brought in from a prefab (via create object) all its references to any object on already in the scene have gone (most importantly the NGUI label that the collider controls).

What is the best way of making sure the FSM keeps the reference to the label?
« Last Edit: March 18, 2013, 09:16:39 PM by Alex Chouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Prefabs and variables
« Reply #1 on: March 18, 2013, 09:58:57 AM »
Hi,

either you don't and you fire a global event that your ngui label will receive  because you will have added a playmaker fsm component to that gameObject and deal with it locally, or you can save the gameObject reference in a global variable instead.

when you store scene's gameObject in a fsm global var they never get lost, and prefabs can use them at will without fear.

 does that make sense?

bye,

 Jean

failtruck

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Prefabs and variables
« Reply #2 on: March 18, 2013, 11:54:22 AM »
Makes total sense.  In fact, I've just tried it and its now working perfectly!  Thanks!  and sorry for putting this in the wrong forum.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Prefabs and variables
« Reply #3 on: March 18, 2013, 02:48:30 PM »
Honestly, using Ngui or Unity's native Ui, this is actually a playmaker thing.

Though, to be honest, i wouldn't have thought to use the global variable. I'd probably have the object that needs to do all this have a start state setup that when it instantiates, it looks for (the find actions probably) the GUI object so that it knows what to tell to fire off the gui-based event.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Prefabs and variables [SOLVED]
« Reply #4 on: March 19, 2013, 01:32:06 AM »
Hi,

 you are on the right forum :) else I might have miss something...

bye,

 Jean