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 KaidaStudios · Sep 10, 2017 at 07:26 PM · networkingunity5network.instantiate

UNET Showing Equipments (Host works/Client doesnt)

alt text

As you can see above, the host correctly displays this information, the client works but does not display the information to the server. I am so confused now I feel I have tried everything. Here is my code please any help is appreciated!

This is attached on Player:

   [SyncVar(hook = "Rpcchangechest")]
     public int echest;
 
  [ClientRpc]
     public void Rpcchangechest(int num) {
         echest = num;
         if (body.male) {
             if (ChestName == ChestName) {
                 Destroy (ChestInst);
             }
             body.Mesh_male_torso.active = false;
             body.Mesh_male_arms.active = true;
             ChestName = Chest [num].name;
             GameObject NewChest = (GameObject)Instantiate (Resources.Load ("Armor/" + ChestName));
             ChestInst = NewChest;
             Destroy (NewChest);
             AddChest ();
             Cmdloadarmor();
         }
 
     }

This is from my UI Script.

  if (itemInfo.EquipType == UIEquipmentType.Chest && !equipped)
                 {
                     //for calling on client
                     transform.root.SendMessage("Rpcchangechest", itemInfo.ID);
 //Supposed to sync?
                     Player.GetComponent<ChangeArmor>().echest = itemInfo.ID;
 }
1.png (209.1 kB)
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 KaidaStudios · Sep 11, 2017 at 06:13 AM

After a very long two days I figured out my first problem that UNET has attacked me with. I will show my solution for anyone else needing help.

From my UI script that was attached in my Player object a command was sent to use this function(Which will find out if the player is the host, or not the host):

     public void updatechest(int newid)
     {
         if (!Network.isServer)
         {
             Cmdchangechest(newid);
         } else
         {
             changechest(newid);
         }
          
     }

Next I have my armor script attached to my Player, with a VarSync variable that calls the hook whenever the eChest variable is changed (We want to only change it with the server, using [Command])

   [SyncVar(hook = "changechest")]
     public int echest;

Then I had the server use this command, I figured any other change of your variable can cause errors, so this is the only time in my whole piece of code I change eChest:

    [Command]
      void Cmdchangechest(int num)
     {
         echest = num;
     }


So sure enough, everything started working correctly. Having [ClientRPC] on the hook function will make things complicated and atleast for me messed it all up. Im guessing perfection is a huge play here within UNET and this has been so dang confusing.. But success!

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

Answer by HammerCar · Sep 10, 2017 at 07:49 PM

ClientRpc and SyncVar are only synced if they are called from the server. You need to add a command method which is executed on the server.

Add this to the player script

 [command]
 public void Cmdchangechest (int num) 
 {
     echest = num
 }

Then do this in the UI script

 if (itemInfo.EquipType == UIEquipmentType.Chest && !equipped)
 {
     //for calling on client
     Player.GetComponent<ChangeArmor>().Cmdchangechest = itemInfo.ID;
 }
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 KaidaStudios · Sep 11, 2017 at 02:25 AM 0
Share

I've been attempting to work around this method and it still only works as Host.. I don't understand :{ Very confused.. Heres my new updated code.

       [SyncVar(hook = "changechest")]
         public int echest;
     
         [Command]
         public void Cmdchangechest(int num)
         {
                 echest = num;
     
         }
 
     public void changechest(int num) {
         echest = num;
 
         if (body.male) {
             if (ChestName == ChestName) {
                 Destroy (ChestInst);
             }
             body.$$anonymous$$esh_male_torso.active = false;
             body.$$anonymous$$esh_male_arms.active = true;
             ChestName = Chest [num].name;
             GameObject NewChest = (GameObject)Instantiate (Resources.Load ("Armor/" + ChestName));
             ChestInst = NewChest;
             Destroy (NewChest);
             AddChest ();
         }
 
     }

Then for the UI.

          if (itemInfo.EquipType == UIEquipmentType.Chest && !equipped)
                 {
                     //CHEC$$anonymous$$ IF ID IS ABOVE CERTIAN A$$anonymous$$OUNT FOR CHESTFULL
                     transform.root.Send$$anonymous$$essage("Cmdchangechest", itemInfo.ID);
                   //  Player.GetComponent<ChangeArmor>().echest = itemInfo.ID;
                     Player.Send$$anonymous$$essage("addarmor", itemInfo.Armor);
                     Player.Send$$anonymous$$essage("addstrength", itemInfo.Strength);
                     print(itemInfo.ID);
                     StartCoroutine(equipitem());
                 }

I feel like it all looks correct based on my research, maybe its the way I send the message to the Player and its only finding the host? I'm not sure, but I feel like nothing has changed.

EDIT It actually does sends the echest as 0 so the variable is not syncing for the client still

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

107 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

Related Questions

Unet: Spawner spawns for every player one object instead of just one 0 Answers

Networking | Getting buffered other - previous spawned players 1 Answer

lan network discovery 0 Answers

problem using OnStartServer() for unity multiplayer networked game 0 Answers

Network rigidbody synchronize 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