Need Networking Concepts Clarified Please

Hi All,

I have been stumbling on issue after issue with setting up a 2D networked brawl-style game. Mainly, I can’t seem to fully grasp how to properly setup the networking architecture. I believe lots of material I read/watch have conflicting concepts which has ultimately confused the heck out of me, not to mention lots of the material is also dated.

When a script on a player detects the player pressed a skill/action button, what should be happening? Currently, I have it setup so that a [Command] is called, for example CmdCastSpell. This command instantiates a clone of this spell (presumably on the server, correct?) and then NetworkServer.Spawn’s the clone. Is this all correct? If so, I’m still struggling with a couple concepts:

Flipping sprites. Why is this so difficult?! My current solution was to network all spells and sync their direction, but it feels so wasteful. Nothing else I tried seemed to work though. Either the host or the clients wouldn’t see flipping. Any more efficient methods out there? Why doesn’t NetworkServer.Spawn create a copy of the server’s instance? Do I even have the correct idea of what is actually happening with NetworkServer.Spawn?

Animations aren’t syncing to the clients. I think if I can understand what’s happening behind the scenes more, I’ll be able to answer this one. When something is NetworkServer.Spawn’d, the objects aren’t completely unique, but they aren’t fully synced either. What exactly is shared and what do I have to explicitly share to get things like animations, direction, and position syncing nicely? (These objects do have NetworkAnimators attached.)

When I refer to the Player object, I’m having trouble knowing/understanding which Player is being referenced. I have a spell that is suppose to spawn at the Caster’s hands, but actually spawns at the local player’s hands and then lerps over to the correct location. The caster is sending the [Command] with the correct vector to the server, then the server spawns the object. Why/how is this happening?

spellBook.CmdCastFireball (facingRight, projPos, projRot);

[Command]
    void CmdCastFireball (bool facingRight, Vector3 projPos, Vector3 projRot)
    {
        GameObject fireballClone = (GameObject)Instantiate(Resources.Load("Fireball"), projPos, projRot);
        fireballClone.GetComponent<scrFireball>().projFaceRight = facingRight;
        NetworkServer.Spawn(fireballClone);
    }

Any other help, such as links to useful up-to-date networking guides, would be greatly appreciated. Also, if you need code examples, I’ll provide them. Sorry for being somewhat generic in my problems.

Thanks in advance,
Mr.Muffles

Register the spawnable objects first in Network Manager Inspecter. NetworkServer.Spawn can only be called from GameObjects with Local Authority.Make sure the above script is attached to the Local Player of that connection.Attach Network Transform to your spawn-able objects to sync transform(change sync transform in inspector).Add Network Animator component to sync Animation.