Skip to content

[UUM-137643] Fix compilation errors and warnings#627

Open
mfe wants to merge 12 commits intomainfrom
UUM-137643_fix_coreclr_errors
Open

[UUM-137643] Fix compilation errors and warnings#627
mfe wants to merge 12 commits intomainfrom
UUM-137643_fix_coreclr_errors

Conversation

@mfe
Copy link
Copy Markdown
Collaborator

@mfe mfe commented Mar 24, 2026

Purpose of this PR

Ticket/Jira #: UUM-137643

This PR address 3 issues:

1 - Compilation errors in the console

error CS0619: 'Object.GetInstanceID()' is obsolete: 'GetInstanceID is deprecated. Use GetEntityId instead.

2 - Warnings (that will become errors in a foreseeable futur):

warning CS0618: 'FindObjectsSortMode' is obsolete: 'FindObjectsSortMode has been deprecated. Use the FindObjectsByType overloads that do not take a FindObjectsSortMode parameter.'
⚠️ In previous versions of the code, a sorting by FindObjectsSortMode.instanceID was used to have the determinism needed for UpdateCaptureNodes. But that was an inconsistant way of sorting. Furthermore, with entityID, the small amount of creation-order semantics that were accidentally present in instanceID is removed. That's why this PR instroduces another way of sorting with determinism (cf SortComponentsByStableSceneHierarchy).

3- replace renderPipelineAsset by defaultRenderPipeline

defautRenderPipeline was introduced in 2019 stream so that was due.

A general mindset for this PR is the less we touch, the better.
The reason is that this code is very legacy and in basic support. We want to mitigate the risk of breaking the past versions and increase our support load.
That's why every changes needed were encapsulated in #if UNITY_6000_4_OR_NEWER...#endif even when the changes would be considered a better practice for precedent versions too (like not sorting with instanceIds).

Testing

Functional Testing status:

Performance Testing status:

Overall Product Risks

Complexity:

Halo Effect:

Documentation & UX Writing

User facing text to review Details
User interface
Public API docs
Changelog
Documentation halo effect Jira link
User manual
Other docs

Additional information

Note to reviewers:

Reminder:

  • Add entry in CHANGELOG.md
  • check defaultRenderPipeline availability - Was introduced as early as 2019.4 so before our minimal supported version (21.3)
  • Wait for Recorder 5.1.6 to be released (see UUM-137641 - Cf Recorder tests
  • Sanity check QA - test import + export both for local and streamed assets with depth

@mfe mfe changed the title Upgrade editor versions in CI [UUM-137643] Fix compilation errors and warnings Mar 24, 2026
@mfe mfe marked this pull request as ready for review March 24, 2026 16:06
@mfe mfe requested review from a team as code owners March 24, 2026 16:06
@mfe mfe force-pushed the UUM-137643_fix_coreclr_errors branch from b8c4202 to 52abb9f Compare April 3, 2026 14:02
@@ -1,24 +1,24 @@
test_editors:
- version: 2021.3
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.

shouldn't we also remove this and upgrade the minimum unity version to 6000.0?

Same with romotion_test_editors

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's the minimum version of the package, so we have to keep the job for promotion.

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.

I believe its allow to bump the minimum version of the package if said version is not supported anymore without being considered a new major release. But if that would increase the scope of this PR, we can do it separately

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I would say it's indeed out of scope, so let's log a task to update this separately.

Copy link
Copy Markdown
Contributor

@LeoUnity LeoUnity left a comment

Choose a reason for hiding this comment

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

Changes looks good to me, we do have a test failure on win trunk unfortunately.

@mfe mfe force-pushed the UUM-137643_fix_coreclr_errors branch from 626a370 to 12f0896 Compare April 7, 2026 14:54
}
#if UNITY_2023_1_OR_NEWER
#if UNITY_6000_4_OR_NEWER
return Object.FindObjectsByType<T>();
Copy link
Copy Markdown
Collaborator Author

@mfe mfe Apr 7, 2026

Choose a reason for hiding this comment

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

The FindObjectsSortMode.InstanceID used in UNITY_2023_1_OR_NEWER code path is not needed as the result of GetTargets is only used with Any(), so I just removed the sorting mode here.

I was tempted to remove it in UNITY_2023_1_OR_NEWER code path too but on a very legacy package in basic support, the less we touch, the better.
Feel free to push back.

{
m_time = 0.0f;
#if UNITY_6000_4_OR_NEWER
m_context = new SafeContext(aiContext.Create(AllocateNativeContextUid()));
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The native function called at the end of the line is aiContextCreate(int uid). So if we keep using a ulong here, we ultimately have to cast it, which can lead to some narrowing and rare but potential collisions.
But in the code where the id is used, there is no need for a correlation between the id and the abcTreeRoot object, we just need an id to destroy on dispose (cf aiContextDestroy(aiContext* ctx)).

Thus the introduction of an alternative surrogate id.

A question for reviewers: what is the bigger risk ?
1- Changing this code
2- Narrowing and collision
😅

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.

I think this approach you took is great!


#endif

#if UNITY_6000_4_OR_NEWER
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Explaination about why we need this:
⚠️ In previous versions of the code, a sorting by FindObjectsSortMode.instanceID was used to have the determinism needed for UpdateCaptureNodes. But that was an inconsistant way of sorting. Furthermore, with entityID, the small amount of creation-order semantics that was accidentally present in instanceID is removed. That's why this PR instroduces another way of sorting with determinism,

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.

A concern that jumped out to me is performance.
When and how often is this sorting taking place? We are doing a lot more computations including string operations to get this determinism.

Also out of curiosity why is determinism important here? What would it mean not having determinism?

Copy link
Copy Markdown
Collaborator Author

@mfe mfe Apr 14, 2026

Choose a reason for hiding this comment

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

Good questions :D

Put on your seat belt 😄

Some context

GetTargets (where this func is used) is the scene discovery mechanism. Its results feed ConstructTree, which inserts nodes into m_nodes aka builds the in-memory capture tree and ultimately determines the order in which Alembic nodes (NewXform, NewPolyMesh, etc.) are created inside the archive.

GetTargets is called at every capture frame during recording.

Why we want determinism

The tree topology is naturaly done and deterministic for parents/children because of the recursiveness used (aka we always resolves parents before children).

But what is not naturally stable is the sibling ordering, aka the order in which NewXform/NewPolyMesh is called on the children of a given parent, which determines the order those children appear in the Alembic file. If no sorting is done, sibling order will not be stable and produce .abc files that bit-wise/ascii-wise looks different when they technically are not (noise during versioning, unnessary cache invalidation...).

BTW the sorting by InstanceID was actually not great either, because from a Unity session to another, the instanceID could change and so the ordering of the sibblings.

The new sorting is based on the GO scene path and root-to-leaf sibling indices (that order is serialized into the scene file and restored identically every time the scene loads), this is now a structural and session-independent sorting.

Perf concern

At every captured frame, we unconditionally calls UpdateCaptureNodes, which calls GetTargets once per enabled capturer type (up to 4: Transform, Camera, MeshRenderer, SkinnedMeshRenderer) = SortComponentsByStableSceneHierarchy runs up to 4× per frame for the entire duration of recording 😅

So, ya, not great, the new sorting is probably worse than native InstanceID sorting.
That said there is room for improv, let me try.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Well, I tried for few hours but the improvements I could get (without breaking everything) are almost anecdoctical and there is still this idea of minimalizing impact / halo in the changes we do in this package.

To mitigate, this is only run when we record. So I would stop there.
Feel free to push back if you feel I should persevere in trying to improve the perf.

How about that @LeoUnity ?

@mfe mfe requested review from LeoUnity and thomas-tu April 10, 2026 13:52
// Theoretical int overflow after ~2 billion AbcLoad calls is impossible in practice.
static int s_nextNativeContextUid;

static int AllocateNativeContextUid() => Interlocked.Increment(ref s_nextNativeContextUid);
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.

Should/could this be uint? we are leaving half of its range on the table

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm using the type of the native function that this id is for (aka aiContextCreate(int uid))

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.

2 participants