how to sync scriptable objects
i have a scriptable object where i put stuff in in a random order (for a puzzle) and whenever a person joins the room they create a different order so i need to have a scriptable object sync or to make the script that puts the info in the scriptable object a "server" script instead of "client" script
if it helps the code that i use
13 Replies
Hi @gewoon_kiefer. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To synchronize your scriptable object data across clients in NormalVR, you'll need to use a different approach. Scriptable Objects are not directly supported for synchronization in Normcore. Instead, you should use a RealtimeComponent and RealtimeModel to synchronize the data. Here's how you can approach this:
1. Create a RealtimeModel to represent your data:
2. Create a RealtimeComponent to manage the synchronization:
3. Use this component in your scene:
- Create an empty GameObject in your scene.
- Add the
SimonColorOrderSync
component to it.
- Assign your SimonColorOrderSO
to the localColorOrder
field.
- Create a list of SimonColorSo
objects and assign them to the availableColors
field.
This approach ensures that:
1. The color order is generated once when the first player joins the room.
2. Subsequent players receive the same order when they join.
3. Any changes to the order are synchronized across all clients.
Remember to add a RealtimeView component to the GameObject that has the SimonColorOrderSync component, so Normcore can manage its lifecycle.
This solution uses Normcore's RealtimeComponent and RealtimeModel system to synchronize the data, which is the recommended approach for custom data synchronization in NormalVR.
Synchronizing Custom Data provides more details on creating custom RealtimeComponents and RealtimeModels in Normcore.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@899009432518803496> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
how are you randomising the order? you can just sync the random seed and it will generate the same puzzle
this is the script i use to randomize the order:
here's how to set a seed https://docs.unity3d.com/ScriptReference/Random.InitState.html
then Random calls will all be the same for clients who use the same seed
how do i create a random seed that the server has then?
@kapa.ai how do I sync a random seed number in normcore
Let me check the knowledge base for you again. One moment! :books:
----------------------
To synchronize a random seed number in Normcore, you can use a RealtimeComponent and RealtimeModel approach. This method ensures that all clients use the same seed for random number generation, maintaining consistency across the network. Here's how you can implement it:
1. First, create a RealtimeModel to hold the seed:
2. Then, create a RealtimeComponent to manage the seed synchronization:
3. Use this component in your scene:
- Create an empty GameObject in your scene.
- Add the
RandomSeedSync
component to it.
- Make sure to add a RealtimeView component to the same GameObject.
Now, whenever you need a random number that should be the same across all clients, you can use the GetRandomNumber
method of the RandomSeedSync
component.
This approach ensures that:
1. The seed is generated once when the first player joins the room.
2. All clients use the same seed for random number generation.
3. The seed is synchronized across all clients.
Remember that this method synchronizes the seed, not individual random numbers. All clients will generate the same sequence of random numbers based on this seed.
For more information on creating custom RealtimeComponents and RealtimeModels in Normcore, you can refer to the Synchronizing Custom Data guide.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@162940911964258305> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
oke thx
@kapa.ai how to use the RandomSeedSync script and make a new random seed
Let me check the knowledge base for you again. One moment! :books:
----------------------
To use the RandomSeedSync script and generate a new random seed in Normcore, you can follow these steps:
1. First, make sure you have the RandomSeedSync script attached to a GameObject in your scene, along with a RealtimeView component.
2. To access the RandomSeedSync component and use it to generate random numbers, you can do the following:
3. To generate a new random seed, you would typically do this when starting a new game or round. You can modify the RandomSeedSync script to include a method for generating a new seed:
4. Then, you can call the GenerateNewSeed method when you want to create a new random seed:
Remember that only one client should generate the new seed (typically the room owner or the game host). The
isOwnedLocally
check in the GenerateNewSeed
method ensures that only the owner of the RandomSeedSync object can generate a new seed.
This approach uses Normcore's RealtimeComponent system to synchronize the random seed across all clients, ensuring that all players in the room will generate the same sequence of random numbers.
Synchronizing Custom Data provides more details on creating and using custom RealtimeComponents in Normcore.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@899009432518803496> Kapa.ai is still learning and improving, please let me know how I did by reacting below.