Entitas
Entitas copied to clipboard
NullReferenceException when adding component
Hi,
I can't add any componet,
Unity error info:
NullReferenceException: Object reference not set to an instance of an object
GameEntity.set_isLocal (System.Boolean value) (at Assets/Scripts/ECS/Generated/Game/Components/GameLocalComponent.cs:16)
ActorFectory.CreateActor (EActorFlag flag, UnityEngine.Vector2 pos, System.Boolean local) (at Assets/Scripts/Core/ActorFectory/ActorFectory.cs:31)
GameController.Start () (at Assets/Scripts/GameController.cs:26)
My code:
public static void CreateActor(EActorFlag flag, Vector2 pos, bool local = false)
{
GameEntity actor = new GameEntity();
actor.isLocal = local;
}
Entitas environment, ok Code generation use jenny, work well,
sorry, I used the wrong code, it should be
GameEntity e = Contexts.sharedInstance.game.CreateEntity();
to create an entity
Yes 👍 always use context.CreateEntity()