Skip to content

Instantly share code, notes, and snippets.

@thelebaron
Last active February 9, 2024 21:52
Show Gist options
  • Select an option

  • Save thelebaron/96a749355408c86eef2954433aa817ca to your computer and use it in GitHub Desktop.

Select an option

Save thelebaron/96a749355408c86eef2954433aa817ca to your computer and use it in GitHub Desktop.
Unity Entities Gotchas!

is a gist the right place where I store dumb tips that future self will forget?

Baking

1. Prefabs from code - Add the Prefab component to it!

If you are creating an entity Prefab, remember to actually add its Prefab component to it, when you assign it to its' Component. This is done automatically if you simply use GetEntity(authoring.GameObject) but you are responsible for it when doing things manually(duh).

2. If you created a Prefab from Code, remember to remove it from the LinkedEntityGroup inside of a baking system(UpdateInGroup PostBakingSystemGroup).

Why future Chris? Because by default any entity created via CreateAdditionalEntity is auto added to a LinkedEntityGroup(if one exists). Subsequently the original entity, if instantiated will also have all entities inside its buffer instantiated(Prefab entity included), and their Prefab component will be removed. In my situation removing the Prefab allowed the LifeTime to tick down, and the entity was destroyed and invalid by the time it came to instantiating the prefab. The errors only complain of an invalid entity(naturally), but the root cause was difficult to track down.

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