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 chelog · Jun 25, 2015 at 12:55 PM · networkingmultiplayerplayerobjectchange

Changing player object UNET

Hello, people

I'm making a little game where players can change what object they're cotrolling. Like they start with a ball and they can roll it using WASD, and when they collide with some other ball tagged "PlayerBody", they will have control on that ball and lose it on old one.

Here's what I do (PlayerBodyScript.cs inheriting from NetworkBehaviour):


 private void OnCollisionEnter(Collision col) {
         if (tag == "Player") {
             // ... some code about jump landing
 
             if (col.gameObject.tag == "PlayerBody" && plyLastUpdated + 3f < Time.time){
                 // set new body if collided with PlayerBody
                 col.gameObject.GetComponent<PlayerBodyScript>().color = color;
 
                 if (isLocalPlayer){
                     // local player updates the camera
                     col.gameObject.GetComponent<PlayerBodyScript>().cam = GameObject.Find("Main Camera").transform;
                     GameObject.Find("Main Camera").GetComponent<CameraScript>().UpdateTarget(col.gameObject);
                 }
 
                 if (isServer) NetworkServer.ReplacePlayerForConnection(connectionToClient, col.gameObject, playerControllerId);
 
                 // unsetting player from this object
                 col.gameObject.GetComponent<PlayerBodyScript>().CmdChangeTagTo("Player");
                 CmdChangeTagTo("PlayerBody");
 
                 color = Color.white;
 
                 plyLastUpdated = Time.time;
             }
         }
     }



But every time I touch other PlayerBody I got this error and user takes control over both bodies (I do not want to destroy old one, but just "move" user to the other "body"):

The error

I am wondering what I'm doing wrong? I'm kinda new in UNET and Unity overall.
Thank you for any 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mentality · Jun 26, 2015 at 11:08 AM

As i can see: ReplacePlayerForConnection don't actually "replace" player controled object but adds new object to control.

So you need to use ReplacePlayerForConnection to your old object too.

PS: Could be wrong, i'll check it myself.

Comment
Add comment · Show 1 · 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 chelog · Jun 26, 2015 at 09:20 PM 0
Share

This replaces the player object for a connection with a different player object. The old player object is not destroyed. If a connection already has a player object, this can be used to replace that object with a different player object. This does NOT change the ready state of the connection, so it can safely be used while changin scenes.

This is how it's explained in ScriptingAPI
I think it should replace existing object for given playerControllerId completely as there's no method like NetworkServer.RemovePlayerForConnection( ... )

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

ReplacePlayerForConnection works but... 0 Answers

I have problem with synchronize multiplayer player position... 0 Answers

RPC activate object 0 Answers

Multiplayer| Attaching camera to player (if i am the owner 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