When try to bake into entity prefab for example: AddComponent(entity, new EntitySpawner { prefab = GetEntity(authoring.gameObject, TransformUsageFlags.Renderable) }), it will still get LocalTransform at the entity prefab but if bake as regular entity LocalTransform will not exist and only have LocalToWorld. Is that expected behavior or bug?
#TransformUsageFlags.Renderable not working properly when bake as entity prefab
1 messages · Page 1 of 1 (latest)
I asked internally & got this answer:
This is the expected behaviour. Prefabs are baked as Dynamic internally, so they can be placed easily through the LocalTransform of the root.
If a prefab were marked only as Renderable, its hierarchy could be collapsed into world space, making the placing of all the elements painful to deal with at instantiation time.
Does that help?
Thanks for the answer but still I would like to bake entity prefab without LocalTransform that able to instantiate entity without LocalTransform for better performance. I have the use case to dynamically spawn static entity that will never move. For placed easily through the LocalTransform of the root, do u mean make it easy to instantiate parent entity that child entity?
The developer of this feature will work on getting a Discord account to answer directly, but in the meantime:
If your prefab contains a hierarchy, Dynamic preserves that hierarchy. In this case you can position all your entities by just moving the root entity of the hierarchy.
If the prefab were just Renderable, all the hierarchy could be flatten into world space and you would need to position individually each of the entities in your prefab (by traversing the LinkedEntityGroup).
Currently there are 2 ways to do what you want, although none of them is straightforward:
Use TransformUsageFlags.ManualOverride, so you disable all the baking of transform components. In this case you will need to create a custom baker for your prefab to add manually the transform components that you need. This could work if you only have a single entity in your hierarchy, but it will be too complicated if you got more than one entity in your hierarchy.
Create a baking system in the PostBakingSystemGroup to remove the components that you don't want in your prefabs. You will need to mark with a tag the prefabs that you want to strip down (this tag can use the attribute [BakingType]). In that baking system you will need to traverse the LinkedEntityGroup, to make sure that all the entities in the prefab hierarchy are stripped down.