sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.03k stars 1.11k forks source link

NullReferenceException when adding component #1003

Closed zhaige95 closed 1 year ago

zhaige95 commented 2 years ago

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,

zhaige95 commented 2 years ago

sorry, I used the wrong code, it should be GameEntity e = Contexts.sharedInstance.game.CreateEntity(); to create an entity

sschmid commented 1 year ago

Yes 👍 always use context.CreateEntity()