Author Topic: HELP! Object reference not set to an instance of an object  (Read 4712 times)

matt.va

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 5
    • View Profile
HELP! Object reference not set to an instance of an object
« on: July 20, 2013, 07:53:25 PM »
hi,

Need some help here....encountered these error, staring at the screen for a few hours and still couldn't resolve.

(1)
Unable to execute function with ID of '1'. Make sure there is a script that can receive this call.
UnityEngine.Debug:LogError(Object, Object)
TNObject:FindAndExecute(UInt32, Byte, Object[]) (at Assets/TNet/Client/TNObject.cs:428)
TNManager:OnForwardedPacket(BinaryReader) (at Assets/TNet/Client/TNManager.cs:761)
TNet.GameClient:ProcessPacket(Buffer, IPEndPoint) (at Assets/TNet/Client/TNGameClient.cs:665)
TNet.GameClient:ProcessPackets() (at Assets/TNet/Client/TNGameClient.cs:609)
TNManager:Update() (at Assets/TNet/Client/TNManager.cs:769)

Script :

   public void LateUpdate(){
      CountScores();   
      // count scores
      if ( Dirty ) {
         TNObject tno = GetComponent<TNObject>();
         tno.Send(1, Target.AllSaved, turn);   

         //syncPlayerList
         int p1 = -99;
         int p2 = -99;
         int p3 = -99;
         int p4 = -99;
         if ( playerList.size > 0 ) p1 = playerList[0];
         if ( playerList.size > 1 ) p2 = playerList[1];
         if ( playerList.size > 2 ) p3 = playerList[2];
         if ( playerList.size > 3 ) p4 = playerList[3];
         
         tno.Send(2, Target.AllSaved, p1, p2, p3, p4);   
         Dirty = false;
      }
   }

   [RFC(1)]
   void syncTurn (int newTurn)
   {
      Debug.Log("[DEBUG] syncTurn!");
      if ( !TNManager.isHosting ) {
         turn = newTurn;
      }
   }

   [RFC(2)]
   void syncPlayerList( int p1, int p2, int p3, int p4 ) {
      Debug.Log("[DEBUG] syncPlayerList!");
      if ( !TNManager.isHosting ) {
         playerList.Clear();
         playerList.Add(p1);
         playerList.Add(p2);
         playerList.Add(p3);
         playerList.Add(p4);
      }
      
   }

(2)
NullReferenceException: Object reference not set to an instance of an object
TNet.List`1[System.Int32].get_Item (Int32 i) (at Assets/TNet/Common/TNList.cs:48)
BallTNET.OnMouseUp () (at Assets/ScriptCS/BallTNET.cs:167)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)

The object prefab is assigned int TNManager, and it was created using TNManager.Create().

Br,
Matt
« Last Edit: July 20, 2013, 08:24:09 PM by matt.va »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HELP! Object reference not set to an instance of an object
« Reply #1 on: July 21, 2013, 04:33:14 AM »
1. Derive your script from TNBehaviour and you won't need to "GetComponent<TNObject>()".
2. You need to have the TNObject script attached to the same game object as this script.

matt.va

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 5
    • View Profile
Re: HELP! Object reference not set to an instance of an object
« Reply #2 on: July 21, 2013, 12:05:57 PM »
1. Derive your script from TNBehaviour and you won't need to "GetComponent<TNObject>()".
2. You need to have the TNObject script attached to the same game object as this script.

1. Yes, inherit from  TNBehaviour.
2. Yes, TNObject attached to prefab, with id 0.

Checked, both are there. Same errors, any other suggestions ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HELP! Object reference not set to an instance of an object
« Reply #3 on: July 22, 2013, 04:20:49 AM »
"ID of 0". This means the ID has not been assigned. You need to instantiate the prefab using TNManager.Create in order for it to be assigned, and the TNObject needs to be on the prefab's root object.