I recently made a change to my game that broke everything.
Before, the whole game would be in one scene, with a simple host and client button. Depending on if the Host pressed the button first, I would change the default player prefab through an approval check to fit the client character and then just run StartClient().
Today I updated it so that you first have to go through a main menu and character selection screen before you enter the game, so I changed the spawn mechanic to an empty gameobject in the gameplay scene that spawns the character as a player prefab using SpawnAsPlayerObject() in OnNetworkSpawn()
For some reason this completely broke my camera and movement script and I can’t access the Singleton that’s in the scene for some reason.
For example this code doesn’t instantiate the cameras anymore, neither locally nor on the network. I checked and the Client does have ownership:
public class AssignCamera : NetworkBehaviour
{
[SerializeField] GameObject _camerasPrefab;
public GameObject cameras;
public override void OnNetworkSpawn()
{
if (!IsOwner) return;
cameras = Instantiate(_camerasPrefab, Vector3.zero, Quaternion.identity);
cameras.GetComponentInChildren<CinemachineVirtualCamera>().Follow = transform;
cameras.GetComponentInChildren<CinemachineVirtualCamera>().LookAt = transform;
cameras.transform.GetChild(2).GetComponent<CinemachineVirtualCamera>().Follow = transform;
cameras.transform.GetChild(2).GetComponent<CinemachineVirtualCamera>().LookAt = transform;
SpawnCamerasServerRpc();
}
[ServerRpc]
private void SpawnCamerasServerRpc()
{
cameras.GetComponent<NetworkObject>().SpawnWithOwnership(OwnerClientId);
}
}
My shoddy programming also requires the cameras to be accessible by other scripts in the player through a public variable.
Some help would be appreciated XOXO