Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asserts/crashes caused by missing component serialized identifiers. #16973

Conversation

mbalfour-amzn
Copy link
Contributor

What does this PR do?

Fixes #16807 .

PR #15985 previously fixed some of the issues related to disabled/pending components and how they work relative to component aliases, but there was still a case where loading a prefab containing a disabled or pending component after an Editor restart would assert and crash.

The reason for this is that while editing, the component would get added to the component, then get its SerializedIdentifier set, then get added to the PendingComponent map. If it meets all of its requirements, it then gets removed from the list and added to the entity. If not, it stays in the pending map.

However, when serializing out the component, the SerializedIdentifier doesn't directly get serialized out with the component. It gets serialized as the key for the PendingComponent map, but it wasn't getting added back as a SerializedIdentifier. Consequently, when the entity gets activated and tries to add components from the PendingComponent list, it fails to successfully look it up in the IsComponentPending() call due to the missing SerializedIdentifier, which ultimately leads to asserts and crashes.

(All of the above also applies to disabled components)

The fix is to set the SerializedIdentifier at the point of deserialization, so that when the component is instantiated in the PendingComponent map, it gets a SerializedIdentifier that matches the key to the map, which ensures that it can be found.

NOTE: If the prefab is hand-edited and the serialized identifier is modified to something that clashes with other components on the entity, chaos may ensue, since the assumption is that the read-in identifier is correct and unique.

How was this PR tested?

Added pending and disabled components to an entity and saved the level. Closed the Editor. Restarted the Editor. Loaded the level and verified that the components could be deleted, re-added, enabled, disabled, without any asserts or crashes.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
@mbalfour-amzn mbalfour-amzn requested review from a team as code owners October 26, 2023 22:04
@mbalfour-amzn mbalfour-amzn merged commit 9f8753c into o3de:point-release/23101 Oct 30, 2023
3 checks passed
@mbalfour-amzn mbalfour-amzn deleted the mbalfour/disabled_component_fix branch October 30, 2023 18:58
AMZN-alexpete pushed a commit to aws-lumberyard-dev/o3de that referenced this pull request Dec 14, 2023
…s. (o3de#16973)

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants