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 GokusGString · Oct 05, 2017 at 12:20 PM · unity 5networkingmultiplayer-networkingspawning

Change player object - UNET

Hi guys I'm trying to change the player's model in my multiplayer game (UNET). But I can't seem to get the new object to actually spawn for the client.

The problem is that I can't spawn the selected object from clients. It works perfectly when the action is performed by the host, but not when a client attempts it. When a client attempts it, I get the following error: "SpawnWithClientAuthority player object is not a player". This is quite confusing as it works perfectly when it's performed by the host.

The code for this particular part is the following:

 private void updateAppearance(GameObject newObject)
 {
 
     Destroy(appearance);
 
     hiderModel.SetActive(false);
 
     int newObjectNum = propNames.IndexOf(newObject.name);
     activePropIndex = newObjectNum;
     Debug.Log(newObjectNum);
 
 
     newObject = (GameObject)Instantiate(props[newObjectNum], playerCam.gameObject.transform);
     newObject.transform.localPosition = new Vector3(0, getObjectHeight(newObjectNum), 0);
 
     NetworkServer.SpawnWithClientAuthority(newObject, gameObject); <--- This part gives the error
 
     appearance = newObject;
     appearance.transform.localPosition = new Vector3(0, appearance.transform.localPosition.y, 0);
 
 
 }

The object to spawn has localAuthority set and has a network transform on it. The object is registered as a spawnable object and it is the instantiated prefab that I am passing to the SpawnWithClientAuthority method. As far as I have read, this should allow the function to work, but unfortunately it doesn't.

The above method was the closest I could get to the actual solution. I tried changing it to a method where I'm using the [command] thingy, but with it I'm not even able to perform it by the host, since for some reason I'm not getting the correct playerid. The code for this method is the following:

 [Command]  
     public void CmdUpdateAppearance(int playerID, GameObject newObject, GameObject playerCam)
     {
         Debug.Log("Change please");  
         GameObject.Find("NetworkManager").GetComponent<Teams>().hiders.CopyTo(hiders);  
         Debug.Log(playerID);   
         GameObject player = hiders.ElementAt(playerID);  
         hiderBehaviour hb = player.GetComponent<hiderBehaviour>();   
         NetworkServer.Destroy(player.GetComponent<hiderBehaviour>().appearance);       
 
         hb.hiderModel.SetActive(false);  
 
         int newObjectNum = hb.propNames.IndexOf(newObject.name);  
         hb.activePropIndex = newObjectNum;  
 
         newObject = (GameObject)Instantiate(props[newObjectNum], playerCam.gameObject.transform);  
         newObject.transform.localPosition = new Vector3(0, hb.getObjectHeight(newObjectNum), 0);  
 
         NetworkServer.SpawnWithClientAuthority(newObject, player);  
 
         hb.appearance = newObject;  
         hb.appearance.transform.localPosition = new Vector3(0, hb.appearance.transform.localPosition.y, 0);  
 
     }


I'm still not sure exactly why I'm not getting the correct playerID, but that method seems to be further away from actually being correct. There are quite a lot of objects which can be spawned through this so I can't have all of them instantiated and simply switching between them as it would most likely be horrific for performance.

Any ideas on how I can actually do this? Or maybe change to first method to work from clients as well?

This is kind of urgent so any help would be appreciated

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 GokusGString · Oct 09, 2017 at 09:24 PM

Got around it by using commands and client rocks and instantiating the object in the clientrpc

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

172 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

Doubt with google play games services ? 0 Answers

[Question] Rock Paper Scissors clone - GameManager in Network game 2 Answers

Multiple NetworkBehaviours with the same SyncVar hook not working 1 Answer

Why are objects only spawning on host but not on remote clients? 3 Answers

UNET Networking: Changing Players texture 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