libgdx / libgdx/ashley

What is the proper way of checking if the entity is already removed?

Open
#245 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Java
Stars
930
Forks
147
PR merge metrics
No merged PRs in 30d

Description

EntityListener handles when the entity is added or removed. My problem is when I remove the entity from the engine, while this entity is being used as Component owner, it cause a java.lang.NullPointerException. I wonder what method to use to check if entity is already removed from the engine.

For example:

public class PoliceComponent implements Component {
    public Entity criminal;
}

engine.removeEntity(entity)

PoliceComponent police ...
Vector2 criminalPos = Mapper.transform.get(police.criminal).position; 
// Now this line will cause an error

Question : is there a method like this to check for entity existence? or something better safer to remove entity while is in use.

    if (engine.hasEntity(entity)) {
          // exists
    }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading EntityListener and the engine.removeEntity call, then trace the Mapper.transform.get(police.criminal) access shown in the example. Determine the supported entity lifecycle and safe handling for components that retain removed entities; done means the behavior and recommended approach are documented or covered by a focused regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.