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 vinhui · Apr 01, 2012 at 04:48 PM · networkspawnrpcinitializeco-op

Network initializing player

Hello,

I'm trying to get co-op working with unity but i got a little problem while spawning new players.

With the first script i can't get the new player see the old player, i understand why it's not doing it. But when i do it the second way, I get every time someone joins and spawns, the olders also get a new character controller.

there is the first way (that is obvious for me why it doesn't work):

     void Start()
     {
         Debug.Log("Spawning the player locally");
         Spawnplayer();
     }
     
     void Spawnplayer()
     {
         Debug.Log("Spawing another player");
         Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 0);
     }

The other way:

 void Start()
     {
         Debug.Log("Spawning the player locally");
         //Spawnplayer();
         networkView.RPC("Spawnplayer", RPCMode.AllBuffered);
     }
     
     [RPC]
     void Spawnplayer()
     {
         Debug.Log("Spawing another player");
         Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 0);
         //Instantiate(PlayerPrefab, transform.position, transform.rotation);
     }
Comment
Add comment · Show 1
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 vinhui · Apr 02, 2012 at 11:53 AM 0
Share

I'm going on another direction, so i got the following:

 void Start()
 {
     Debug.Log("Spawning the player locally");
     networkView.RPC("PlayerLoadedLevel", RPC$$anonymous$$ode.AllBuffered, Network.player);
     //Spawnplayer();
     //networkView.RPC("Spawnplayer", RPC$$anonymous$$ode.AllBuffered);
 }
 
 [RPC]
 void Spawnplayer(NetworkPlayer player, Transform[] playerTrans, NetworkPlayer[] players)
 {
     if(player == Network.player)
     {
         Debug.Log("Spawing another player");
         GameObject playerObject = Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 0) as GameObject;
         playerObject.name = "Player"+player.ToString();
         
         for(int i=0; i<players.Length; i++)
         {
             GameObject pl = Instantiate(PlayerPrefab, playerTrans[i].transform.position, playerTrans[i].transform.rotation) as GameObject;
             pl.name = "Player"+players[i].ToString();
         }
         //Instantiate(PlayerPrefab, transform.position, transform.rotation);
     }
 }
 
 [RPC]
 void PlayerLoadedLevel(NetworkPlayer LoadedPlayer)
 {
     if(Network.isServer)
     {
         Transform[] playerTrans = GameObject.FindGameObjectsWithTag("Player");
         networkView.RPC("Spawnplayer", RPC$$anonymous$$ode.AllBuffered, LoadedPlayer, playerTrans, Network.connections);
     }
 }

But when i run this, i get the following error: Failed to invoke arriving RPC method because the parameters didn't match the function declaration. 'Spawnplayer' of 'NetworkSpawn'.

But i've no idea what i'm doing wrong.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Branx · Apr 02, 2012 at 01:32 PM

Script Reference says: Valid RPC parameters are int, float, string, NetworkPlayer, NetworkViewID, Vector3 and Quaternion. Having a Transform[] as parameter type is still legal because you could call the function the usual way. However the RPC call can't handle it - correctly logging an Error that directs you to the function declaration of SpawnPlayer.

Comment
Add comment · Show 6 · 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 vinhui · Apr 02, 2012 at 02:55 PM 0
Share

hmmm, well i took a look at the m2h networking tutorial. I saw nothing really specially about the way how they did it. so how can spawn the player and let him also see the older, already spawned, players?

avatar image Branx · Apr 02, 2012 at 03:46 PM 0
Share

I don't know that Tutorial, but the most simple way is to call Network.Instantiate() and let Unity do the rest. Don't place Network.Instantiate() in a RPC method. Call it directly on the client, e.g. in Start();

avatar image vinhui · Apr 02, 2012 at 04:50 PM 0
Share

but when i do that, the new player cant see the earlier spawned players. I've added the networkview on the player prefab and its observing the player Transform (https://lh3.googleusercontent.com/-2V2tZ_$$anonymous$$yVC0/T3nYw_nOGkI/AAAAAAAAAI0/r7fw3BZhk$$anonymous$$o/s720/$$anonymous$$nipsel.PNG)

avatar image vinhui · Apr 03, 2012 at 02:35 PM 0
Share

now i read the documentation about the network.instantiate again, i see it's bufferd. The only problem is that the new instantiated player cant see the already instantiated players

avatar image Branx · Apr 03, 2012 at 03:28 PM 0
Share

Could it be your buffered calls somehew get lost? Did you check "Run in background" ? Does the same problem occur with normal buffered RPC calls. And are you sure your objects are not on top of each other because a Walker script or smth is acticated on both? Sorry if these are too obvious questions, but this looks like only some $$anonymous$$or detail is missing somewhere. Can you update the posted scripts to your current?

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

RPC function to update clients varialbe 0 Answers

Mutliplayer SetActive(true) 0 Answers

Network - Killing Player, Then Respawn - Issue with RPC 1 Answer

Disconnect a player from a network 1 Answer

Network.Destroy(), Couldn't perform remo 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