how to sync what parent the object has?
i have a a object that i spawn in with realtime.instantiate() and it needs to have a specific parent to have a correct scale and function correctly,
for the player who spawns the object it is correctly done but for everyone else it is just in the hierarchy and not with the correct parent
3 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:
----------------------
According to the documentation, RealtimeTransform and RealtimeView do not support reparenting objects in Normcore. This is a known limitation that can cause synchronization issues between clients.
From the documentation:
Don't reparent game objects with RealtimeTransform on them!>
RealtimeTransform does not track the parent of a RealtimeTransform and cannot synchronize it at runtime.>
Additionally, if a RealtimeTransform is reparented under another game object, and that game object is destroyed, it will take the RealtimeTransform with it, leading to inconsistent state between clients.RealtimeTransform Extra Notes Instead of reparenting, the documentation suggests this alternative approach: 1. Create an empty game object at the position where you want your object to be (on the parent) 2. Use a script to synchronize the world position between this empty game object and your RealtimeTransform object Here's the recommended approach from the documentation:
A common case where folks want this functionality is in order to pick up an object. 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 that you would like to pick up.RealtimeTransform Extra Notes This approach gives you the same visual result without the synchronization issues that come with reparenting. If your object has a Rigidbody, make sure to use the
MovePosition()
and MoveRotation()
methods in FixedUpdate()
.
For your specific case, you might need to:
1. Create your parent object first
2. Instantiate your object with Realtime.Instantiate()
3. Use a script to synchronize the position/rotation/scale between the parent and the instantiated object on all clients
----------------------
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.
Realtime Transform doesn't support reparenting but you can create this behaviour if you give every parent a unique id and reparent the object on the client locally
Or you can minic reparenting by setting the position and rotation and scale of the object to match the parent every frame on the owner side and it will behave as if it were reparented without the destroyed parent issue mentioned by the bot