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 /
  • Help Room /
avatar image
0
Question by pIPLING · Jan 19, 2021 at 01:33 AM · multiplayer-networkingmirror

Snapping objects to skeleton in multiplayer game and synching them.

So currently I have a player prefab which includes animations and rigs. Attached to this player at the root node are my networkIdentity, networkTransforms, networkAnimator and then two custom scripts. One being a playerController which amongst many things checks to see if the player hits the "E" key. This then calls a function I have in my second script attached to the root which is an inventory manager, this handles what the current item is and swaps to the next item in the inventory. The swap process takes the current item and calls its stow function which changes the parent and snaps it to a transform. Then it calls equip on the next item which does the same thing. In my case, its snapping in between the spine and the right hand in my skeleton rig. All works fine on single player. When I run it on my networked scenes, the transform change goes through but changing between parents does not work. The item itself is also a prefab and stored in the orignal player prefab on it's spine. Again in the root of the player, I included the networkChildTransform and referenced to the object on the spine. Thanks again in advance

Player controller attached at root:

 public class PlayerController : NetworkBehaviour
 {
 
     InventoryManager inventory;
 
     // Update is called once per frame
     void Update()
     {
         if (!hasAuthority) { return; }
 
         if (Input.GetButtonDown("Swap"))
         {
             inventory.SwapItem();
         }
     }
 }
 

Inventory manager attached at root:

 public class InventoryManager : NetworkBehaviour
 {
 
     public List<GameObject> inventoryLocations;
 
     public List<GameObject> inventory;
     public GameObject currentItem;
 
     int currentIndex = 0;
 
     Animator anim;
 
     // Start is called before the first frame update
     void Start()
     {
         anim = GetComponent<Animator>();
         currentItem = inventory[currentIndex];
         anim.SetInteger("equipID", currentItem.GetComponent<ItemController>().equipAnim);
     }
 
     [ClientRpc] 
     void RpcStow()
     {
         Debug.Log("clientside");
         currentItem.GetComponent<ItemController>().SnapToStow(inventoryLocations[currentItem.GetComponent<ItemController>().stowLocation]);
     }
 
     [ClientRpc]
     void RpcEquip()
     {
         currentItem.GetComponent<ItemController>().SnapToEquip(inventoryLocations[currentItem.GetComponent<ItemController>().equipLocation]);
     }
 
     [Command]
     void CmdStow()
     {
         RpcStow();
     }
 
     [Command]
     void CmdEquip()
     {
         RpcEquip();
     }
 
 
     public void SwapItem()
     {
         if (inventory.Count <= 0)
         {
             return;
         }
 
         currentIndex++;
         if (currentIndex >= inventory.Count)
         {
             currentIndex = 0;
         }
 
         currentItem.GetComponent<ItemController>().SnapToStow(inventoryLocations[currentItem.GetComponent<ItemController>().stowLocation]);
         CmdStow();
         currentItem = inventory[currentIndex];
         anim.SetInteger("equipID", currentItem.GetComponent<ItemController>().equipAnim);
         currentItem.GetComponent<ItemController>().SnapToEquip(inventoryLocations[currentItem.GetComponent<ItemController>().equipLocation]);
         CmdEquip();
 
     }
 
 }
 

The Item controllers code to snap to locations:

 public class ItemController : MonoBehaviour
 {
     // Start is called before the first frame update
     public int equipAnim;
     public int useAnim;
     public int equipLocation;
     public Vector3 equipPosition;
     public Vector3 equipRotation;
     public Vector3 equipScale;
 
     public int stowLocation;
     public Vector3 stowPosition;
     public Vector3 stowRotation;
     public Vector3 stowScale;
 
 
     public void SnapToEquip(GameObject parent)
     {
 
         transform.SetParent(parent.transform);
         transform.localPosition = equipPosition;
         transform.localRotation = Quaternion.Euler(equipRotation);
         transform.localScale = equipScale;
     }
 
     public void SnapToStow(GameObject parent)
     {
         transform.SetParent(parent.transform);
         transform.localPosition = stowPosition;
         transform.localRotation = Quaternion.Euler(stowRotation);
         transform.localScale = stowScale;
     }
 }
 

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 pIPLING · Jan 19, 2021 at 04:11 AM

For anyone who stumbles on this and is looking for a solution I ended up solving the problem. I deleted the Rpc and cmd versions of the snap functions. i then made a command function as a wrapper to an rpc version of swapItem(). This ended up syncing both on clients and host.

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

159 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

Related Questions

is mirror unity support local wifi host on android? 1 Answer

Unity Mirror Problem Client Recv: failed to connect to ip=localhost port=7777 reason=System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'localhost' 1 Answer

How to make multiplayer with multiple local cameras? 1 Answer

My Android Client Disconnects after I start Match. 0 Answers

Problem: Mirror/UNET - No authority on object even when using Command & ClientRpc 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