Author Topic: Issue with network object id  (Read 3349 times)

DoomSamurai

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Issue with network object id
« on: February 13, 2014, 03:06:26 PM »
Hi,

I have an issue with a TNO I'm creating two copies of (one copy instantiated from two clients) with
  1. TNManager.Create("CASTLE", true);

Both objects appears correctly in my scene but I get two errors:

Quote
Network ID 16777213 is already in use by "Player:1". Please make sure that the network IDs are unique.

followed by :

Quote
Network ID 16777212 is already in use by "Player:2". Please make sure that the network IDs are unique.

I checked and my TNObject script on my CASTLE prefab has it's id set to zero. It's in my resources folder. It has no child objects with TNOs or something like that. In the scene, my CASTLE objects now have ids set to 1 and 2.

One particularity is that I'm creating the castle in the Start function of a script attached to a game controller network object. Is it possible that this is creating the issue?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issue with network object id
« Reply #1 on: February 14, 2014, 06:19:00 AM »
TNManager.Create should work regardless of where you're calling it from, but the owner of the created object is going to be whoever calls the Create function. Make sure that only one player is doing that.

Also... you mentioned that TNO IDs for your castle objects are 1 and 2? Those are static IDs, implying an object that was not created dynamically. 16,777,212 is a dynamic ID, assigned by the TNManager.Create call's server response. Why is it complaining about a dynamic ID, when you have a static ID?

DoomSamurai

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Issue with network object id
« Reply #2 on: February 14, 2014, 10:41:54 AM »
That's just it, I don't have a static ID. This is my prefab in the Resources folder. Its got a Cube object and empty gameobjects I use for my pathfinding graph as children. The parent object just have a box collider, a TNO script and a CastleManager script I disabled, thinking it could be the source of the issue but apparently it isn't.  The TestTNO object you can see in the Resources folder is another object with just a box collider, a TNO script and a Cube child object. It does the same thing when I try to create it in the Start function of my GameController, namely the id issue.




I also tried creating both object with an autocreate gameobject. The script is as follows :

  1. public GameObject prefab;
  2.  
  3.         /// <summary>
  4.         /// Creates a network object. MustBeHost controls if the user must be the host to create the object.
  5.         /// </summary>
  6.  
  7.         public bool persistent = false;
  8.     public bool mustBeHost = false;
  9.  
  10.         void Start ()
  11.         {
  12.             if (!mustBeHost || TNManager.isHosting)     TNManager.Create(prefab, transform.position, transform.rotation, persistent);
  13.                 Destroy(gameObject);
  14.         }

It does the same thing when I try to auto-create either the Castle or the TestTNO. I use the same auto-create script to create the GameController itself and it works perfectly fine.

Is it possible that somehow there is an issue with the sequence of the network objects creation?

DoomSamurai

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Issue with network object id
« Reply #3 on: February 14, 2014, 09:08:45 PM »
I did some additionnal tests and apparently only the first two TNOs I instantiate are problematic. All the following TNOs I auto-create have an ID assigned to them. Although their IDs are decrementing.

Here's a few things I noticed. I have a game lobby scene where I instantiate a lobby controller TNO via the auto-create script and two player managers TNOs when players join the channel. The game lobby scene is the scene that's loaded when a player joins a channel but the player managers are created in the OnNetworkJoinChannel callback. In the lobby my game controller gets an Id of 16777214 and my local player manager gets an id of 16777213. When the second player joins the channel, it's id is 16777212. When players confirm they are ready to start the game, I use
  1. TNManager.LoadLevel("Game");
to load the game scene. My auto-create script create the GameController when the scene is loaded and the GameController gets an id of 16777214 which is okay since my lobby controller was destroyed in the previous scene. Then the next two TNOs I instantiate gets the ids 1 and 2 because the ids 16777213 and 16777212 are already in use by my player managers, which are flagged as DontDestroyOnLoad. Then all the following TNOs have ids that go from 16777211 and down.

I hope this help find the problem, I'll do some more tests in the meantime.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issue with network object id
« Reply #4 on: February 15, 2014, 02:32:17 AM »
Oh in there lies the problem. You should never mark dynamically created objects as DontDestroyOnLoad. TNet assumes that all dynamic objects get destroyed when you switch scenes.

If you want to keep something from one scene to another, then give it a static TNObject ID, and make it be a part of the scene. Don't instantiate it dynamically.

DoomSamurai

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Issue with network object id
« Reply #5 on: February 15, 2014, 11:15:38 AM »
Got it, thanks Aren!