Niv
Niv3d ago

Mixing ownership within a single prefab

I'd like to have mixed ownership within a single Realtime.Instantiate() prefab. Basically it is made of two parts: 1st part is always owned by the client that created it 2nd part starts ownerd by the creating client but later other clients can request ownership of that part From the docs it seems like you cannot take ownership of a realtimeView and its components if the parent view is owned by another client. Does that mean I need to put a root RealtimeView with no RealtimeComponents on it that will remain unOwned so I can request ownership of the parts mentioned above? Any other design pattern offered for mixed ownership?
3 Replies
kapa.ai
kapa.ai3d ago
Hi @Niv. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources provided, I can offer some insights on mixing ownership within a single prefab in NormalVR. You're correct that by default, ownership of a RealtimeView is enforced on all its children. As stated in the Server Authority + Ownership + Lifetime Flags 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." However, there are a couple of approaches you can consider to achieve mixed ownership within a single prefab: 1. Unowned Root RealtimeView: Your suggestion of using an unowned root RealtimeView is a valid approach. You can create a root GameObject with a RealtimeView that remains unowned, and then have child GameObjects with separate RealtimeViews for the parts you want to have different ownership. This way, you can request ownership of the child RealtimeViews independently. 2. Using RealtimeComponents with separate ownership: Another approach is to use multiple RealtimeComponents on the same GameObject, each with its own ownership. As mentioned in the Server Authority + Ownership + Lifetime Flags documentation: "A single object can have more than one RealtimeComponent, all of them owned by different clients." To implement this, you would need to create custom RealtimeComponents for each part of your prefab that needs separate ownership. Make sure to compile your RealtimeModels with a meta-model by using the createMetaModel: true attribute:
[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;
}
Then, you can request ownership of specific components:
GameObject myObject = Realtime.Instantiate("My Object", ownedByClient: true);

// Get the custom RealtimeComponent for the second part
MyCustomComponent secondPart = myObject.GetComponent<MyCustomComponent>();

// Later, another client can request ownership of just this component
secondPart.RequestOwnership();
GameObject myObject = Realtime.Instantiate("My Object", ownedByClient: true);

// Get the custom RealtimeComponent for the second part
MyCustomComponent secondPart = myObject.GetComponent<MyCustomComponent>();

// Later, another client can request ownership of just this component
secondPart.RequestOwnership();
This approach allows you to have fine-grained control over ownership within a single prefab without needing to create a separate hierarchy of GameObjects. Remember that when using custom RealtimeComponents with separate ownership, you'll need to manage the logic for when and how ownership changes occur in your application. Both of these approaches should allow you to achieve mixed ownership within a single prefab instantiated by Realtime.Instantiate(). The choice between them depends on your specific use case and how you want to structure your prefab and components. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3d ago
<@269927864265211906> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
maxweisel
maxweisel3d ago
If you went to track two owners, they need to be siblings of each other Leave the root unowned and have two child game objects with conflicting ownership

Did you find this page helpful?