Is there a way to sync the instantiation transform without a RealtimeTransform?
In my scene, static props are loaded in at runtime. I need them to be instantiated with the same position and rotation across all clients, but I do not need to sync position and rotation after instantiation. Realtime.Instantiate requires that I have a RealtimeTransform to sync the position and rotation even if just at instantiation. Is there no other way to do this?
9 Replies
Hi @Voltaia. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, you can synchronize the instantiation transform without a
RealtimeTransform
. The Realtime.Instantiate()
method in NormalVR allows you to instantiate a prefab with a specific position and rotation. This method instantiates a realtime prefab in the scene on all clients, and the fully instantiated game object, along with all RealtimeViews
and RealtimeComponents
, will be initialized and ready for use immediately.
Here is an example of how you can use it:
In this method:
- prefabName
is the name of the prefab to instantiate. The prefab must contain a RealtimeView
on the root and it must live within a Resources folder or Unity will not be able to locate it on other clients.
- position
and rotation
are the initial position and rotation of the instantiated object.
- options
is used to override the default ownership / lifetime settings for the object or to use a specific instance of Realtime when multiple instances are available in the scene.
Please note that the prefab you are instantiating must contain a RealtimeView
on the root. A RealtimeView
is used to identify a game object and its RealtimeComponents
across multiple clients. When a prefab is instantiated, RealtimeView
creates a model for each RealtimeComponent
on the prefab and puts it into the datastore. Then, when the prefab is instantiated on other clients, RealtimeView
will connect the model in the datastore with its respective RealtimeComponent
on the prefab.
You can find more information about this in the Realtime.Instantiate documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.Realtime) and the RealtimeView documentation (https://normcore.io/documentation/realtime/realtimeview).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@276154194606424064> kapa.ai is still learning and improving, please let us know how it did by reacting below
you can disable position/rotation/scale sync after instantiation if you want
or you could sync it with a custom model that only synchronizes it once
Is there any performance hit if I leave position/rotation/scale on?
all components incur a small overhead to track changes but no data is serialized or sent if you’re not changing the position/rotation/scale
Gotcha
Another question: If I call Realtime.Instantiate on a parent object, and there are child objects with custom models, will the custom models sync with each other automatically? It's looking to me like I will have to Realtime.Instantiate the parent object and then also Realtime.Instantiate on all the children.
you don't need to call it on the children
when you call it, it spawns the prefab and wires up all views and components on it
Is there any reason they may not automatically wire up? I'm experiencing some weird behavior.
as long as you're not trying to AddComponent<> them at runtime then you should be good