Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to delete Entity #18

Open
cchandel opened this issue Mar 27, 2023 · 1 comment
Open

Unable to delete Entity #18

cchandel opened this issue Mar 27, 2023 · 1 comment

Comments

@cchandel
Copy link

Hi,
I'm creatng an entity in an asyncworld as below.

e = Gaw.NewEntity()
e.Add(p, m, t, r, pr, h, i, d, r)
Entities[id] = e

then deleting the entity by

Entities[id].Destroy()

After Destroying, the entity remains available when doing :-

iterT := ecs.GetComponentAll[components.T](m)
for iter := iterT; !iter.End(); iter.Next() {
  ecs.Log.Info(t.id)
}

Please help.

@zllangct
Copy link
Owner

Now it's running correctly. This bug was caused by incorrect deletion order in the API.

func (e *EntityInfo) Destroy(world IWorld) {
	for i := 0; i < len(e.compound); i++ {
		world.deleteComponentByIntType(e.entity, e.compound[i])
	}
	// must be last
	world.deleteEntity(e.entity)
}

Adjust API to no longer export EntityInfo, All operations should be obtained through SyncWrapper.

world.Sync(func(gaw SyncWrapper) error {
	u, ok := GetUtility[__world_Test_U_Input](gaw)
	if !ok {
		return errors.New("utility not found")
	}
	gaw.DestroyEntity(entities[1])
	return nil
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants