Skip to content

Tag the camera created by CreateScene with MainCamera - #217

Merged
nowsprinting merged 3 commits into
masterfrom
fix/create-scene-main-camera-tag
Sep 15, 2026
Merged

nowsprinting merged 3 commits into
masterfrom
fix/create-scene-main-camera-tag

Conversation

@nowsprinting

@nowsprinting nowsprinting commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • [CreateScene(camera: true)] created a camera named "Main Camera" without the built-in MainCamera tag, so Camera.main returned null and tests relying on it (e.g., Canvas.worldCamera setup, screenshot helpers) went inconclusive.
  • Set tag = "MainCamera" on the created GameObject. The block is shared by the Play Mode and Edit Mode scene-creation paths, so one change covers both.
  • Update the XML doc comment note to state that Camera.main returns the created camera.
  • The GameObject.tag setter is a banned API (RS0030); suppressed at line scope with a why-not comment, since the ban text itself allows assignment outside the player loop.

Test plan

  • New acceptance tests Attach_WithCamera_CameraMainIsCreatedCamera (Edit Mode and Play Mode) fail before the fix and pass after
  • CreateSceneAttributeTest Play Mode 12/12, Edit Mode 2/2

🤖 Generated with Claude Code

nowsprinting and others added 3 commits September 15, 2026 15:53
The camera created by the attribute is named "Main Camera" but is not
tagged MainCamera, so Camera.main returns null and tests relying on it
become inconclusive. These tests pin the expected behavior before the fix.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Camera.main resolves cameras by the built-in MainCamera tag, so a camera
merely named "Main Camera" is invisible to it. Tagging it lets tests that
rely on Camera.main (e.g. Canvas.worldCamera setup, screenshot helpers)
work under [CreateScene(camera: true)] without extra setup.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The GameObject.tag setter is banned to keep tag writes out of the player
loop, but Camera.main only resolves MainCamera-tagged cameras and this
assignment runs once per test in BeforeTest, so the ban's own escape
hatch applies.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 15, 2026 07:11
@github-actions github-actions Bot added the bug Something isn't working label Sep 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Clarify the unloadOthers documentation and update the README to match the new Camera.main contract.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR tags cameras created by CreateSceneAttribute as MainCamera, enabling Camera.main, with Edit Mode and Play Mode coverage.

Changes:

  • Tags generated cameras as MainCamera.
  • Adds acceptance tests for both test modes.
  • Updates XML documentation.
File summaries
File Summary
Runtime/Attributes/CreateSceneAttribute.cs Tags created cameras and updates documentation. Findings: moderate documentation issue regarding competing main cameras when unloadOthers is false; README documentation update requested as a nit.
Tests/Runtime/Attributes/CreateSceneAttributeTest.cs Adds Play Mode coverage for Camera.main.
Tests/Editor/Attributes/CreateSceneAttributeTest.cs Adds Edit Mode coverage for Camera.main.
Review details

Suppressed comments (1)

Runtime/Attributes/CreateSceneAttribute.cs:39

  • unloadOthers is a supported option, but when it is false this leaves any existing enabled MainCamera cameras loaded. Unity does not guarantee that Camera.main selects the newly created camera in that situation, so this parameter documentation overstates the contract. Either qualify the documentation to the no-competing-camera case or explicitly define how competing main cameras are handled.
        /// <param name="camera">true: create main camera object (tagged <c>MainCamera</c>, so <c>Camera.main</c> returns it) in new scene</param>
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Runtime/Attributes/CreateSceneAttribute.cs
@github-actions

Copy link
Copy Markdown

Code Metrics Report

master (aa04e7e) #217 (9d83bfa) +/-
Coverage 84.5% 84.5% 0.0%
Code to Test Ratio 1:1.4 1:1.4 +0.0
Test Execution Time 6m22s 7m19s +57s
Details
  |                     | master (aa04e7e) | #217 (9d83bfa) | +/-  |
  |---------------------|------------------|----------------|------|
  | Coverage            |            84.5% |          84.5% | 0.0% |
  |   Files             |               65 |             65 |    0 |
  |   Lines             |             2453 |           2453 |    0 |
  |   Covered           |             2073 |           2073 |    0 |
+ | Code to Test Ratio  |            1:1.4 |          1:1.4 | +0.0 |
  |   Code              |             4159 |           4161 |   +2 |
+ |   Test              |             6154 |           6175 |  +21 |
- | Test Execution Time |            6m22s |          7m19s | +57s |

Code coverage of files in pull request scope (100.0% → 100.0%, patch 100.0%)

Files Coverage +/- Patch Coverage Status
Runtime/Attributes/CreateSceneAttribute.cs 100.0% 0.0% 100.0% modified

Reported by octocov

@nowsprinting
nowsprinting merged commit df8126a into master Sep 15, 2026
15 checks passed
@nowsprinting
nowsprinting deleted the fix/create-scene-main-camera-tag branch September 15, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants