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?
#Mirror isn't syncing the sprite renderer
26 messages · Page 1 of 1 (latest)
is your sprite a child object?
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
Or is it one object already with a NetworkTransfrom and it's not syncing the rotation?
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.
it's syncing the rotation, but the sprite renderer isn't getting synced
Also when i am trying to change the sprite with a script mid-game, it's not updating it
I'm not too sure what you mean by that, in the inspector in the transform component is the rotation changing or not if you use the editor as the client?
its either syncing the rotation or its not
The rotation is getting synced
what do you mean by sprite renderer then?
are you trying to change the target transform in script?
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)
It worked! That was of huge help, thanks!
yeah i had to change the [Server] into [Command]
you know any other things you can put in the parentheses of the SyncVar Attribute?