Hey,
my goal is to create a blueprint entity for building during baking - a version of the original prefab but MeshFilter and MeshRenderer components only. It seems odd to me that I cant create a dynamic GameObject to be baked in a baker (CreateAdditionalGameObject) or clone a baked Entity (CreateAdditionalEntity(Entity source, …)).
One approach that works is to clone the prefab via Object.Instantiate and call GetEntity on that but that creates a dangling GameObject.
My next thought was a baking system but they can’t create new entities either. I could create an empty Entity during baking, then modify that in a baking system - that seems very convoluted…
The only solution I do see is either create a persistent GameObject stored somewhere, which is not optimal - I always want an up-to-date version of the original prefab OR CreateAdditionalEntity and add all the graphics components myself… because the RenderMeshUtility.AddComponents wants a World which I don’t have access to during baking.
There must be something I’m missing.
There’s a lot of things missing in Entities Graphics. You probably want to asmref to get access to the MeshRendererBakingUtility.
And since this is a gap that I have filled in my framework, I may as well share it for inspiration: https://github.com/Dreaming381/Latios-Framework/blob/master/Kinemation/Authoring/OverrideMeshRendererBaker.cs
Hmm, thank you
I tried again this morning and got it working:
var prefabEntity = GetEntity(placable.Prefab, TransformUsageFlags.None);
var blueprintEntity = CreateAdditionalEntity(TransformUsageFlags.Dynamic, entityName: placable.name);
var meshFilter = placable.Prefab.GetComponent<MeshFilter>();
var meshRenderer = placable.Prefab.GetComponent<MeshRenderer>();
if (meshFilter != null && meshRenderer != null)
{
var mesh = meshFilter.sharedMesh;
var material = meshRenderer.sharedMaterial;
AddComponent<WorldRenderBounds>(blueprintEntity);
AddSharedComponent(blueprintEntity, RenderFilterSettings.Default);
AddComponent<MaterialMeshInfo>(blueprintEntity);
AddComponent<WorldToLocal_Tag>(blueprintEntity);
AddComponent(blueprintEntity, new RenderBounds { Value = meshRenderer.bounds.ToAABB() });
AddComponent<PerInstanceCullingTag>(blueprintEntity);
AddSharedComponentManaged(blueprintEntity, new RenderMesh { materials = new() { material }, mesh = mesh });
}
placeablePrefabs.Add(new PlaceablePrefab
{
Id = placable.UniqueId,
PrefabEntity = prefabEntity,
BlueprintEntity = blueprintEntity,
PlacementMode = placable.PlacementMode
});
And that made me realize that I actually want explicit control of how the blueprint looks - which children are active etc. So instead of doing more complicated automation I’ll just create explicit blueprint prefabs and bake these.