when avatars are created do they have ownership of the child views as well

when an avatar is created are the child views also owned , i see that in the demo the avatar thats created has ownership of the origin view and transform and the child views only have ownership of the realtime transforms and not the views , is there a way to set that , would it be better to create a new avatar manager with a new custom model that has a meta model to achieve owner ship of child views when the avatar is created
4 Replies
kapa.ai
kapa.ai2mo ago
Hi @Lost Wizard Corp.. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, when an avatar is created, the ownership settings of the parent are enforced on all child models. This means 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. This behavior is seen in action with RealtimeViews and RealtimeComponents as they both use models. The RealtimeView's model contains the models for all child RealtimeViews and all RealtimeComponents, so any ownership settings on the RealtimeView apply to child views and to components as well source (https://normcore.io/documentation/room/ownership-and-lifetime-flags#how-ownership-is-enforced). In the case of a player prefab, which is a common RealtimeView prefab, we generally want to ensure that each player prefab can only be modified by the player that owns it. 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 source (https://normcore.io/documentation/room/ownership-and-lifetime-flags#how-ownership-is-enforced). However, it's important to note that only the local player can update values in realtime components on their own avatars. This is intentional! It's recommended that you don’t try to clear ownership of the avatar—you’re going to be in a world of hurt if you do source (https://normcore.io/documentation/realtime/common-questions#im-trying-to-store-my-players-health-in-a-realtimecomponent-on-my-avatar-how-can-i-let-other-players-modify-this-values-or-others). If you want to provide additional granularity, you can request ownership on any RealtimeComponent or RealtimeModel. A single object can have more than one RealtimeComponent, all of them owned by different clients. Requesting ownership works just like it does for RealtimeView. However, before you can use this on a custom RealtimeComponent, you'll need to make sure your RealtimeModel includes a meta-model source (https://normcore.io/documentation/room/ownership-and-lifetime-flags#requesting-ownership-of-any-realtimecomponent-or-realtimemodel). Here's an example of requesting ownership on a RealtimeTransform, which is itself a RealtimeComponent subclass:
public void CreateObjectAndRequestOwnershipOfRealtimeTransform() {
// Instantiate the My Object prefab, leave the view unowned.
GameObject myObject = Realtime.Instantiate("My Object", ownedByClient: false);

// Get the RealtimeTransform component
RealtimeTransform realtimeTransform = myObject.GetComponent<RealtimeTransform>();

// Request Ownership
realtimeTransform.RequestOwnership();
}
public void CreateObjectAndRequestOwnershipOfRealtimeTransform() {
// Instantiate the My Object prefab, leave the view unowned.
GameObject myObject = Realtime.Instantiate("My Object", ownedByClient: false);

// Get the RealtimeTransform component
RealtimeTransform realtimeTransform = myObject.GetComponent<RealtimeTransform>();

// Request Ownership
realtimeTransform.RequestOwnership();
}
And here's how you can compile your model with a meta-model:
[RealtimeModel(createMetaModel: true)]
public partial class MyModel {
[RealtimeProperty(1, true)]
private float _myNumber;
}
[RealtimeModel(createMetaModel: true)]
public partial class MyModel {
[RealtimeProperty(1, true)]
private float _myNumber;
}
The createMetaModel: true in the RealtimeModel attribute constructor tells Normcore to compile your model with a meta-model, which is where all ownership state will be stored so it may be sent to the server source (https://normcore.io/documentation/room/ownership-and-lifetime-flags#requesting-ownership-of-any-realtimecomponent-or-realtimemodel). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1220362612794069042> kapa.ai is still learning and improving, please let us know how it did by reacting below
Mechabit
Mechabit2mo ago
you can just check isOwnedLocallyInHierarchy property of the child view if you need that info, taking ownership of every child view is unnecessary.
Lost Wizard Corp.
the movement control script i have is on the prefab avatar itself and the controls need to be separated so one avatar doesnt control the other avatars with the control script which i put the isownedlocally check and that script is on each hand which has a realtime transform and view but when its instantiated the realtime view on the hands doesnt pick up the owned by client and is left with no ownership , then the script fails because its not owned locally , the realtime transforms on the hands start with local client ownership, this happens on the head too , i went back to check the demo and the vr player prefab there also is started with only realtime transform local client ownerships as well to see if it was something i added or perhaps the way it was generated from the start ,i went ahead and made a fresh avatar manager so i could adjust the parameters and a new model so ican access when the model has finished loading as well as making it meta-model = true to grab the ownership of all the children , which is where im at now and havent had a chance to test yet with this setup, i will try referencing the main view on the origin