4
\$\begingroup\$

I don't know what I did wrong I tried couple different ways from not using commands to using SpawnWithClientAuthority. But It either gives build and compile errors or just the Error in the title

Here the Start function of my player object

 void Start () {
    player = isLocalPlayer;
    race = Data.races[(int)selectRace].getInstance();
    clss = Data.classes[(int)selectClass].getInstance();
    health = race.Health * clss.HealthMultiplyer;
    speed = race.Speed * clss.SpeedMultiplyer;
    armor = race.Armor * clss.ArmorhMultiplayer;
    energy = race.Energy * clss.EnergyMultiplayer;
    skills.AddRange(race.RaceSkills);
    skills.AddRange(clss.ClassSkills);


        Data.entities.Add(this);

    Debug.Log(isLocalPlayer);


    if (!isLocalPlayer)
        return;
    int enID = Data.entities.IndexOf(this);
    foreach (Skill s in skills)
        s.CmdSpawn(enID);

}

And here is the spawn functions from skills I try to spawn

[Command]
public override void CmdSpawn(int enID)
{
    setEntity(Data.entities[enID]);
    Debug.Log("Spawned");
    dir = getEntity().lookingAt;
    gameObject.transform.position = getEntity().transform.position + dir * 0.65f;
    transform.up = dir;
    NetworkServer.Spawn(gameObject);
}

and

[Command]
public override void CmdSpawn(int enID)
{
    setEntity(Data.entities[enID]);
    dir = getEntity().lookingAt;
    transform.up = dir;
    dir = new Vector3(dir.z, dir.y, -dir.x);
    gameObject.transform.position = getEntity().transform.position + dir * 0.65f;

    NetworkServer.Spawn(gameObject);


}

If you can help, thank you ^.^

\$\endgroup\$
  • \$\begingroup\$ " build and compile errors or just the Error in the title" what is build and compile error? \$\endgroup\$ – Muhammad Faizan Khan Jan 17 '18 at 4:26
0
\$\begingroup\$

Well this is the problem which i usally get when first i were learning UNET. So here is the general answer and i am sure it will solve your problem once you get that How UNET actually work.

Beside your code fragment, the error

Trying to send command for object without authority.

clearly means that you are sending Command request from an object whose authority you don't have.

So What it means and how to resolve it you can see my answer Here.

According to your code fragment, Before sending the command (or executing command function), Assign authority of that object(where your script attached) to your Player.

hope that it will make sense and solve the problem. Happy!

\$\endgroup\$
  • \$\begingroup\$ Problem is I am already senfing it from the player object. Threre is even if (!isLocalPlayer) return; statement which if that was false it wouldnt even call the the command. \$\endgroup\$ – Alice Jan 16 '18 at 15:17
0
\$\begingroup\$

Your problem here is this line:

s.CmdSpawn(enID);

You are performing a Command on your Skills from the PlayerController which your player doesn't seem to have authority over. There are a few ways to fix this. Either you can assign authority of the skills to the player something like:

s.GetComponent<NetworkIdentity>().AssignClientAuthority(connectionToClient);

OR

I would personally change around your Spawn method so that it is on your PlayerController and instead of just passing in the enID, you should pass in the Skill s and the enID

CmdSpawn(s, enID);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.