Author Topic: TNManager.Create doesn't assign unique network ID  (Read 2269 times)

Adriaan

  • Guest
TNManager.Create doesn't assign unique network ID
« on: July 02, 2013, 10:12:13 AM »
Hi Aren,

I've stumbled upon a problem that I hadn't encountered before, and I think you can help me. Previously, I saw that TNManager automatically updates each TNObject's unique network ID when an object is being created through Create(), right? Well, since I've made changes to my code and added TNManager.Create()'s to a while loop, I get errors that Network ID 78 is already in use by "SomeGameObject(Clone)/Cube", while I didn't have this problem before.

Could this be the problem, to Create() two prefabs at the almost same time?

So:
- the prefab is in the manager list
- multiple instances of the prefab are created through: TNManager.Create(prefab, position, rotation);
- the objects causing errors are TNObject on children of the prefab
- The error in Unity says: "Network ID 78 is already in use by "SmallFighter(Clone)/Cube"."
- Network ID 78 is the ID I gave it in the editor, but that should be picked up by the manager, right?

Where should I look for? Should I try to replace the while loop or that cannot be it?

(Possible problem: the prefabs are recurring objects in the game and spawned and die occasionally, but they are part of the bigger object. When they 'die', they actually don't TNManager.Destroy() themselves, but rather the object above it. Maybe the ID isn't removed from the list then, because it's a child?)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.Create doesn't assign unique network ID
« Reply #1 on: July 02, 2013, 10:17:05 AM »
You need to give it ID of 0 if you want it to be dynamic (and save that on the prefab). Also, depending on the version of TNet, nested TNObjects may not be supported in it.

Adriaan

  • Guest
Re: TNManager.Create doesn't assign unique network ID
« Reply #2 on: July 02, 2013, 10:35:47 AM »
Alright, tried to set the ID's to 0 everywhere, but I can clearly see in the editor that the parent prefab does have a unique ID but the child doesn't...

I downloaded the latest version of Tnet an hour ago... Anything else I could be doing wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNManager.Create doesn't assign unique network ID
« Reply #3 on: July 02, 2013, 11:28:03 AM »
Only one TNObject can receive an ID on instantiation -- the root TNObject. Child TNObject simply inherits the parent's ID, but only if it's set to 0. Are you using 1.7.2c? Line 254 of TNObject should read:
  1. if (id == 0) mParent = FindParent(transform.parent);