Warning from actors

I encountered a very strange problem. I defined a class that loads actors, but when I use it in another file, I get the “actor warning”. What is the reason?


The following is my code and calling process!

----------------------------------actor----------------------------------------------------------------
from panda3d.core import *
from direct.actor.Actor import Actor
class ActorObject(Actor):
    def __init__(self, max_health, max_speed):
        super().__init__(self)
        self.max_health = max_health
        self.health = max_health
        self.max_speed = max_speed
        self.walking = False
        self.velocity = Vec3(0, 0, 0)
        self.NeAcc = 500
    def show_actor(self, pos, modelName, modelAnims, modelScale, colliderName):
        self.actor = Actor(modelName, modelAnims)
        self.actor.reparentTo(render)
        self.actor.setPos(pos)
        self.actor.setScale(modelScale)
        capsule = CollisionSphere(0, 0, 0, 5)
        collider_node = CollisionNode(colliderName)
        collider_node.addSolid(capsule)
        self.collider = self.actor.attachNewNode(collider_node)
-----------------------------------------------------------------------------------------------------------------
from direct.showbase.ShowBase import ShowBase
from actor import ActorObject
ShowBase()
ppp = ActorObject(10,40)        
ppp.show_actor((0,0,0), "woodmen",
                                {"walk": "woodmen_walk",
                               "stand": "woodmen_stand",
                               "die": "woodmen_die",
                               "attack": "woodmen_attack"},  1, "wood")
base.run()

What should have caused this?

Ah, the problem, I believe, is that while your class constructs and stores an Actor–which is likely fine–it also sub-classes Actor, meaning that it is itself an Actor, too. This is technically fine–but when your class constructs itself, and in particular when it constructs its super-class (i.e. Actor), it doesn’t pass in a valid model as Actor expects.

Specifically, your call to “super().__init__(self)” is more or less the same as constructing an Actor like this: myActor = Actor(). Since no valid model is passed in, you get a warning to inform you of that potential issue.

2 Likes

Ok, I understand, thank you very much for your answers, I have solved this problem!

1 Like

It’s true that no valid model is passed in, but I’d like to give my own interpretation of what I think is going on, if you don’t mind :wink: .

Actually, it’s more like writing myActor = Actor(self). When using super() to call a base class method, self is not required as the first argument to be passed into it. But since it is passed into super().__init__ in the given code, it is treated as the models argument of Actor.__init__, and that’s what really causes the warning.
Also, creating an Actor without specifying a model does not seem to lead to a warning or error (probably because models and animations can be loaded afterwards using load_model and load_anims).

Anyway, I hope you’re not annoyed by my meddling in this topic :stuck_out_tongue: .

1 Like

Not at all! You clarified the matter, and that’s a welcome thing, for my part. :slight_smile:

In any case, I own no claim on this thread! It’s public, open for people to comment on. :slight_smile:

Ah, that’s interesting–I didn’t know that “self” was superfluous when using “super”–I don’t usually employ that approach myself, generally preferring “<superclass>.__init__(self …)”. So, yes, as you say, it would seem that the super-constructor was presumably attempting to construct an Actor using the instance-reference as its “model”. :slight_smile:

2 Likes

Great, your explanation made me thoroughly understand the cause of this problem, it seems that I really need to study further. Thank you so much!

2 Likes