Search Unity

[TargetRPC] is causing a NullReferenceException... HELP!

Discussion in 'Multiplayer' started by Di_o, Jun 26, 2016.

  1. Di_o

    Di_o

    Joined:
    May 10, 2016
    Posts:
    62
    So I updated to the 5.4 beta. I want to test the new [TargetRPC] with a simple "Hello world!" script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Networking;
    4.  
    5. public class RampUp : NetworkBehaviour {
    6.  
    7.     void OnTriggerEnter(Collider target){
    8.         if (target.tag == "Hand_NoTeam" || target.tag == "Hand_Green" || target.tag == "Hand_Orange" || target.tag == "Hand_Blue") {          
    9.             CmdRampUp();      
    10.         }
    11.     }
    12.  
    13.     [TargetRpc]
    14.     public void TargetRampUp(NetworkConnection target){
    15.         Debug.Log ("Cheeseburger!");
    16.     }
    17.  
    18.     [Command]
    19.     void CmdRampUp (){
    20.         TargetRampUp (connectionToClient);
    21.     }
    22. }
    The result:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.Networking.NetworkBehaviour.SendTargetRPCInternal (UnityEngine.Networking.NetworkConnection conn, UnityEngine.Networking.NetworkWriter writer, Int32 channelId, System.String rpcName) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkBehaviour.cs:122)
    RampUp.CallTargetRampUp (UnityEngine.Networking.NetworkConnection target)
    RampUp.CmdRampUp () (at Assets/Scripts/Vibration/RampUp.cs:20)
    RampUp.CallCmdRampUp ()
    RampUp.OnTriggerEnter (UnityEngine.Collider target) (at Assets/Scripts/Vibration/RampUp.cs:9)


    I'm really new to all the netcode stuff, can somebody explain that NullRefeferenceException to me?