Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Oakioats · Mar 07, 2017 at 04:22 PM · networkingmultiplayerclasses

[SOLVED]UNET Changing character classes during multiplayer game?

How do I change player prefab with the network manager during a live game? I want the user to be able to choose what class they want to play as like a Rogue, Mage, or Warrior. Then once the player dies they can choose a new class to spawn as.

The only closest examples of this mechanic I can find is people choosing a class in the lobby manager scene, but then once in game they are stuck with the player prefab for the rest of the match. I need to allow the player to dynamically change their player prefab during the game between response

How can I change the initial player prefab in the network manager during run time and sync it to the server for the other clients to see.

These folks are close :: but not quite there. Has anyone worked through this or have an idea. I've been searching up other documents and forums but nothing is hitting the nail on the head. Appreciate any and all help.

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

2 Replies

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

Answer by TestifyNow · Mar 09, 2017 at 04:53 PM

send [Comman]d, which in turn does [ClientRPC], in this RPC destroy player prefab, create a new one, and give the same player local authority over 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 Oakioats · Mar 20, 2017 at 06:16 PM 0
Share

Thank you, I was noticing some issues and looking over the code when RPC was co$$anonymous$$g up. Thank you for the correction. I will see how it goes.

avatar image Oakioats · Mar 20, 2017 at 06:45 PM 0
Share

Seems to fix a bit. I threw in this, I have a command function calling this RPC function. It gets the player connection, original prefab info, and set the colliders off. After it instantiates a new object, assigns old prefab info to new object, set prefab switched to true(no worries about this), destroys old object, and finally replaces prefab connect. There is one issue...

 [ClientRpc]
     void RpcSpawnPlayer()
     {
         //GameObject instance = Instantiate (testObj, testObj.transform.position,               this.gameObject.transform.rotation);
         //NetworkServer.SpawnWithClientAuthority (instance, connectionToClient);
         var conn = GetComponent<NetworkIdentity> ().connectionToClient;
         SetupPlayer playerStates = GetComponent<SetupPlayer> ();
         gameObject.GetComponent<SetupPlayer> ().SetActiveState (false);
         var newPlayer = Instantiate<GameObject> (testObj,playerStates.originalPos,transform.rotation);
         //send player states to next prefab player
         newPlayer.GetComponent<SetupPlayer> ().playerName = playerStates.playerName;
         newPlayer.GetComponent<SetupPlayer> ().score = playerStates.score;
         newPlayer.GetComponent<SetupPlayer> ().$$anonymous$$m = playerStates.$$anonymous$$m;
         newPlayer.GetComponent<SetupPlayer> ().originalPos = playerStates.originalPos;
         //makes sure starting prefab states only reset once
         newPlayer.GetComponent<SetupPlayer> ().prefabSwitched = true;
         Destroy (GetComponent<NetworkIdentity> ().gameObject);
         NetworkServer.ReplacePlayerForConnection (conn,newPlayer,0);
     }

The issue was originally happening on both client and host, but now it is just the host thanks to your lead. The host once changed seems to spawn in another position for a split second before beginning at the starting point(start spawn position). Is there any reason this code would have any issues?

avatar image
0

Answer by Oakioats · Mar 12, 2017 at 06:07 PM

SOLVED: So after some jumping around managed to find a simple snippet of code to swap player prefabs.

Unity doc for replacing/swapping player prefab

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Networking pattern for team-based play 1 Answer

Networking Camera not attaching to instantiated object 2 Answers

Animation over network using rpcs 0 Answers

Frames Per Second Cost from Multiplayer? 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