When to update manually created handles

I’m often asking myself when it’s necessary to call handle.Update (ComponentTypeHandle, ComponentLookup, EntityInfoStargeLookup…) when we do not use SystemAPI.

Suppose you want to use them multiple times in the same system update with structural changes in-between.

  • Should they be updated once at the beginning of the update?
  • Or each time there is a structural change.

In the editor, you need to update the handle if any structural changes occurred since the last time you updated the handle. The per-component type safety handles get invalidated upon a structural change, and the lookup needs a new, valid one.

Builds don’t require updating more than once per update. AtomicSafetyHandle-based safety management is an editor concept, and all that’s left to do without that is get a value for the global system version which increments before the system update.

You need to comply with the editor-specific requirements by updating between a structural change and usage of the handle / lookup. However, if you would rather not include the later updates in builds (note that updates are pretty minimal without the safety handle update, as it just amounts to getting a system version value or, in the case of EntityStorageInfoLookup, nothing at all), you could make the subsequent calls to update conditional on ENABLE_UNITY_COLLECTIONS_CHECKS to make them editor-only.

1 Like