Do you find the error ?

Hi
I have an script with following error :

RPC call failed because the function ‘removeUsernameFromAll’ does not exist in the any script attached to’Main Camera’
UnityEngine.NetworkView:RPC(String, RPCMode, Object[ ])
Multi:OnApplicationQuit() (at Assets/Skripts/Multi.js:39)

This is the script:

var username : String;
var imTheOwner : boolean;
var serverConnections : int;
var playersConnected : String;



function Start(){




    if(username == "admin01") {
 
         imTheOwner = true;
        
  }else{
             
           imTheOwner = false;
                 
}      
}

function Update() {
       serverConnections = Network.connections.Length;
}

@RPC
function sendUsernameToAll(usrName : String){
       playersConnected += "\n" + usrName;
}

@RPC
function sendUsernameFromAll(usrName : String){
       playersConnected = playersConnected.Replace("\n" + usrName, "");
}

function OnApplicationQuit(){
networkView.RPC("removeUsernameFromAll", RPCMode.AllBuffered, username);
}

function OnGUI () {
GUILayout.BeginVertical(GUI.skin.box);
GUILayout.Label("du trits bei als " + username);
if(imTheOwner)
  GUILayout.Label("Server Inhaber");
if(GUILayout.Button("Logout")){
    username = "";
    GetComponent(Hauptmenue).enabled = true;
    GetComponent(Hauptmenue).username = "";
    GetComponent(Hauptmenue).enableUsrNameSelector = false;
    enabled = false;
}
if(imTheOwner){
     if(!Network.isServer){
    
       if(GUILayout.Button("Server starten")){
       startMainServer();
       }
       }
      
     if(Network.isServer){
      if(GUILayout.Button("Stop Server")){
         Network.Disconnect();}
    
     GUILayout.Label("verbundene Spieler: " + serverConnections);
    
    
     }
      
      
       }
if(!imTheOwner){
   if(!Network.isClient){
       if(GUILayout.Button("Server beitreten")){
                   
           Network.Connect("localhost", 25001);
      
       }
      
       }
       
        if(Network.isClient){
         GUILayout.Label("mit server verbunden");
           if(GUILayout.Button("verbindung trennen")){
           networkView.RPC("removeUsernameToAll", RPCMode.AllBuffered, username);
           Network.Disconnect();}
       
       
       
        }
       
  }       
  
         
if(Network.isServer || Network.isClient){                
                              
if(!imTheOwner || imTheOwner){

GUILayout.BeginVertical(GUI.skin.box);
    GUILayout.Label("Players connected");
     GUILayout.Label(playersConnected);
  GUILayout.EndVertical();
}
}
GUILayout.EndVertical();
}
function OnConnectedToServer(){
       networkView.RPC("sendUsernameToAll", RPCMode.AllBuffered, username);
     
}
function OnServerInitialized(){
networkView.RPC("sendUsernameToAll", RPCMode.AllBuffered, username);
}
function startMainServer(){
     Network.InitializeServer(32, 25001, !Network.HavePublicAddress());
     Debug.Log("Server startet");
}

Do you can see the error?

the error is telling you everything you need to know… the function you are trying to use doesn’t exist. You don’t have “removeUsernameFromAll()” in that script.

Errors tell you which line is causing it… in this case line 39.

1 Like

Exactly that.

It’s actually telling you that you don’t have a matching method named removeUsernameFromAll marked as an RPC on any script that is attached to Main Camera. It doesn’t necessarily need to be in the script that was included in the opening post.

Note: the error will occur if there is a parameter mismatch also.

yep. that’s exactly what it says. It should be noted that reading the debugger is pretty essential and @beno531 should do some googling on the topic :slight_smile:

true… small assumption on my part that the op only has this script on the object, but given the “send” functions and the rest of the code I think the op has just missed creating the “remove” functions in here somewhere :slight_smile:

Looking at his code I believe you are probably right in this instance :slight_smile: