Hey there,
I'm having an issue where clients can correctly only see objects in the additive scene they are in, but are able to take damage from collisions with objects from other scenes.
I have three scenes:
- Main - My offline scene that basically just has a 'find match' button that calls
StartClient() - Queue - An empty container scene that is set to the online scene on the network manager
- Arena - the additive scene players are moved two when two people connect to the server / enter the queue.
I've added a SceneInterestManagement to my Network Manager in the main scene and added a PhysicsSimulator to an empty GameObject in the Arena scene.
When players connect, they are added into lobbies and when the lobby reaches max players (2), this StartMatch function is called in my custom network manager
private IEnumerator StartMatch(Lobby lobby)
{
var op = SceneManager.LoadSceneAsync("Arena", LoadSceneMode.Additive);
yield return op; // Wait for the scene to load
lobby.Scene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
if (lobby.Scene.IsValid())
{
foreach (var conn in lobby.Players)
{
// Destroy old player object
if (conn.identity != null)
{
NetworkServer.Destroy(conn.identity.gameObject);
yield return new WaitForEndOfFrame();
}
// Send message to client to load the new scene
conn.Send(new SceneMessage { sceneName = lobby.Scene.name, sceneOperation = SceneOperation.LoadAdditive });
yield return new WaitForEndOfFrame();
base.OnServerAddPlayer(conn);
SceneManager.MoveGameObjectToScene(conn.identity.gameObject, lobby.Scene);
}
}
else
{
Debug.LogError("Failed to load Arena scene.");
}
}
Is there something obviously wrong about how I'm moving the players into a new Arena scene here?
If I look at the scene from the server's perspective (image attached) when I have 4 players that have queued up, it all looks good. The players are separated into different scenes, but the fireball object at the bottom of the first arena scene did damage to a player in the second scene.
The Fireball in this case is spawned via a [Command] attributed function, the code that actually spawns the object is here:
public override void Cast(GameObject caster, Vector2 startPosition, Vector2 targetPosition)
{
if (!NetworkServer.active) return;
var projectile = Instantiate(projectilePrefab, startPosition, Quaternion.identity);
SceneManager.MoveGameObjectToScene(projectile, caster.scene);
NetworkServer.Spawn(projectile);
projectile.GetComponent<Projectile>().SetTarget(targetPosition);
}
Any help in understanding why the server-handled collisions aren't recognizing the different scenes would be greatly appreciated, thanks!