Rotation isnt synced

I cant seem to find anything on spawning an object when a player joins and Ive been stuck on this for weeks

using System;
using UnityEngine;
using Unity.Netcode;

public class PlayerManager : NetworkBehaviour
{
    private readonly NetworkVariable<int> _rotation = new NetworkVariable<int>(0);
    [SerializeField] private GameObject playerBoardPrefab;

    private void Update()
    {
        Debug.Log(OwnerClientId + "; clientInt:" + _rotation.Value);
    }

    public override void OnNetworkSpawn()
    {
        if (!IsServer) return;
        NetworkManager.Singleton.OnClientConnectedCallback += SpawnPlayer;
    }

    public override void OnDestroy()
    {
        if (IsServer)
        {
            NetworkManager.Singleton.OnClientConnectedCallback -= SpawnPlayer;
        }
    }

    private void SpawnPlayer(ulong clientId)
    {
        int rotation = _rotation.Value;
        GameObject playerBoard = Instantiate(playerBoardPrefab);
        playerBoard.transform.GetChild(0).GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, rotation);
        NetworkObject networkObject = playerBoard.GetComponent<NetworkObject>();
        networkObject.Spawn();

        _rotation.Value = rotation+90;
    }
}

what am I missing here

Hi @SkippyProduction ,
Actually this code isn’t enough to understand of your structure.
I really high recommend you “code monkey” tutorial video
There are 2 ways of creating PlayerPrefab object. One is automatically and other is manually.
Create automatically is simple and easy and that video will show you this way.

PlayerManager object is scene object or you create manually?

1 Like