# SetOwner

> Set the owner object using the specified owner key. You can only set the owner once, multiple attempts will produce a warning. This call does not bind the lifetime of the specified owner object, it is simply a reference. Whilst it is valid to not specify an owner object (NULL), it is recommended for debugging purposes.

## Definition

* **Type:** Method
* **Namespace:** [Unity.U2D.Physics](/engine/6000.6/script-reference/unity/u2d/physics.md)
* **Assembly:** UnityEngine.PhysicsCore2DModule

## SetOwner(ReadOnlySpan\<PhysicsBody>, Object, int)

Set the owner object using the specified owner key. You can only set the owner once, multiple attempts will produce a warning. This call does not bind the lifetime of the specified owner object, it is simply a reference. Whilst it is valid to not specify an owner object (NULL), it is recommended for debugging purposes.

```csharp
public static void SetOwner(ReadOnlySpan<PhysicsBody> bodies, Object owner, int ownerKey)
```

### Parameters

**** (\[ReadOnlySpan\<PhysicsBody>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The bodies to set ownership for.**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): The object that owns this key. Whilst it is valid to not specify an owner object (NULL), it is recommended for debugging purposes.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The owner key to be used. The value must be non-zero. You can use [PhysicsWorld.CreateOwnerKey](/engine/6000.6/script-reference/unity/u2d/physics/physicsworld/createownerkey.md) for this value although any non-zero integer will work.

## SetOwner(Object, int)

Set the owner object using the specified owner key. You can only set the owner once, multiple attempts will produce a warning. This call does not bind the lifetime of the specified owner object, it is simply a reference. It is also valid to not specify an owner object (NULL) to simply gain an owner key however it can be useful, if simply for debugging purposes and discovery, to know which object is the owner.

```csharp
public void SetOwner(Object owner, int ownerKey)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): The object that owns this key. This can be NULL if not required but is recommended as the key is formed in part by the hash-code of the owner object.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The owner key to be used. If zero then a new owner key is created. You can use [PhysicsWorld.CreateOwnerKey](/engine/6000.6/script-reference/unity/u2d/physics/physicsworld/createownerkey.md) for this value although any non-zero integer will work.

## SetOwner(Object)

Set the owner object using the specified owner key. You can only set the owner once, multiple attempts will produce a warning. This call does not bind the lifetime of the specified owner object, it is simply a reference. It is also valid to not specify an owner object (NULL) to simply gain an owner key however it can be useful, if simply for debugging purposes and discovery, to know which object is the owner.

```csharp
public int SetOwner(Object owner)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): The object that owns this key. This can be NULL if not required but is recommended as the key is formed in part by the hash-code of the owner object.

### Returns

| Type                                                       | Description             |
| ---------------------------------------------------------- | ----------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The owner key assigned. |
