playMaker

Author Topic: Setting up prefab to find a gameObject at runtime  (Read 1746 times)

richardh

  • Junior Playmaker
  • **
  • Posts: 97
Setting up prefab to find a gameObject at runtime
« on: February 01, 2015, 04:22:32 AM »
Can someone tell me how to setup a prefab that requires an object in the scene at runtime please?

The link between my FSM and the player is lost once I make the FSM part of a prefab So i need to reference the player so the prefab finds it at runtime. But I can't figure out how.

What events do I need to use please?

thanks

R

richardh

  • Junior Playmaker
  • **
  • Posts: 97
Re: Setting up prefab to find a gameObject at runtime
« Reply #1 on: February 01, 2015, 08:03:55 AM »
So, to be a bit clearer, if I want to reference a gameObject in a prefab so that when the prefab is created in the scene it will find the gameObject, what do I do?

thanks

richardh

  • Junior Playmaker
  • **
  • Posts: 97
Re: Setting up prefab to find a gameObject at runtime
« Reply #2 on: February 01, 2015, 10:00:54 AM »
I think I've sussed it.

I created a global gameObject variable called 'Player'.
In the prefab I used event 'Find Object' :
object name [none]
with tag [Player]
store [global/Player]

This seems to work. Is this the right approach?

thanks
R