Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

NullReferenceException when adding component

Open zhaige95 opened this issue 1 year ago • 1 comments

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 avatar Jul 23 '22 15:07 zhaige95

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

zhaige95 avatar Jul 23 '22 15:07 zhaige95

Yes 👍 always use context.CreateEntity()

sschmid avatar Aug 25 '22 21:08 sschmid