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 /
avatar image
2
Question by Demoux · Mar 18, 2016 at 03:59 AM · networkingnetworknetworkview

[UNET] Client cannot call [Command]s, only the host can

I've searched all over the place and have tried numerous things to make this work. Here's the situation. I have the player press a button and it calls a Cmd function that instantiates a prefab and then sends the server the new gameobject using NetworkServer.Spawn(obj). This works great as the host; I can spawn the object and the other client can see it synced as well. However, when I do the same on the client, the Cmd function does not even run. I inserted print messages specifically into the command function to see if it was running, and it wasn't. All the code before and after the function call ran perfectly. It's as if the game decided to skip over the Cmd function because the client can't run those for some reason. Am I missing something here that I should know about client->server messages?

Comment
Add comment · Show 4
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 Guhanesh · Mar 18, 2016 at 05:48 AM 1
Share

[command] functions only run on servers and not on clients.share your code so we can help you.

avatar image Demoux Guhanesh · Mar 18, 2016 at 11:06 PM 0
Share

Thanks for the reply! I didn't know that [Command] functions could only be run on the server. How would a client send a message to the server then? I've looked over the API a bunch but haven't seen anything.

Here's the code that I'm trying to use. Basically, I want the client to send the server a gameobject (instantiated or prefab, doesn't matter) and then for the server to spawn that object so that it will appear for all clients.

[Command] public void CmdSpawn() { NetworkServer.Spawn(spawnedInstance);

 }

And right before that gets called I have this:


        spawnedInstance= Instantiate(spawnPrefab, 
                                    transform.position + new Vector3(0,4,0), 
                                    Quaternion.identity) as GameObject;

So what I'm looking for is a way for a client to tell the server to spawn an object and set a few settings on it as well.

Edit: Okay so I messed up the formatting but you should be able to get what I mean.

avatar image Sruthin55 · Apr 14, 2016 at 05:07 PM 0
Share

I have the same problem and I've been stuck for about a week now and I've seen tutorials where command runs on the client (for example spanning bullets). If you found a solution can you please share .

avatar image Demoux Sruthin55 · Apr 16, 2016 at 10:11 PM 0
Share

@Sruthin55 This is what my code looks like after I solved it. I forget how I did it (I think it was something with how I set the framework up).

 //within FixedUpdate on a keypress
 CmdSpawnPokemon(gameObject);
 
 
     [Command]
     void CmdSpawnPokemon(GameObject master) //Tells the server to spawn our pokemon, then sends it back to the player
     {
         GameObject go = Instantiate(pokemonPrefab, //Instantiate using prefabs
                                     master.transform.position + new Vector3(0, 4, 0),
                                     Quaternion.identity) as GameObject;
         go.GetComponent<PokemonInfo>().owner = master; //Set the owner of the pokemon to the parameter sent by the client
         go.GetComponent<Pokemon$$anonymous$$oveInput$$anonymous$$anager>().info.owner = master; //Do it again for fun
         NetworkServer.SpawnWithClientAuthority(go, connectionToClient); //Spawn the gameobject on the server
         RpcReceiveActivePokemon(go); //Send the gameobject back to the client so they can do stuff with it
     }
     

Try something like that. Sorry that I'm not able to help more.

Oh I remember a bit more now. When I was debugging in the original post and said that the function didn't even run on the client, that was true. It was running on the server and I just wasn't spawning it correctly.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Melloe · Jun 01, 2017 at 02:54 PM

Also stuck on this problem, can anybody halp?

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
0

Answer by Orion_78 · Jan 04, 2019 at 02:06 PM

Client must do Command from a script attached to the Player spawned by the NetworkManager on connection

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

78 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

Related Questions

Simple NetworkView Question. 1 Answer

How to get OnTriggerEnter working over a network 2 Answers

Network Soccer Ball Position jitter, sending transform position late? 0 Answers

UNET AssetID 0000 zero 0 Answers

PLS recommend plugins for networking/sever which ONLY work for authentication + storing player info. 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