1

I have an animator object in ursina. I want to destroy it.

from ursina import *
app = Ursina()
walka = Animation("assets/zombies/zombie1/walk/",fps = 5,loop=True)
animator1 =  Animator(animations= {"walk":walka})
animator1.state = "walk"
destroy(animator1)
app.run()

This doesn't seem to work and throws this error: AttributeError: 'Animator' object has no attribute 'eternal'

Yuvan
  • 11
  • 3
  • I'm not sure where the error comes from (could be an oversight in Ursina) but you could try to manually set `animator1.eternal = False` – Jan Wilamowski Oct 05 '21 at 04:50
  • @JanWilamowski after adding this , it gives me this error ```AttributeError: 'Animator' object has no attribute 'children'``` – Yuvan Oct 05 '21 at 04:57
  • Adding `animator1.children = []` should do the trick. The issue seems to be that the `destroy()` code assumes the existence of several attributes: https://github.com/pokepetter/ursina/blob/18b8d6e3f4df3c0c4b3cdfcf8616510706fbd7d3/ursina/ursinastuff.py#L55 – Jan Wilamowski Oct 05 '21 at 04:58
  • It might be worth raising an issue at https://github.com/pokepetter/ursina/issues – Jan Wilamowski Oct 05 '21 at 04:59
  • @JanWilamowski it is giving this error now : ```AttributeError: 'str' object has no attribute 'finish'``` But I will raise an issue on github. Thank you – Yuvan Oct 05 '21 at 05:24
  • yeah, it looks like the `destroy()` function isn't compatible with animations yet. You could implement your own version, based on the one I linked. – Jan Wilamowski Oct 05 '21 at 05:27
  • @JanWilamowski i can't understand how he destroys it, can you tell me to what should I edit the destroy function – Yuvan Oct 05 '21 at 05:37
  • The last error you got occurs because `_destroy()` iterators over the keys of `entity.animations` rather than its values, presumably because it used to be a list at some point. You can iterate yourself and call `.finish()` and `.kill()` on all your animations. – Jan Wilamowski Oct 05 '21 at 05:42
  • @JanWilamowski is there a way to add an animation as an texture to an entity??? So that i can delete that entity – Yuvan Oct 05 '21 at 05:43
  • Have a look at this question: https://stackoverflow.com/questions/65060290/custom-animation-in-ursina-engine and this answer: https://stackoverflow.com/questions/68130756/show-image-on-screen-with-ursina/68147680#68147680 – Jan Wilamowski Oct 05 '21 at 05:49
  • @JanWilamowski i can't just add parent=camera.ui, because my game wouldn't run accordingly – Yuvan Oct 05 '21 at 05:51
  • That might not be necessary. Why do you want to destroy the object before running the app anyway? – Jan Wilamowski Oct 05 '21 at 05:55

1 Answers1

0

Do this:

from ursina import *

app = Ursina()
walka = Animation("assets/zombies/zombie1/walk/", fps=5, loop=True)
animator1 = Animator(animations={"walk": walka})
animator1.state = "walk"
walka.disable() # disables the animation.

app.run()
Tanay
  • 561
  • 1
  • 3
  • 16