Author Topic: Assigning TNObject IDs Via Code  (Read 2527 times)

Acheron

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Assigning TNObject IDs Via Code
« on: October 09, 2013, 07:53:10 PM »
Hi there,
I'm developing a game in which players outfit vehicles with guns and use them in arena combat. I spawn the vehicle using TNManager.CreateEx(), which assigns it an ID, then load in weapons into slots according to how the player placed them. Each moving part has a TNObject set to 0, and uses the core vehicle as its TNObject.mParent.
1) It does not seem possible to assign TNObject id's manually. Doing this only seemed to change the TNObject.mParent ID.
2) After the vehicle and weapons are generated on client and host, the client throws an exception similar to the following, related to updating a turret's rotation: "Unable to execute function with ID of '23'. Make sure there is a script that can receive this call." This happens often, but not all the time, and always just after the debug log that suggests that the vehicle components have all been created client-side.
3) When the weapon components are all accounted for and there is no error, they all share the same rotation and fire at the same time. This is not my intent, they should operate independently of each other. I suppose they are all getting the packet since they are instances of the same prefab, and that TNet is somehow broadcasting the packet to all nested TNObjects.
I want to know: how can I manually assign and register unique IDs at runtime? This model that groups nested TNObjects and only utilizes the parent is slowing my development progress down. All guns of the same type are linked in a buggy way, and those execution exceptions are seemingly related as well.
TNet is a great product, such an improvement over Unity's native support. I hope that I can resolve this problem soon. Thank you in advance for your help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Assigning TNObject IDs Via Code
« Reply #1 on: October 10, 2013, 07:54:34 AM »
You can't nest TNObjects. Child TNObjects always inherit the ID from the parent. This is done this way because when an object is deleted on the server by its ID, only that object should be deleted. The server doesn't know anything about a hierarchy. It's all on the client side. You need to design your sync class with this in mind and only use one TNObject per instance.

You should also never attempt to change TNObject IDs manually at run-time. Do it for static objects, but never for instantiated objects. Object ID is something that the server specifies for you.