Author Topic: How to do custom setup behavior on an object after creation.  (Read 1966 times)

Pigomigo

  • Guest
How to do custom setup behavior on an object after creation.
« on: April 20, 2013, 12:15:14 PM »
I understand why TNManager.Create doesn't return a reference to the new object. However, I am confused how I would do any setup on that object that was custom to the specific instance that was created.

For example, lets say I have a player who is flying a jet. He wants to fire a missile that will home in on a specific target in the level. I have a missile prefab, but when I instantiate the missile it doesn't know what its target is. I need to pass that data to the specific missile instance that was created, but my player doesn't have a reference to it, so I am not sure how.

What is the correct way to handle this? I could have the player create a missile, then wait around for an unclaimed missile object to exist, then "claim" it and do stuff with it, but this seems cumbersome. Is there a better way?

iByte

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: How to do custom setup behavior on an object after creation.
« Reply #1 on: April 21, 2013, 12:56:02 AM »
In the start method of the instantiated object check

if (TNManager.isThisMyObject) then do whatever you need to track this object by this player.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to do custom setup behavior on an object after creation.
« Reply #2 on: April 21, 2013, 07:08:29 PM »
TNManager.isThisMyObject should ideally be checked in Awake() rather than Start(). If you need it in Awake, Update, or any other function, check tno.isMine (where tno is TNObject).