Cinemachine cameras lose Follow/LookAt target after runtime player spawn #35

Closed
opened 2026-03-13 04:34:31 +00:00 by copilot · 0 comments
Collaborator

Problem

Cinemachine virtual cameras that previously had a direct scene reference to the player's Transform (Follow / LookAt) lose that reference when the player is instantiated at runtime (spawned), resulting in cameras that no longer track the player.

Root Cause

Scene-serialized object references to the player are null after spawning because the player GameObject no longer exists as a pre-placed scene object — it is instantiated dynamically.

Proposed Fix

Add a small CinemachineTargetBinder MonoBehaviour to each virtual camera that needs to track the player. On Start (or whenever the player is spawned/ready), the script:

  1. Searches for the player instance (e.g. by tag "Player" or a singleton reference).
  2. Assigns the found Transform to CinemachineVirtualCamera.Follow and/or LookAt.
// Example sketch
void Start()
{
    var player = GameObject.FindWithTag("Player");
    if (player == null) return;
    var vcam = GetComponent<CinemachineVirtualCamera>();
    vcam.Follow = player.transform;
    vcam.LookAt = player.transform;
}

If the player spawns asynchronously, the binder should listen to a spawn event/callback instead of relying on Start timing.

Acceptance Criteria

  • CinemachineTargetBinder script created and attached to all relevant virtual cameras.
  • Cameras correctly track the player after runtime spawn.
  • Works for both synchronous and asynchronous spawn flows.
  • No hard scene references to the player required on the camera GameObjects.
## Problem Cinemachine virtual cameras that previously had a direct scene reference to the player's `Transform` (Follow / LookAt) lose that reference when the player is instantiated at runtime (spawned), resulting in cameras that no longer track the player. ## Root Cause Scene-serialized object references to the player are `null` after spawning because the player GameObject no longer exists as a pre-placed scene object — it is instantiated dynamically. ## Proposed Fix Add a small `CinemachineTargetBinder` MonoBehaviour to each virtual camera that needs to track the player. On `Start` (or whenever the player is spawned/ready), the script: 1. Searches for the player instance (e.g. by tag `"Player"` or a singleton reference). 2. Assigns the found `Transform` to `CinemachineVirtualCamera.Follow` and/or `LookAt`. ```csharp // Example sketch void Start() { var player = GameObject.FindWithTag("Player"); if (player == null) return; var vcam = GetComponent<CinemachineVirtualCamera>(); vcam.Follow = player.transform; vcam.LookAt = player.transform; } ``` If the player spawns asynchronously, the binder should listen to a spawn event/callback instead of relying on `Start` timing. ## Acceptance Criteria - [ ] `CinemachineTargetBinder` script created and attached to all relevant virtual cameras. - [ ] Cameras correctly track the player after runtime spawn. - [ ] Works for both synchronous and asynchronous spawn flows. - [ ] No hard scene references to the player required on the camera GameObjects.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lavarius/ProjectOverlay#35
No description provided.