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 /
  • Help Room /
This question was closed Apr 28, 2016 at 08:33 AM by Hardstop for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Hardstop · Apr 28, 2016 at 07:30 AM · instantiateplayernetworkparenting

Unity server/client player attachments parenting

Hey

So i have stumbled upon a problem with attaching items or objects to a player on run time over the server and network, the spawning is fine and parent attaching seems to be fine aswell for own player, other network users dont get the parent synchronization somehow.

Example:

  • Player 1 connects, gets a spawned hat on him, when he moves, it moves along, since its parented to head.

  • Player 2 connects, sees the object at current player 1 position and near head, but when Player 1 moves, the hat is not attached/parented.

I'm using unity's UNET Command attribute to send the object initializiation, instantiation and network server spawning and parent attaching with local positioning. After that, i'm sending a ClientRpc function through to all the clients once, to set the parent for other players aswell, but it seems to be mishandling something or not working correctly.

PS! I know that this code will instantiate and create the hat object for the head parent only for server.

Cmd_AttachItems - Called once the player loads. (Script is attached to player prefab with unityengine.networking use and networkbehaviour set. Here's the blank code from my empty example scene:

 [Command]
     public void Cmd_AttachItems(string prefabname,Vector3 pos,GameObject parent)
     {
         GameObject spawned_object = Instantiate(Resources.Load(prefabname) as GameObject);
         spawned_object.transform.SetParent(parent.transform);
         Debug.Log(spawned_object.transform.parent.transform);
         spawned_object.transform.localPosition = new Vector3(0,0,0);
         NetworkServer.Spawn(spawned_object);
         Rpc_ClientRpcSyncItemOnce(spawned_object);
     }
     [ClientRpc]
     public void Rpc_ClientRpcSyncItemOnce(GameObject obj)
     {
         Debug.Log(obj.transform.parent.transform);
         obj.transform.SetParent(obj.transform.parent.transform);
         obj.transform.localPosition = new Vector3(0, 0, 0);
     }

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

  • Sort: 
avatar image
0

Answer by Hardstop · Apr 28, 2016 at 08:32 AM

I got it fixed!

I made a script that is attached to the attachable item, which has the parent's net id attached to it.

 [SyncVar]
     public NetworkInstanceId parentNetId;

And under the start function of this attachable object i'm attaching the object to the parent with the same net id

 if (parentNetId != null) { 
             Debug.Log("Attached item net id:" + parentNetId);
             GameObject parentObject = ClientScene.FindLocalObject(parentNetId);
             transform.SetParent(parentObject.transform);
         }


The player has net id attached to it aswell and once created, the id is sent and set for the attachable item.

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

Follow this Question

Answers Answers and Comments

75 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

Related Questions

How do I properly deal with Internal_CloneSingle can only be called from the main thread 0 Answers

Simple Host - Client Callback 0 Answers

Spawn Objects in a Server UNet 0 Answers

How can i create only one Player gameobject in Network game? 0 Answers

Why would instantiating a prefab cause my player to move slightly to the right? 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