Author Topic: isMine always false  (Read 519 times)

LuffyGray

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
isMine always false
« on: April 03, 2017, 02:34:23 PM »
isMine() is returning false even if the instantation call was made on the client querying the ownership.

Instantiation code:
  1.         public static void OnClientConnected(bool _success, string _message) {
  2.  
  3.                 if (_success) {
  4.  
  5.                         TNManager.Instantiate (NetworkManager.instance.channelID, "SpawnPlayerRig", "Cube", true,
  6.                                 Vector3.zero, Quaternion.identity);
  7.                        
  8.                 } else {
  9.  
  10.                         Debug.Log ("Failed connection");
  11.  
  12.                 }
  13.  
  14.         }

RCC Call:
  1.         [RCC]
  2.         public static GameObject SpawnPlayerRig (GameObject _prefab, Vector3 _position, Quaternion _rotation) {
  3.  
  4.                 // Instantiate the prefab
  5.                 GameObject _gameObject = _prefab.Instantiate();
  6.  
  7.                 // Set the position and rotation based on the passed values
  8.                 Transform _transform = _gameObject.transform;
  9.                 _transform.position = _position;
  10.                 _transform.rotation = _rotation;
  11.  
  12.                 //This is always false
  13.                 if (_gameObject.GetComponent<TNObject> ().isMine) {
  14.  
  15.                         ClientManager.localPlayer = _gameObject;
  16.                         ClientManager.localNetRig = _gameObject.GetComponent<NetworkRig> ();
  17.  
  18.                 }
  19.  
  20.                 return _gameObject;
  21.  
  22.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: isMine always false
« Reply #1 on: April 04, 2017, 05:08:21 AM »
TNObject hasn't been instantiated at this point. You are the one that's creating the object in your prefab.Instantiate() call. TNObject doesn't get added/set until after the RCC exits. This is why you're returning the game object reference after all.

If you need to do something that checks tno.isMine, do it in the script's Start() function attached to that instantiated object, or pass the instantiating player's ID alongside other arguments to your RCC call.