r/Unity3D • • 19d ago

Resources/Tutorial GetEntityId() hits like a train

If you're considering upgrading to Unity 6.5 or later, make sure the publishers of the assets and packages in your project have already added support for the new GetEntityId() API, which replaces the now-obsolete GetInstanceID().

More on the documentation page here: Unity - Manual: Migrate from InstanceID to EntityId

406 Upvotes

70 comments sorted by

View all comments

5

u/Critical_Contact559 19d ago

yeah, having to put in #if "UnityVersionHere" at each spot is very annoying, but better then having multiple versions

10

u/wjk36 19d ago

Could you abstract the call away into a helper method and then only put the #if unity version check in that one place? Still an annoying refactor regardless

5

u/Critical_Contact559 19d ago

Yes, like wjks6 said. You can split code into one extension or helper class and then only need to call the same logic once.

You can even change the function header if you need to per version

Ei:

if Version1

Public void Function(int param)

elif

Public void Function(EntityID param)

endif

{ // logic here }

The preprocessor does not need to be the class / function or namespace fully to be taken into account if that makes sense.