#Mirror isn't syncing the sprite renderer

26 messages · Page 1 of 1 (latest)

jolly lava
#

So, I am using mirror for networking and when I try to flip my sprite on the x-axis via code, it flips it on the screen of the Local Player, but it doesn't flip it on other clients. When I flip the sprite in the renderer before i run the game, it works just fine. It's just when i try to change the sprite renderer via script, it doesn't work. What do I do?

slim onyx
#

If so add a NetworkTransformChild to the top networked object, add the sprite renderer transform to the target field and then the choose to only sync the rotation.
If the client owner should be able to change the rotation select the Client Authority check box

#

Or make a custom script to sync the rotation using a sync var

slim onyx
#

Or is it one object already with a NetworkTransfrom and it's not syncing the rotation?

jolly lava
#

I am trying to sync 2 things: the parent, which is the player prefab, and a child of that prefab. The parent already has the NetworkTransformChild Component and the Transform of the child is selected on the target field. Also the sync rotation box is checked.

jolly lava
#

Also when i am trying to change the sprite with a script mid-game, it's not updating it

slim onyx
#

its either syncing the rotation or its not

jolly lava
#

The rotation is getting synced

slim onyx
#

what do you mean by sprite renderer then?

#

are you trying to change the target transform in script?

jolly lava
slim onyx
#

oh, that flip

#

yeah, you'll need to make a custom sync var to turn that on/off

#

I'll make an example one for you

#
public class SyncSpriteFlip
{
    [SerializeField]
    private SpriteRenderer spriteRenderer;

    [SyncVar(hook = nameof(OnSpriteFlip))]
    private bool flipX;

    private void OnSpriteFlip(bool oldValuve, bool newValue)
    {
      //No idea if thats the actual code to change the flip x but you get the idea
      spriteRenderer.flip.x = newValue;
    }

    [Server]
    public void SetFlipX(bool newState)
    {
        flipX = newState
    }
}
#

something like that

#

if the client is the only that tells the server if it need to flip, change the [Server] into a [Command]

#

You'll need to do something like that for any value you want to change over the network with unity component fields like that
(or use RPC's instead of SyncVars if you don't need to worry about late joiners)

jolly lava
#

Alright, thanks a lot!

#

I will give it a try soon

jolly lava
#

yeah i had to change the [Server] into [Command]

#

you know any other things you can put in the parentheses of the SyncVar Attribute?