Cam
Cam3mo ago

Ownership of child components with a parent realtime view owned

Feel like this should be obvious but I don't know how to solve it at the moment. I have a gameobject with the root view owned by a client (So it can be destroyed when leaving), but I also have child components on the object that I want to be owned by different clients, however this doesn't exactly seem to be possible in the default state? I'm wondering if it's basically just possible to have the child component be owned by whoever while having the root view owned by a different client. Alternatively another solution could be destroying it myself when the owner leaves? I'm not sure how normcore handles that however, or if there are nice callbacks for when clients join / leave
20 Replies
kapa.ai
kapa.ai3mo ago
Hi @Cam. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Normcore, ownership is hierarchical: if a parent RealtimeView is owned by a client, all child RealtimeViews and RealtimeComponents inherit that ownership. This means you cannot have a child component owned by a different client than the root RealtimeView. The server enforces this, blocking other clients from making changes to the model or any of its child models if the parent is owned by someone else. This is by design to ensure consistent authority and security over object state in multiplayer scenarios. From the documentation:
Models can have other models as children, and the ownership settings of a parent are enforced on all children. If a model is owned by one client, all other clients are blocked from making changes to the model or any of its child models.
...
Rather than setting ownership of every component on the player, we can set ownership of the root RealtimeView, and the server will block all other clients from making modifications to any RealtimeView or RealtimeComponent model.
Room: Server Authority + Ownership + Lifetime Flags
If you need different clients to own different parts of an object, you must structure your GameObjects so that those parts are not children (in the RealtimeView hierarchy) of a root that is owned by another client. Each independently owned part must have its own root RealtimeView. As for destroying objects when a client leaves: Normcore provides lifetime flags for this. If you instantiate a prefab with destroyWhenOwnerOrLastClientLeaves: true, the server will automatically destroy it when the owner disconnects—no custom logic needed. You can also listen for avatar join/leave events using RealtimeAvatarManager.avatarCreated and avatarDestroyed if you need to react to players joining or leaving the room in your own scripts Realtime > XR Avatars. In summary: - You cannot have child components owned by different clients if the parent RealtimeView is owned. - To allow different ownership, split those components into separate root RealtimeViews. - Use Normcore's built-in lifetime flags for automatic destruction on disconnect, and use avatar events for custom join/leave logic. Let me know if you need guidance on restructuring your objects for this! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@271788139381653514> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Mechabit
Mechabit3mo ago
you can leave the root view unowned and have sibling children owned by different people
Cam
CamOP3mo ago
I need the root view owned however for destruction on owner leave, unless there's a better alternative to that
Mechabit
Mechabit3mo ago
what is this for?
Cam
CamOP3mo ago
Player, there's a child component that others can take ownership over, but I want the root to always be owned by the player themselves so it can be destroyed when leaving
Mechabit
Mechabit3mo ago
what if you use a separate object thats not parented to the player whatever it is and just have it follow the player transform
Cam
CamOP3mo ago
Can't sadly :( Is a core part of the player And would need to be destroyed with the player
Mechabit
Mechabit3mo ago
what is it?
Cam
CamOP3mo ago
ik it's not helpful for help sake but i'd rather be intentionally vague for other reasons, basically, the prefab root is owned by the client themselves (or should be for the sake of destroying on leave). there is a child component that ideally can transfer ownership between any client, typically would be owned by the player themselves, but can still transfer. the main ways that would solve it would be either some way to allow child based ownership regardless of parent ownership, or to have some alternative way to destroy it when a person leaves @Max I don't wanna bug you too much, but do you know if this is possible or there is some way to solve it more properly?
Mechabit
Mechabit3mo ago
your best bet is a separate objcet that gets destoryed when the connected object gets destoryed without parenting, you can have the owning player do it you can set up an event that fires OnDestroy
Cam
CamOP3mo ago
Yeah that may work, just unfortunate cause it seems kinda yucky. Additionally would need to have the other object probably destroyed by the lower client I guess that's a large feature suggestion if anything, some callback for clients joining / leaving, I mean they already create new client IDs, it would be nice to do like realtime.OnClientJoined or something
Moardak
Moardak3mo ago
Not saying it wouldn't be helpful to have join/leave events directly built into Realtime but this is super easy to implement yourself. Just follow the pattern in their realtime avatar manager. Whenever an avatar is created it registers itself with the manager and raises a joined event. And whenever one is destroyed, it deregisters with the manager and raises a leave event.
maxweisel
maxweisel3mo ago
@Cam can you tell me what you’re trying to do in the context of your game? there’s no way to have child objects owned by a different client. it almost sounds like you’re having someone pick up an object and if they get disconnected, it gets destroyed with them. even if you could have someone else own the object that they’ve picked up, it’s still gonna get destroyed just because GameObject.Destroy destroys all children no matter what I can probably make a good recommendation if I know at a high-level you’re trying to do in your game
Cam
CamOP3mo ago
I would want it to get destroyed when left that's correct Would it be fine to DM you so I don't have to talk more publicly here?
maxweisel
maxweisel3mo ago
sure
Mechabit
Mechabit3mo ago
is it NSFW? lol
Cam
CamOP3mo ago
hahah no, just some other reasons behind it, apologies lol
Mechabit
Mechabit3mo ago
I think you can register to the owner changed event and if someone leave their objects get set to unowned if they're not destroyed
Cam
CamOP3mo ago
Hm that's not a bad idea yeah

Did you find this page helpful?