# (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:

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

    ```csharp
    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**](https://github.com/oxr-sdk/XumNet).

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

{% embed url="https://youtu.be/axJmmaOfT8M" fullWidth="false" %}

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

{% embed url="https://youtu.be/d3jKuBUHBpg" %}

***

## 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.&#x20;
   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.

<figure><img src="https://1876721110-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk9x6Q91DD1TwPbuAFpLM%2Fuploads%2FFFF37k02XN4oXGGZ40w6%2Fimage.png?alt=media&#x26;token=80ab3595-64d7-4a00-af7c-395bca7d4ab3" alt=""><figcaption></figcaption></figure>

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

```csharp
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.

{% embed url="https://youtu.be/7gg1seKIubs" %}
**Fig.3** Tutorial demonstrating Requesting ownership for the shared object by using XUM RPC\

{% endembed %}

***

## 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**](https://github.com/oxr-sdk/Packages/blob/main/XRInteractionManager.unitypackage) package.
2. Add the **Interaction Manager** from `Assets/App/Scripts/Tmp_Management` &#x20;
3. Configure the parameters in the Inspector as below.

<figure><img src="https://1876721110-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk9x6Q91DD1TwPbuAFpLM%2Fuploads%2Fgit-blob-18bb67e2de010c620a7345fbb842b7e68d5b2ae7%2FObjectHandling.png?alt=media" alt=""><figcaption></figcaption></figure>
