Author Topic: Return created object?  (Read 2319 times)

Adriaan

  • Guest
Return created object?
« on: May 26, 2013, 06:27:14 PM »
Hello!

Probably a simple question with a simple answer: how do I return the created object from this?

  1. TNManager.Create(enemyPrefab, somePosition, Quaternion.identity);

I hopes something like the following would work, but unfortunately it doesn't.

  1. GameObject enemy = TNManager.Create(enemyPrefab, somePosition, Quaternion.identity);

How do I get around this issue?

Adriaan

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Return created object?
« Reply #1 on: May 26, 2013, 07:03:06 PM »
It's a commonly asked question on the forum. The answer is that you don't. Creation call is delayed and happens on all clients at the same time, so there is no object at the time when you create it (as it happens later).

The proper way of doing this is to have a script attached to this object that will do something in its Start() function (after checking tno.isMine if you need it -- only the person that created the object will have TNObject.isMine set to 'true'.)

If the object doesn't have a TNObject script on it, then you can still check if you are the one who created this object by checking TNManager.isThisMyObject in Awake() of a script attached to this object.

Adriaan

  • Guest
Re: Return created object?
« Reply #2 on: May 26, 2013, 07:04:46 PM »
Ah, I get it. Thank you!