Skip to content

Comments

Fast enter playmode support#1098

Open
sim-bz wants to merge 7 commits intomainfrom
uum-131015
Open

Fast enter playmode support#1098
sim-bz wants to merge 7 commits intomainfrom
uum-131015

Conversation

@sim-bz
Copy link
Collaborator

@sim-bz sim-bz commented Feb 12, 2026

Purpose of this PR

https://jira.unity3d.com/browse/UUM-131015

Static variable management in Cinemachine to support fast enter playmode.

We'll need to add exceptions for

  • CinemachineFreeLook CreateRigOverride and DestroyRigOverride (because of static responders in CinemachineFreeLookEditor).
  • CinemachineVirtualCamera CreatePipelineOverride and DestroyPipelineOverride (because of static responders in CinemachineVirtualCameraEditor).
  • CinemachineCore CameraUpdatedEvent and CameraActivatedEvent (because of static responders in CinemachineVolumeSettings).

Testing status

[Explanation of what’s tested, how tested and existing or new automation tests. Can include manual testing by self and/or QA. Specify test plans. Rarely acceptable to have no testing.]

  • Added an automated test
  • Passed all automated tests
  • Manually tested

Documentation status

[Overview of how documentation is affected by this change. If there is no effect on documentation, explain why. Otherwise, state which sections are changed and why.]

  • Updated CHANGELOG
  • Updated README (if applicable)
  • Commented all public classes, properties, and methods
  • Updated user documentation

Technical risk

[Overall product level assessment of risk of change. Need technical risk & halo effect.]

Comments to reviewers

[Info per person for what to focus on, or historical info to understand who have previously reviewed and coverage. Help them get context.]

Package version

[Justification for updating either the patch, minor, or major version according to the semantic versioning rules]

  • Updated package version

@sim-bz sim-bz requested a review from richardk-u3d February 12, 2026 21:04
{
Array.Fill(s_ColliderBuffer, null);
Array.Fill(s_ColliderDistanceBuffer, 0f);
Array.Fill(s_ColliderOrderBuffer, 0);

Choose a reason for hiding this comment

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

FYI i am fixing the analyzer to consider calls to Array.Fill as successful initialization

Copy link
Collaborator

Choose a reason for hiding this comment

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

These don't need to be initialized at all, as they are just scratch buffers. I would have disabled the warning here.

Copy link

@richardk-u3d richardk-u3d left a comment

Choose a reason for hiding this comment

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

some commented out bits im not sure about, but overall looks good

Copy link

@richardk-u3d richardk-u3d left a comment

Choose a reason for hiding this comment

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

need to figure out if having 2 RuntimeInitializeOnLoadMethod's is something we want to allow. the analyzer gets confised by it.

@sim-bz sim-bz marked this pull request as ready for review February 17, 2026 15:51
@sim-bz sim-bz requested a review from glabute as a code owner February 17, 2026 15:51
@u-pr
Copy link
Contributor

u-pr bot commented Feb 17, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

UUM-131015 - Fully compliant

Compliant requirements:

  • Implemented 'ResetStaticsOnLoad' with '[RuntimeInitializeOnLoadMethod]' across the codebase for identified classes (CinemachineCore, CinemachineDebug, CinemachineBlend, etc.).
  • Handled Editor-specific static resets (FreeLookEditor, VirtualCameraEditor).
  • Converted some statics to readonly or instance members where appropriate (CameraState, CinemachineOrbitalTransposer).
  • Handled exceptions for CinemachineCore events as noted in the PR description.
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪

The PR touches many files with a repetitive pattern to handle static resets, requiring verification of initialization logic and potential race conditions across Editor and Runtime assemblies.
🏅 Score: 92

The PR systematically addresses the Fast Enter Play Mode requirements with appropriate resets and architectural changes. A potential race condition in debug settings initialization prevents a perfect score.
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Race Condition

In CinemachineDebug.ResetStaticsOnLoad, GameViewGuidesEnabled is set to false. However, in CinemachineCorePrefs.ResetStaticsOnLoad (Editor), it is set to ShowInGameGuides.Value. Since both methods are decorated with [RuntimeInitializeOnLoadMethod], their execution order is undefined. If CinemachineDebug runs last, it will overwrite the user's preference with false. Consider removing the assignment in CinemachineDebug if the Editor script handles it, or consolidating the logic.

GameViewGuidesEnabled = false;
  • Update review

🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr

@u-pr
Copy link
Contributor

u-pr bot commented Feb 17, 2026

PR Code Suggestions ✨


🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr

@sim-bz sim-bz requested a review from richardk-u3d February 17, 2026 18:02
{
Array.Fill(s_ColliderBuffer, null);
Array.Fill(s_ColliderDistanceBuffer, 0f);
Array.Fill(s_ColliderOrderBuffer, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

These don't need to be initialized at all, as they are just scratch buffers. I would have disabled the warning here.

[RuntimeInitializeOnLoadMethod]
private static void ResetStaticsOnLoad()
{
s_StoryboardGlobalMute = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't want to be resetting this on domain reload. It's value should be taken from CinemachineCorePrefs.StoryboardGlobalMute.Value

[RuntimeInitializeOnLoadMethod]
private static void ResetStaticsOnLoad()
{
Array.Fill(s_Buffer, 0f);
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to fill the buffer with anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I know they are scratch buffers, but it's preferable to zero-out/clear dangling information from scratch buffers than to add an exception for these imho ... @richardk-u3d Do you have any feedback for these use cases?

Choose a reason for hiding this comment

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

If they really do not need clearing, I suppose we are wasting performance/hurting enter playmode time by clearing them. If that's the case, I would suppress the warning instead. (though it's your call - you are the owners/area experts)

If you choose to suppress the warning instead, please just include a comment explaining why it does not need resetting, so it's obvious for future readers.

Comment on lines +231 to +232
Array.Fill(s_HitBuffer, default);
Array.Fill(s_PenetrationIndexBuffer, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to fill these buffers

Choose a reason for hiding this comment

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

As with the other cases of "you dont need to", if you change this to suppress the warning, it would be good to include a comment saying why it does not need resetting.

{
s_AvailableStringBuilders = null;
OnGUIHandlers = null;
GameViewGuidesEnabled = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be initialized to CinemachineCorePrefs.ShowInGameGuides.Value

[RuntimeInitializeOnLoadMethod]
private static void ResetStaticsOnLoad()
{
Array.Fill(s_ColliderBuffer, null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

not needed, unless having stale Collider pointers upsets c# and unity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants