Author Topic: Finding what you just created  (Read 4248 times)

greyhoundgames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Finding what you just created
« on: May 19, 2014, 10:04:41 AM »
I am probably missing something, but none of the create functions or examples actually use what they created directly. Its only on a touch or something after the fact that manipulates them. How does one get the game object or TNO that was created as the result of a create call.
Example: I want to create 30 cubes and assign each a random texture all at once.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Finding what you just created
« Reply #1 on: May 19, 2014, 06:00:33 PM »
Create calls are never immediate. They are delayed. The create message is a request that gets sent to the server, and the object will be created some time later. You can't modify the object immediately because the doesn't exist yet.

If you need to pass custom data along with your Create call, create a custom Create call. Check the sticky for more info.

greyhoundgames

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 39
    • View Profile
Re: Finding what you just created
« Reply #2 on: May 19, 2014, 07:46:56 PM »
Thanks for the info. That is what I was looking for. I am assuming it is not safe to hold onto instances of these game object's since they could be destroyed at any time without your knowledge? Do you have a way to reference them by some unique guid? I assume I cannot set the parent in this callback to keep things in "buckets".

For example, I want to maintain a list of cameras of each player that is connected. In my create callback I could store the game object into some list somewhere but that sounds like a bad idea.

Also I commented out the changes mentioned on my thread regarding crashing unity so while im working with this stuff hopefully I will find out if the issue is reproduce able still.

On a side note, are channels the same as games? Taking the sample thats included, I added a new scene to the list of example1-3 that you can pick. Everything works fine in it, but when a client connects I do not get:OnPlayerJoined call which in the comments mentions joined the channel. Is there a different broadcast for a player joined a level?

Edit:I see, I needed OnNetworkPlayerJoin
« Last Edit: May 19, 2014, 09:54:53 PM by greyhoundgames »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Finding what you just created
« Reply #3 on: May 20, 2014, 03:05:31 PM »
You can most certainly reparent them as you see fit. Just don't parent them to other dynamically instantiated objects.

These objects will only be destroyed if you do that via TNManager.Destroy, or switch scenes.