Skip to content

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

@ronjunevaldoz

Description

@ronjunevaldoz

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
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions