# Unity takes wrong cameras to players

**URL:** <https://community.coherence.io/t/unity-takes-wrong-cameras-to-players/597>\
**Category:** Help\
**Created:** [October 9, 2024, 6:22pm UTC](https://community.coherence.io/t/unity-takes-wrong-cameras-to-players/597 "2024-10-09T18:22:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dopszu](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dopszu](https://community.coherence.io/u/dopszu)\
**Post date:** [October 9, 2024, 6:22pm UTC](https://community.coherence.io/t/unity-takes-wrong-cameras-to-players/597/1 "2024-10-09T18:22:03Z")

</div>

I’m trying to add coherence to my simple multiplayer game, but the problem is after joining to the room (rooms work well) unity isn’t recognising the cameras to players, so u can move the player, but you see view of another player camera (you can see yourself from 3rd perspective and you should from first)

---

<div class="post-metadata">

**Author:** ![cary](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/cary/32/37_2.png) [@cary](https://community.coherence.io/u/cary)\
**Post date:** [October 9, 2024, 6:45pm UTC](https://community.coherence.io/t/unity-takes-wrong-cameras-to-players/597/2 "2024-10-09T18:45:19Z")

</div>

Hey there. It’s likely you have the camera setup in the player’s prefab. This means that when you have a replicated player that replicated player also has a camera so if it’s set to be the main camera it will take over. The easy solution to this is using [Component Actions](https://docs.coherence.io/manual/components/coherence-sync#component-actions).

You can set the camera component to be disabled when replicated (not authority)

Alternatively, you can use the [CoherenceSync Events](https://docs.coherence.io/manual/components/coherence-sync#coherencesync-events) to disable the GameObject that holds the camera and other things you want disabled on the player when it is replicated.

---

<div class="post-metadata">

**Author:** ![muhammadkhankk945](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@muhammadkhankk945](https://community.coherence.io/u/muhammadkhankk945)\
**Post date:** [October 31, 2024, 1:52pm UTC](https://community.coherence.io/t/unity-takes-wrong-cameras-to-players/597/3 "2024-10-31T13:52:24Z")

</div>

OOH i am having the same issue here, but i wrote code and it got fixed,  
Here is the code:  
[SerializeField] private Camera playerCamera;

// This field can be set when instantiating or spawning the car to mark it as owned by the local player  
public bool isLocalPlayer;

void Start()  
{  
UpdateCameraOwnership();  
}

private void UpdateCameraOwnership()  
{  
// Enable the camera only if this car is owned by the local player  
playerCamera.enabled = isLocalPlayer;  
}

and here is where the main code is located:  
// Instantiates the selected car prefab at a specified position  
private void InstantiateSelectedCar(GameObject carPrefab, bool isLocalPlayer)  
{  
Vector3 spawnPosition = Vector3.zero; // Adjust as needed for spawn location  
Quaternion spawnRotation = Quaternion.identity; // Adjust as needed for initial rotation  
GameObject carInstance = Instantiate(carPrefabs[selectedCarIndex], spawnPosition, spawnRotation);

```
 // Set isLocalPlayer for the local player’s car
 CarCameraManager cameraManager = carInstance.GetComponent<CarCameraManager>();
 if (cameraManager != null)
 {
     cameraManager.isLocalPlayer = isLocalPlayer;
 }

```

}

---

<div class="post-metadata">

**Author:** ![ciro](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/ciro/32/82_2.png) [@ciro](https://community.coherence.io/u/ciro)\
**Post date:** [November 1, 2024, 11:07am UTC](https://community.coherence.io/t/unity-takes-wrong-cameras-to-players/597/4 "2024-11-01T11:07:47Z")

</div>

> [@muhammadkhankk945](#):
>
> OOH i am having the same issue here, but i wrote code and it got fixed,

Thanks for sharing the code, @muhammadkhankk945!

But check out also @cary’s reply above, because Component Actions are very handy to create behaviour that differs whether that entity is authoritative or not, and you can even create custom ones!

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex017/uploads/coherence/original/1X/b3aa79eb9519fac7aad7eba18f15a1e8ce60f6e2.png) [@system](https://community.coherence.io/u/system)\
**Post date:** [January 30, 2025, 11:08am UTC](https://community.coherence.io/t/unity-takes-wrong-cameras-to-players/597/5 "2025-01-30T11:08:07Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
