(Optinal) Object Mamagment

Synchronizing an Object

To enable network synchronization of a shared object in FishNet, you’ll need to add specific components that handle position, rotation, and state synchronization across clients.

  1. In the Unity Inspector, add the following FishNet components to your GameObject to be shared:

    1. NetworkObject

    2. NetworkTransform

Instantiating an Object

To dynamically spawn objects during runtime in XR environment, you must instantiate them through the networking system so that all connected users see and interact with the same objects. The OXR Platform provides a user-friendly, FishNet-based API that simplifies this process. Using the platform's networking abstraction layer, developers can easily manage synchronized object instantiation across clients.

To instantiate a networked object using the XUM API:

  1. Import the XumNet package:

    using XumNet;
  2. Call the XumNetwork.Instantiate() method with the desired prefab, position, and rotation:

    XumNetwork.Instantiate(prefab, position, rotation);
    
    // Method prototype
    void XumNetwork.Instantiate(
        NetworkObject prefab,
        Vector3 position,
        Quaternion rotation
    );

You can use this API to spawn both avatars and other shared objects in the networked XR environment. For more detailed information about the XUM API, please refer to this page.

The video below shows how easily an avatar can be spawned using the provided XUM API.

The video video demonstrates how to spawn shared objects using XUM API.


Ownership Transfer

The OXR Platform shows how ownership is requested and obtained when a user initiates a Grab interaction using the GestureHandler component (C_GestureHandler.cs) in the demo project. This component is implemented using the XUM RPC provided by the OXR Platform. You can also learn how to utilize XUM RPC in your own implementations.

To enable users to take control of shared objects in a networked XR environment, follow the steps below:

  1. In the Inspector, add the following component to the GameObject:

    1. XumView

    2. GestureHandler

  2. Add the below component of XR Interaction Toolkit.

    1. XR Grab Interactable

  3. Make sure that the event handler ('Grab' handler in demo project) should be registered in the "XR Grab Interactable" component beforehand.

GestureHandler handles ownership requests by calling XumView.RPC(), which internally triggers a server-side RPC (RequestOwnership) to request ownership transfer.

XumView.RPC(xumView.RPC(nameof(RequestOwnership), RpcTarget.MasterClient);

// Method prototype
void XumView.RPC(
    string methodName,
    RpcTarget target,
    params object[] args
);

The video below demonstrates how to request ownership of a shared object using the provided XUM API.

Fig.3 Tutorial demonstrating Requesting ownership for the shared object by using XUM RPC

Making Object Interactable

To make your shared object respond to user input:

  1. Add the appropriate interaction components, such as:

    1. XR Grab Interactable

    2. XR Simple Interactable

    3. Or any other XR Toolkit-based interaction script

These components allow users to grab, move, or otherwise interact with the object during a session.


Auto-configuring Shared Object

XRCollaboration demo project provides a unified Interaction Manager component that automatically applies all necessary features—such as synchronization, ownership control, and hand interaction handling—to shared objects, without requiring manual API calls. This enables developers to easily make objects interactive and sharable in a multi-user XR environment, with minimal setup effort.

  1. Download and import the XR Interaction Manager package.

  2. Add the Interaction Manager from Assets/App/Scripts/Tmp_Management

  3. Configure the parameters in the Inspector as below.

Last updated