- Home /
Trying to send command for object without authority - on a networkidenity with local authority
Im trying to send a command so that a the health of an enemy will be subtracted by sending a command to the server but I keep getting the warning: Trying to send command for object without authority. While the NetworkIdentity on the gameobject is set to local authority. Can anybody help me with this
This is how the command is called:
public void damageEnemy(GameObject enemy, float damage) {
if (!isLocalPlayer) return;
EnemyManager enemyManager = enemy.GetComponent<EnemyManager>();
if (enemyManager == null) return;
enemyManager.CmdDamage(damage);
}
Answer by Remingsworth · Oct 01, 2017 at 08:04 AM
It sounds like there are 2 issues here. 1) You said you are calling the networking method from a child object. You need to have all your networking stuff on the parent object (all networking scripts and only 1 network identity which should have Local Player Authority). Just make references from the scripts on the player parent to tell the child objects what to do. 2) You shouldn't have commands on a non-player object. Commands are sent from the client to the server and not from non-player objects to the server. You need to use something like [SyncVar] to sync the health of the enemy over the network.
Answer by DiegoSLTS · Aug 12, 2016 at 01:40 PM
What gameObject's NetworkIdentity has local authority? It sounds like you set local authority for the object with that script, but you need local authority on the enemyManager object to send commands from that object.
Yes the object of that script has the authority but I call the method from a child object
I'm not sure what you meant, the enemy$$anonymous$$anager object hast local player authority set?
Note that for non-player objects setting "local player authority" is not enough to be able to execute commands, you have the set who's the player (client) that has authority, since the object exists for all the clients but only one can have authority over it.
Check this link, specially the "Client Authority for Non-Player Objects" section: https://docs.unity3d.com/$$anonymous$$anual/UNetConcepts.html
You don't want to assign Local Player Authority on an enemy just to deal damage... everyone online would be fighting, so to speak, over who has authority to deal damage.
Your answer
Follow this Question
Related Questions
Can I use Rpc Calls and Commands on the same object? 0 Answers
UNET Server not setting [SyncVar] 0 Answers
Trying to send command for object without authority. - change color of object from client 0 Answers
SyncListString not changing in a Command 0 Answers
SyncListString not changing properly 0 Answers