playMaker

Author Topic: Best practice for finding un-instantiated objects?  (Read 2021 times)

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Best practice for finding un-instantiated objects?
« on: March 06, 2017, 08:54:34 AM »
Hi,

I am just curious on how people usually assign/declare varibles that has not been instanitaed into the game yet.

In my game there is a lot of stuff (treasures, enemies, NPS etc) that have a "Find game object with tag: Player" on them. The thing is it's a multiplayer game with Photon so the when the game starts the player have not yet been instantiated (Because the user needs to create a room before the player instantiates).

So all the "stuff" in the scene obviously can't find a  player yet (because no player yet exists) and the variables don't get assigned.

There are plenty of different ways to solve this small issue but I was just courses on how people usually solve this. IS there a "best" way to solve this?

bye,
Christian

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best practice for finding un-instantiated objects?
« Reply #1 on: March 07, 2017, 12:57:23 AM »
Hi,

The Player should broadcast a global event "ON PLAYER INITIALIZED" or something like that, then all interested fsm can catch this and store the sender of this event which will be the player.

 That's one way that works for me, but looking for gameobejct by tag is also good, but NEVER use FindGameObject using the name, it's not performing very well, and if you change the name it won't work anymore...
 
Bye,

 Jean

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Best practice for finding un-instantiated objects?
« Reply #2 on: March 07, 2017, 10:33:19 AM »
Hi,

The Player should broadcast a global event "ON PLAYER INITIALIZED" or something like that, then all interested fsm can catch this and store the sender of this event which will be the player.

 That's one way that works for me, but looking for gameobejct by tag is also good, but NEVER use FindGameObject using the name, it's not performing very well, and if you change the name it won't work anymore...
 
Bye,

 Jean

Alright good points! I'm still a bit new to Playmaker so I haven't got into how "broadcasting" works yet....but judging by the name it sounds pretty straightforward, so I think already got a good idea on how it works. Gonna look into that solution tomorrow. Thanks jean :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Best practice for finding un-instantiated objects?
« Reply #3 on: March 09, 2017, 01:25:43 AM »
Hi,

Good luck :) make sure you watch videos on this and check out all the samples on the Ecosystem, also follow me on twitter to get news and updates on the Ecosystem content and playmaker in general.

Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Best practice for finding un-instantiated objects?
« Reply #4 on: March 09, 2017, 03:00:22 AM »
Hi,
You might want to check out the "Global events and Global Transitions" tutorial on the User Tutorial wiki page
It is in the Beginner section.