Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Pigomigo on April 20, 2013, 12:15:14 PM

Title: How to do custom setup behavior on an object after creation.
Post by: Pigomigo 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?
Title: Re: How to do custom setup behavior on an object after creation.
Post by: iByte 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.
Title: Re: How to do custom setup behavior on an object after creation.
Post by: ArenMook 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).