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 Calum-McManus · Aug 12, 2016 at 04:20 PM · networkinginteractionserverside

UNet server spawning objects can't be interacted with

I am spawning some targets on the server (a function with the [ServerCallback] Attribute. Everything syncs up nicely but when I try to shoot them and call the hit function which calls a function with the [Command] Attribute I get "Trying to send command for object without authority".

So i tried setting player authority but no luck at all!

  [ServerCallback]
         public virtual void SpawnObj(GameObject obj)
         {
             GameObject spawnObj = Instantiate(obj) as GameObject;
             m_Spawns.Add(spawnObj);
             
             NetworkServer.Spawn(spawnObj);
             RpcGiveAuth(gameObject.GetComponent<NetworkIdentity>());
         }
 
         [ClientRpc]
         private void RpcGiveAuth(NetworkIdentity id)
         {
             id.AssignClientAuthority(NetworkManager.Instance.client.connection);
         }


I have tried another way using SyncVar Hooks, but once again these are only picked up when the var is changed on the server, which means i need to use Command again so still need authority. Is there a better way of doing this?

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

Answer by DiegoSLTS · Aug 12, 2016 at 05:03 PM

ServerCallback attribute should be used for the standard MonoBehaviour methods like Update or Start. It means they'll run only for instances in the server. I you want a custom method to run only on the server you have to use the Server attribute. Also, check if what you want here isn't actually a Command function. Server and ServerCallback attributes make the method return authomatically if it's not running on the server, so if you call those functions in a client nothing happens, while Command makes a method called on a client to be executed on the server.

NetworkIdentity.AssignClientAuthority should be called in the server, the server is the only one that can set who has authority over something, otherwise any client could take authority on anything. Since you're calling that method in a function marked as a ClientRPC, you're calling AssignClientAuthority on the clients, which does nothing, and if it did something, you'll be giving authority over something to all clients, which doesn't make sense.

Also, you're spawning a GameObject and have a reference on the spawnObj variable, but you're sending the NetworkIdentity of the gameObject with that script attached. You have to assign authority to the spawnObj's NetworkIdentity component.

So, something like this might work, or at least be closer to working:

 [Server]
 public virtual void SpawnObj(GameObject obj)
 {
     GameObject spawnObj = Instantiate(obj) as GameObject;
     m_Spawns.Add(spawnObj);
          
     NetworkServer.Spawn(spawnObj);
     NetworkConnection clientConnection = ; //Here you have to select a client and get the network connection to that client, I can't guess how you'll decide that.
     NetworkIdentity id = spawnObj.GetComponent<NetworkIdentity>();
     id.AssignClientAuthority(clientConnection);
 }
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 Calum-McManus · Aug 16, 2016 at 09:51 AM 0
Share

So this is going in the right direction, the auth is trying to be set on the correct clients but now it says "AssignClientAuthority owner can not be null". Any ideas to get around this. It seems a client must take ownership of the object, but I just want the players to interact with these objects.

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

70 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

Related Questions

Best practices to synchronize object states 1 Answer

Can I use ASP.NET Core SignalR with Unity 3 Answers

Independent countdown on server-side 1 Answer

Should I use Unity to act as a Master Server for a game or what would be the appropriate approach? 0 Answers

UNET - Password protection approach. 2 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