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
0
Question by PixelFireXY · Dec 13, 2012 at 10:41 AM · errorplayerspawnrpcspecific

Problem with spawn player with RPC calls(c #)

Hi, im working on adventure game in multiplayer, and i made the code for spawn, but im stuck in one point, im show you the situation:

this piece of code is attached of a gameObject(DontDestroyOnLoad already placed)

 bool _isSpawned = false;
 public GameObject player;
 public List<MPPlayer> playerList = new List<MPPlayer>();

 void OnLevelWasLoaded(int level)
     {
         if (level == 1)
         {
             if (!_isSpawned)
             {
                 spawnPoint = GameObject.FindGameObjectsWithTag("spawnpoint");
 
                 networkView.RPC("Server_AssignSpawnPoint", RPCMode.All, Network.player);
 
                 _isSpawned = true;
 
             }
         }
 
 [RPC]
     public void Server_AssignSpawnPoint(NetworkPlayer playerNet)
     {
         if (Network.isServer)
         {
             for (int i = 0; i < playerList.Count; i++)
             {
                 if (playerList[i].plNetwork == playerNet)
                 {
                     networkView.RPC("Client_SpawnPlayer", playerNet, i);
                     break;
                 }
             }
         }
     }
 
     [RPC]
     public void Client_SpawnPlayer(int index)
     {
         GameObject playerNet = Network.Instantiate(player, spawnPoint[index].transform.position, spawnPoint[index].transform.rotation, 0) as GameObject; 
     }

 public class MPPlayer
 {
     public string plName = "";
     public NetworkPlayer plNetwork;
 }


This is level0 scene and when i load new level(level1) this code is called at start, in this code above there is this piece of code:

 for (int i = 0; i < playerList.Count; i++)
 {
     if (playerList[i].plNetwork == playerNet)
     {
         networkView.RPC("Client_SpawnPlayer", playerNet, i);
         break;
     }
 }

i want that the client(or server) in list call method and spawn own player character, i have specific that who must call the function is Network.player(playerNet), but when i try to spawn the console send me this message:

Can't send RPC function because the target is not connected to the server. UnityEngine.NetworkView:RPC(String, NetworkPlayer, Object[]) ConnectionScriptManager:Server_AssignSpawnPoint(NetworkPlayer) (at Assets/scripts/Network Scripts/ConnectionScriptManager.cs:270) UnityEngine.NetworkView:RPC(String, RPCMode, Object[]) ConnectionScriptManager:OnLevelWasLoaded(Int32) (at Assets/scripts/Network Scripts/ConnectionScriptManager.cs:252)

i try change playerNet with RPCMode.All and obviusly work, but for example if 2 players play, 4 character controller is spawned(2(number of players) per 2(total number of methods))

anyone can help me? :S thanks in advance :)

P.S. playerList have already list of player connected, the problem is only for call method from specific client(or server)

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
0
Best Answer

Answer by PixelFireXY · Dec 13, 2012 at 11:56 AM

Find! :D i don't know why dont work but if i change this piece:

 [RPC]
     public void Server_AssignSpawnPoint(NetworkPlayer playerNet)
     {
         if (Network.isServer)
         {
             for (int i = 0; i < playerList.Count; i++)
             {
                 if (playerList[i].plNetwork == playerNet)
                 {
                     networkView.RPC("Client_SpawnPlayer", playerNet, i);
                     break;
                 }
             }
         }
     }
 
     [RPC]
     public void Client_SpawnPlayer(int index)
     {
         GameObject playerNet = Network.Instantiate(player, spawnPoint[index].transform.position, spawnPoint[index].transform.rotation, 0) as GameObject; 
     }

with this:

[RPC] public void Server_AssignSpawnPoint(NetworkPlayer playerNet) { if (Network.isServer) { for (int i = 0; i < playerList.Count; i++) { if (playerList[i].plNetwork == playerNet) { print(playerNet); networkView.RPC("Client_SpawnPlayer", RPCMode.All, i, playerNet); break; } } } }

 [RPC]
 public void Client_SpawnPlayer(int index, NetworkPlayer plNet)
 {
     if (Network.player == plNet)
     {
         GameObject playerNet = Network.Instantiate(player, spawnPoint[index].transform.position, spawnPoint[index].transform.rotation, 0) as GameObject;
     }
 }

works perfectly, anyway if anyone know why i receve error with previous code please answer me. Thanks anyway at all :D

Comment
Add comment · 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

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

9 People are following this question.

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

Related Questions

How do I create an Initial Spawn Point? 2 Answers

RPC Call Error/Failed 1 Answer

Network initializing player 1 Answer

Add spawn to script [Multiplayer] 0 Answers

move particle direction with player 1 Answer


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