Hello !
I have one simulator for two scenes (Lobby and Arena ) ,that simulator switches when you play the game, players are not supposed to be split in two scenes and so i need new connections to have a feedback of "where is the simulator is " but the two scenes seem impossible to communicate to each others.
what’s the best way to assign the right scene to load on a new client connection ?
Is there a place for the whole server where i can fetch variables as a new client connection ? (like a big server singleton that synchronize the chosen data )
Can i create a serverside object that will answer to multiples scenes client connections ?
Client connections are special entities that are always visible, regardless of the scene you’re in. You can create a client connection object for the Simulator that will keep the information about the scene that simulator is in.
For example:
[RequireComponent(typeof(CoherenceSync))]
public class SimulatorConnection : MonoBehaviour
{
[Sync]
public string Scene;
CoherenceSync sync;
void Start()
{
sync = GetComponent<CoherenceSync>();
}
void Update()
{
if (sync.HasStateAuthority)
{
Scene = SceneManager.GetActiveScene().name;
}
}
}
Just attach this script to a game object and create a networked entity out of it. The last step is assigning this entity as Simulator Client Connection:
Simulator will automatically create that object after connecting to the world. After client connects, it can use the connections manager to get the simulator connection object:
I’m afraid, for the time being, if you’re using the scene system then this simply won’t be achievable. Without the scene system this is easily done, however you’re losing filtering entities by scene.
We’ve published a 1.5.0 a second ago which features Cloud Storage - you could make Simulator update the entry for “activeScene” whenever it changes while new clients could simply fetch it upon connection. This would give you a close to real-time sync without losing the scene filtering.