Random lobby seed
how do I make a room seed that is set when a person joins the lobby and is synced to everyone?
5 Replies
Hi @Jaydon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To create a random room seed that is set when the first person joins a Normcore lobby and is synced to everyone, you should use a custom RealtimeModel to store the seed value. This ensures the seed is synchronized across all clients, including late joiners.
Here’s a high-level approach based on the official guides:
1. Create a RealtimeModel for the seed:
Define a model class (e.g.,
Inherit from
This ensures the seed is generated and synchronized as soon as the room is joined. 4. Access the seed from any client:
All clients can read the seed from the model after joining the room. This approach leverages Normcore’s datastore to ensure the seed is set once and remains consistent for all clients, including those who join later. For more details on synchronizing custom data, see the official guide: Synchronizing Custom Data. If you need a full working example, you can adapt the pattern from the Timers + Synchronized Playback recipe, replacing the time field with your seed. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
Define a model class (e.g.,
RoomSeedModel
) with a private field for the seed, marked with the [RealtimeProperty]
attribute.
2. Create a RealtimeComponent to manage the seed:Inherit from
RealtimeComponent<RoomSeedModel>
. When the component is initialized, check if the seed is unset (e.g., zero). If so, generate a random seed and set it in the model. This will sync the value to all clients.
3. Add the component to a GameObject in your scene:This ensures the seed is generated and synchronized as soon as the room is joined. 4. Access the seed from any client:
All clients can read the seed from the model after joining the room. This approach leverages Normcore’s datastore to ensure the seed is set once and remains consistent for all clients, including those who join later. For more details on synchronizing custom data, see the official guide: Synchronizing Custom Data. If you need a full working example, you can adapt the pattern from the Timers + Synchronized Playback recipe, replacing the time field with your seed. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@891438191020744704> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
What do you mean synced to everyone? Like a random number that's used to generate a level? The bot's answer here is correct.
Yes, sorry. I figured it out myself and I didn't realize that I downvoted. My solution was similar to the bot's so it wasn't wrong.
all good! glad you figured something out