ArgumentException: The Object you want to instantiate is null.

I am baking link to monobehaviour prefab in this component:

public class Phantom : IComponentData
{
    public VRIKSource VRIKSourcePrefab;
}

public class VRIKSource : MonoBehaviour {....}

This is authoring class:

public class PhantomAuthoring : MonoBehaviour
{
    public VRIKSource VRIKSource;

    class Baker : Baker<PhantomAuthoring>
    {
        public override void Bake(PhantomAuthoring authoring)
        {
            AddComponentObject(new Phantom() {VRIKSourcePrefab = authoring.VRIKSource});

            AddBuffer<PhantomCommandData>();
            var buffer = AddBuffer<PhantomBone>();
            buffer.Length = authoring.VRIKSource.Bones.Length;
        }
    }
}

Everything works ok in editor, but when i build dedicated server build I get ArgumentException: The Object you want to instantiate is null. On this line of code:

foreach (var (phantom, phantomEntity) in SystemAPI.Query<Phantom>().WithNone<VRIKSolver>().WithEntityAccess())
{
    var vrikSource = Object.Instantiate(phantom.VRIKSourcePrefab);
    ...
}

Where is my prefab in build?

We recently found a similar bug in the baking process, where some of the referenced values on MonoBehaviours would be stripped away during the baking process in a build. It sounds like the same issue, and it is on our radar to fix. I can’t give you an ETA unfortunately.

1 Like