Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

[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:
    51
    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?
     
unityunity