MasterOX 水
MasterOX 水2mo ago

realtime instantiate

how can i instantiate something under a parent with realtime
4 Replies
kapa.ai
kapa.ai2mo ago
Hi @MasterOX 水. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To instantiate a prefab under a parent with Realtime in NormalVR, you can use the Realtime.Instantiate() method. This method instantiates a realtime prefab in the scene on all clients. 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 to use Realtime.Instantiate():
GameObject playerGameObject = Realtime.Instantiate(
prefabName: "Player", // Prefab name
ownedByClient: true, // Make sure the RealtimeView on this prefab is owned by this client
preventOwnershipTakeover: true, // Prevent other clients from calling RequestOwnership() on the root RealtimeView.
useInstance: realtime); // Use the instance of Realtime that fired the didConnectToRoom event.
GameObject playerGameObject = Realtime.Instantiate(
prefabName: "Player", // Prefab name
ownedByClient: true, // Make sure the RealtimeView on this prefab is owned by this client
preventOwnershipTakeover: true, // Prevent other clients from calling RequestOwnership() on the root RealtimeView.
useInstance: realtime); // Use the instance of Realtime that fired the didConnectToRoom event.
However, it's important to note that Normcore does not synchronize parent relationships between objects. If the new parent gets destroyed, it will take the RealtimeView and its components with it, which can result in desyncs between your clients. Therefore, it's generally recommended not to reparent a game object with a RealtimeView or RealtimeComponent on it (source (https://normcore.io/documentation/realtime/common-questions#can-i-reparent-a-game-object-with-a-realtimeview-or-realtimecomponent-on-it)). Also, RealtimeTransform does not support reparenting (source (https://normcore.io/documentation/realtime/common-questions#can-i-reparent-realtimetransform)). For more information, you can check out the Realtime.Instantiate() documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.Realtime). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@758040514678489279> kapa.ai is still learning and improving, please let us know how it did by reacting below
Mechabit
Mechabit2mo ago
RealtimeTransform | Normcore Documenation
RealtimeTransform is a built-in RealtimeComponent that can be used to synchronize the transform or rigidbody of a GameObject.
Mechabit
Mechabit2mo ago
parenting isn't supported out of the box Instead of reparenting, create an empty game object on your player character at the pick-up point. Then use a script that synchronizes the world position of the pick-up point object and the RealtimeTransform object