Author Topic: Why does TNManager.Create return void vs GameObject?  (Read 3927 times)

iByte

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Why does TNManager.Create return void vs GameObject?
« on: April 12, 2013, 09:22:39 PM »
Why does TNManager.Create return void vs GameObject? If I wanted a handle to the resultant GameObject I would need to "Find" it?

iByte

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why does TNManager.Create return void vs GameObject?
« Reply #1 on: April 13, 2013, 06:54:12 AM »
Because it's an asynchronous call. It's delayed until it can happen on all connected clients.

Simply put, how would you sync what you are about to do after instantiating the object? With Unity's networking you get a reference back. Great -- now you are using it. Great as well -- except that what you are now doing with this reference only happens on the client you've instantiated the object on, but not on the remaining clients. See the issue?

You don't need to "find" anything. Change your logic so that whatever you are trying to do happens in a script attached to the object you're instantiating. This way it happens on all clients properly.

iByte

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Why does TNManager.Create return void vs GameObject?
« Reply #2 on: April 13, 2013, 11:06:09 AM »
Hi I need to create one object (ball) per player that will be viewable across all player machines and a second object per player (ball camera) that will only interact with a players own version of that first object.

I am unsure how that second object should be getting a reference to the first object?

iByte

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why does TNManager.Create return void vs GameObject?
« Reply #3 on: April 13, 2013, 11:47:03 AM »
Sounds like you should have a script on the first object that will create a local object in its Start() function using simple Object.Instantiate. There is no sense in synchronizing the 2nd object.

iByte

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Why does TNManager.Create return void vs GameObject?
« Reply #4 on: April 15, 2013, 11:53:55 PM »
Hi in my functions below TNManager.players only seems to list additional players added after the first player?


  1. void OnNetworkPlayerJoin (Player p) {
  2.  
  3.         Debug.Log("Player: " + p.name + " joined.");
  4.                
  5.         Debug.Log("OnNetworkPlayerJoin: " + "numPlayers: "  + TNManager.players.size);
  6.  
  7. }
  8.  
  9. void OnNetworkJoinChannel (bool success, string messgae) {
  10.         if (success) {
  11.                 TNManager.playerName = TNManager.player.name + TNManager.player.id;
  12.         }                      
  13. }
  14.        
  15. void OnNetworkPlayerRenamed ( Player p, string previous) {
  16.                
  17.         Debug.Log("New name: " + p.name + " - Old Name: " + previous);
  18.        
  19.         foreach (Player x in TNManager.players) {
  20.                 Debug.Log("PlayerList: " + x.name);
  21.         }
  22. }
  23.  

Output after starting the game in the editor first and then the standalone exe

  1. OnNetworkConnect
  2. New name: Guest1 - Old Name: Guest
  3.  
  4. Player: Guest joined.
  5. OnNetworkPlayerJoin: numPlayers: 1
  6. New name: Guest2 - Old Name: Guest
  7. PlayerList: Guest2
  8.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Why does TNManager.Create return void vs GameObject?
« Reply #5 on: April 16, 2013, 11:41:17 AM »
You don't count. This is a list of other players.