Actor issue

import direct.directbase.DirectStart
from direct.actor.Actor import Actor


class Game():
    def __init__(self):
        butterfly = Actor({'bumbum': 'resource/MyApache.egg'}, 
                  {'bumbum' : {'fly':'resource/ApacheAnimation.egg'}}
                )
        butterfly.setPos(0, 10, 0)
        butterfly.setScale(0.15, 0.15, 0.15)
        butterfly.setTwoSided(True)
        butterfly.loop('fly')
        butterfly.reparentTo(render)
        
g = Game()

run()

butterfly doesn’t “fly”

when I put self.butterfly instead of butterfly, it works @@

If I want to keep Game class and do not use “self” keyword , what should I do?

You must keep a reference to an Actor, or else it will self destruct and become static geometry.
Once your init function finishes, “butterfly” goes out of scope and there is no longer a reference.
The easiest way to do this is set it as an attribute of your class (use “self”).

Is there a reason why you would not want to keep a reference to the Actor?

If it is just for background decoration or something like that, you might want to keep a list of Actors, for example:

class Game():
    def __init__(self):
        self.actors = []
        butterfly = Actor({'bumbum': 'resource/MyApache.egg'},
                  {'bumbum' : {'fly':'resource/ApacheAnimation.egg'}}
                )
        butterfly.setPos(0, 10, 0)
        butterfly.setScale(0.15, 0.15, 0.15)
        butterfly.setTwoSided(True)
        butterfly.loop('fly')
        butterfly.reparentTo(render)
        self.actors.append(butterfly)

Thank you ^^ It is good answer for me.