Search code examples
pythonpython-3.xgame-engineursina

Delete every entity that was spawned | Python ursina


How do I delete every Entity that was spawned?

For example:


Entity1 = Entity(...)
Entity2 = Entity(...)
Entity3 = Entity(...)

destroy(scene.entities) # Just an example

How do I delete all those with one or multiple lines of code without appending to a list?

Trying to delete every entity that was intialized


Solution

  • Use

    scene.clear()
    

    or

    [destroy(e) for e in scene.entities]
    

    Using a list comprehension can be easier than using a for loop, since it won't mess up the list while you're iterating.