I get the "EntityHeader could not be loaded" or something error a lot.
Subscene contains 1 Gameobject with nothing on it except this baker; and 5 gameobjects referenced in it. (also breaks with 3)
This is the baker.
Why?
using System;
using Unity.Entities;
using UnityEngine;
namespace Jovian.Authoring
{
public class ShipRegistryAuthoring : MonoBehaviour
{
public GameObject[] ships;
}
public class ShipRegistryBaker : Baker<ShipRegistryAuthoring>
{
public override void Bake(ShipRegistryAuthoring authoring)
{
var self = GetEntity(authoring, TransformUsageFlags.None);
var buffer = AddBuffer<ShipPrefabRegistryElement>(self);
foreach (var ship in authoring.ships)
{
RegisterPrefabForBaking(ship); //breakage happens with or without this, nobody could explain me why this is or isn't needed
var prefab = GetEntity(ship, TransformUsageFlags.None);
buffer.Add(new ShipPrefabRegistryElement {prefab = prefab});
}
}
}
[Serializable]
public struct ShipPrefabRegistryElement : IBufferElementData
{
public Entity prefab;
}
}
The entities in the gameobject array are fairly simple:
using JetBrains.Annotations;
using Jovian.Components;
using Jovian.ECS.Systems;
using Jovian.Systems;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
namespace Jovian.Authoring
{
[SelectionBase]
[DisallowMultipleComponent]
public class ShipAuthoring : MonoBehaviour
{
public float outlineWidth = 1;
public VesselClass vesselClass;
[Header("Engine Config")]
public Propulsion propulsion;
}
[UsedImplicitly]
internal class ShipAuthoringBaker : Baker<ShipAuthoring>
{
public override void Bake(ShipAuthoring authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
// Gameplay Logic
AddComponent(entity, new Vessel {vesselClass = authoring.vesselClass});
AddComponent(entity, authoring.propulsion);
AddComponent<ShipControls>(entity);
AddComponent<PIDControl>(entity);
// Floating Origin
AddComponent<Position>(entity);
AddComponent<Origin>(entity);
AddComponent<CameraOffset>(entity);
AddComponent<ScreenPosition>(entity);
// Bootstraps
AddComponent(entity, new NameBootstrap {name = GetName()});
AddComponent<TagColliderBootstrap>(entity);
// Shader properties
AddComponent(entity, new OutlineWidth {value = authoring.outlineWidth});
AddComponent(entity, new OutlineColor {value = new float4(0, 0, 0, 1)});
AddComponent(entity, new FactionColor {value = new float4(.5f, .5f, .5f, .1f)});
}
}
}