Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by e_Glyde · May 07, 2013 at 09:21 PM · multiplayerfunctionrpccall

RPC call failed

When I click the spawn button in my multiplayer game this error shows up.

  1. RPC call failed because the function '­Client_PlayerAlive' does not exist in the any script attached to'PlayerManager'

  2. UnityEngine.NetworkView:RPC(String, RPCMode, Object[])

  3. MultiplayerManager:Client_SpawnPlayer(NetworkPlayer, Vector3, Quaternion) (at Assets/Scripts/MultiplayerManager.cs:180)

  4. UnityEngine.NetworkView:RPC(String, RPCMode, Object[])

  5. MultiplayerManager:Server_SpawnPlayer(NetworkPlayer) (at Assets/Scripts/MultiplayerManager.cs:168)

  6. MultiplayerManager:SpawnMenu() (at Assets/Scripts/MultiplayerManager.cs:223)

  7. MultiplayerManager:OnGUI() (at Assets/Scripts/MultiplayerManager.cs:155)

MultiplayerManager

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class MultiplayerManager : MonoBehaviour 
 {
     public static MultiplayerManager instance;
     public GUIManager guiManager;
     
     public GameObject PlayerManagerPrefab;
         
     public string PlayerName;
     
     private string MatchName = "";
     private string MatchPassword = "";
     private int MatchMaxUsers = 32;
     
     public List<MPPlayer> PlayerList = new List<MPPlayer>();
     public List<MapSetting> MapList = new List<MapSetting>();
     
     public MapSetting CurrentMap = null;
     public int oldprefix;
     public bool IsMatchStarted = false;
     
     //General Multiplayer Modes
     public bool MatchLoaded;
     public MPPlayer MyPlayer;
     public GameObject[] SpawnPoints;
         
     void Start()
     {
         DontDestroyOnLoad(gameObject);
         instance = this;
         PlayerName = PlayerPrefs.GetString("PlayerName");
         CurrentMap = MapList[0];
     }
     
     void FixedUpdate()
     {
         instance = this;
     }
     
     void Update()
     {
     }
     
     public void StartServer(string servername, string serverpassword, int maxusers)
     {
         MatchName = servername;
         MatchPassword = serverpassword;
         MatchMaxUsers = maxusers;
         Network.InitializeServer(MatchMaxUsers, 2550, false);
         Network.InitializeSecurity();
         MasterServer.RegisterHost("DeathMatch", MatchName, "");
     }
     
     void OnServerInitialized()
     {
         Server_PlayerJoinRequest(PlayerName, Network.player);
     }
     
     void OnConnectedToServer()
     {
         networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, PlayerName, Network.player);
     }
     
     void OnPlayerDisconnected(NetworkPlayer id)
     {
         networkView.RPC("Client_RemovePlayer", RPCMode.All, id);    
     }
     
     void OnPlayerConnected(NetworkPlayer player)
     {
         foreach(MPPlayer pl in PlayerList)
         {
             networkView.RPC("Client_AddPlayerToList", player, pl.PlayerName, pl.PlayerNetwork);
         }
             networkView.RPC("Client_GetMultiplayerMatchSettings", player, CurrentMap.MapName, "", "");
     }
     
     void OnDisconnectedFromServer()
     {
         PlayerList.Clear();
     }
     
     [RPC]
     void Server_PlayerJoinRequest(string playername, NetworkPlayer view)
     {
         networkView.RPC("Client_AddPlayerToList", RPCMode.All, playername, view);
     }
     
     [RPC]
     void Client_AddPlayerToList(string playername, NetworkPlayer view)
     {
         MPPlayer tempplayer = new MPPlayer();
         tempplayer.PlayerName = playername;
         tempplayer.PlayerNetwork = view;
         PlayerList.Add(tempplayer);
         if(Network.player == view)
         {
             MyPlayer = tempplayer;
             GameObject play = Network.Instantiate(PlayerManagerPrefab, Vector3.zero, Quaternion.identity, 5) as GameObject;
         }
     }
     
     [RPC]
     void Client_RemovePlayer(NetworkPlayer view)
     {
         MPPlayer temppl = null;
         foreach(MPPlayer pl in PlayerList)
         {
             if(pl.PlayerNetwork == view)
             {
                 temppl = pl;
             }
         }
         if (temppl != null)
         {
             PlayerList.Remove(temppl);
         }
     }
     
     [RPC]
     void Client_GetMultiplayerMatchSettings(string map, string mode, string others)
     {
         CurrentMap = GetMap(map);
     }
     
     public MapSetting GetMap(string name)
     {
         MapSetting get = null;
         
         foreach(MapSetting st in MapList)
         {
             if(st.MapName == name)
             {
                 get = st;
                 break;
             }
         }
         
         return get;
     }
     
     [RPC]
     void Client_LoadMultiplayerMap(string map, int prefix)
     {
         Network.SetLevelPrefix(prefix);
         Application.LoadLevel(map);
     }
     
     void OnGUI()
     {
         if(!MyPlayer.PlayerIsAlive && IsMatchStarted)
             SpawnMenu();
         
         if(IsMatchStarted && Input.GetKey(KeyCode.Tab))
         {
             guiManager.ScoreBoard();    
         }
     }
     
     [RPC]
     void Server_SpawnPlayer(NetworkPlayer player)
     {
         print("Sever spawn");
         int numberspawn = Random.Range(0, SpawnPoints.Length - 1);
         networkView.RPC("Client_SpawnPlayer", RPCMode.All, player, SpawnPoints[numberspawn].transform.position + new Vector3(0,2,0), SpawnPoints[numberspawn].transform.rotation);
     }
     
     [RPC]
     void Client_SpawnPlayer(NetworkPlayer player, Vector3 position, Quaternion rotation)
     {
         MultiplayerManager.GetMPPlayer(player).PlayerIsAlive = true;
         MultiplayerManager.GetMPPlayer(player).PlayerHealth = 100;
         if(player == MyPlayer.PlayerNetwork)
         {
             MyPlayer.PlayerManager.ControllerTransform.position = position;
             MyPlayer.PlayerManager.ControllerTransform.rotation = rotation;
             MyPlayer.PlayerManager.networkView.RPC("­Client_PlayerAlive", RPCMode.All);
         }
         else
         {
             
         }
     }
     
     void OnLevelWasLoaded()
     {
         if(Application.loadedLevelName == CurrentMap.MapLoadName && Network.isServer)
         {
             MatchLoaded = true;
             SpawnPoints = GameObject.FindGameObjectsWithTag("spawnpoint");
             networkView.RPC("Client_ServerLoaded", RPCMode.AllBuffered, IsMatchStarted);
         }
     }
     
     [RPC]
     void Client_ServerLoaded(bool started)
     {
         MatchLoaded = true;
         IsMatchStarted = started;
     }
     
     public static MPPlayer GetMPPlayer(NetworkPlayer player)
     {
         foreach(MPPlayer play in MultiplayerManager.instance.PlayerList)
         {
             if(play.PlayerNetwork  == player)
             {
                 return play;
             }
         }
         return null;
     }
     
      //Deathmatch
     void SpawnMenu()
     {
        if(GUI.Button(new Rect(5, Screen.height -40, 250, 35),"Spawn"))
        {
          if(Network.isServer)
           Server_SpawnPlayer(Network.player);
          else
           networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player);
        }
     }
     
     [RPC]
     public void Client_UpdatePlayerHealthAndAlive(NetworkPlayer targetplayer, bool IsAlive, int CurrentHealth)
     {
         MPPlayer player = MultiplayerManager.GetMPPlayer(targetplayer);
         player.PlayerIsAlive = IsAlive;
         player.PlayerHealth = CurrentHealth;
     }
 }
 
 [System.Serializable]
 public class MPPlayer
 {
     public string PlayerName = "";
     public NetworkPlayer PlayerNetwork;
     public PlayerManager PlayerManager;
     public int PlayerHealth = 100;
     public bool PlayerIsAlive;
     public int PlayerScore;
     public int PlayerKills;
     public int PlayerDeaths;
 }
 
 [System.Serializable]
 public class MapSetting
 {
     public string MapName;
     public string MapLoadName;
     public Texture MapLoadTexture;
 }

PlayerManager

 using UnityEngine;
 using System.Collections;
 
 public class PlayerManager : MonoBehaviour {
 
     public MPPlayer thisplayer{
         get
         {
             return MultiplayerManager.GetMPPlayer(networkView.owner);
         }
     }
     public PlayerController Controller;
     public Transform ControllerTransform;
     
     public GameObject OutsideView;
     
     public Vector3 CurrentPosition;
     public Quaternion CurrentRotation;
     
     void Start()
     {
         ControllerTransform.gameObject.SetActive(false);
         OutsideView.SetActive(false);
         thisplayer.PlayerManager = this;
         DontDestroyOnLoad(gameObject);
     }
     
     void FixedUpdate()
     {
         if(networkView.isMine)
         {
             CurrentPosition = ControllerTransform.position;
             CurrentRotation = ControllerTransform.rotation;
         }
         else
         {
             OutsideView.transform.position = CurrentPosition + new Vector3(0,-0.1f,0);
             OutsideView.transform.rotation = CurrentRotation;
         }
     }
     
     void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
     {
          if (stream.isWriting) 
         {
           stream.Serialize(ref CurrentPosition);
             stream.Serialize(ref CurrentRotation);
         }
         else 
         {
             stream.Serialize(ref CurrentPosition);
             stream.Serialize(ref CurrentRotation);
         }
     }
     
     public void GetBulletDamage(int damage)
     {
         if(Network.isServer)
             Server_HandleBulletDamage(damage);
         else
         networkView.RPC("Server_HandleBulletDamage", RPCMode.Server, damage);
     }
     
     [RPC]
     public void Server_HandleBulletDamage(int damage)
     {
         thisplayer.PlayerHealth -= damage;
         if(thisplayer.PlayerHealth <= 0) //When dead
         {
             thisplayer.PlayerIsAlive = false;
             thisplayer.PlayerHealth = 0;
             networkView.RPC("Client_PlayerDead", RPCMode.All);
             MultiplayerManager.instance.networkView.RPC("Client_UpdatePlayerHealthAndAlive", RPCMode.Others, thisplayer.PlayerNetwork, false, 0);
         }
         else //When alive getting hit
         {
             MultiplayerManager.instance.networkView.RPC("Client_UpdatePlayerHealthAndAlive", RPCMode.All, thisplayer.PlayerNetwork, thisplayer.PlayerIsAlive, thisplayer.PlayerHealth);
         }
     }
     
     [RPC]
     public void Client_PlayerDead()
     {
         OutsideView.SetActive(false);
         if(networkView.isMine)
             ControllerTransform.gameObject.SetActive(false);
     }
     
     [RPC]
     public void Client_PlayerAlive()
     {
         print("Alive works");
         OutsideView.SetActive(true);
         if(networkView.isMine)
             ControllerTransform.gameObject.SetActive(true);
         else
             OutsideView.SetActive(true);
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by whydoidoit · May 07, 2013 at 09:31 PM

Looks to me like you've managed to get a non-printing character in the name of that call. "Client_PlayerAlive". Delete the string and retype it.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image e_Glyde · May 07, 2013 at 11:50 PM 0
Share

Thank you so much this bug caused my game to stop development, now I can finally continue.

avatar image whydoidoit · May 07, 2013 at 11:52 PM 0
Share

Glad to help! Really tricky one that...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rpc client issue 0 Answers

Temporarily hold Buffered RPC call 1 Answer

Does failed RPC affects anything? 0 Answers

Networking RPC calls never sent to other clients 1 Answer

Networked Piano 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges