Repository navigation
Tag the camera created by CreateScene with MainCamera - #217
Merged
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
🟡 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
unloadOthersis a supported option, but when it isfalsethis leaves any existing enabledMainCameracameras loaded. Unity does not guarantee thatCamera.mainselects 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.
Code Metrics Report
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%)
Reported by octocov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[CreateScene(camera: true)]created a camera named "Main Camera" without the built-inMainCameratag, soCamera.mainreturnednulland tests relying on it (e.g.,Canvas.worldCamerasetup, screenshot helpers) went inconclusive.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.Camera.mainreturns the created camera.GameObject.tagsetter 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
Attach_WithCamera_CameraMainIsCreatedCamera(Edit Mode and Play Mode) fail before the fix and pass afterCreateSceneAttributeTestPlay Mode 12/12, Edit Mode 2/2🤖 Generated with Claude Code