In my game, I have a custom “character” class that contains all sorts of game-specific info (status, hit pts, speed, name, etc).
The character object has a property , “model”, which is actually a reference to an Actor model for the character.
When picking characters to move (basic RTS type setup) I have std picker code which finds the picked object (in this case the Actor model). Is there an easy way to get to the character object that is the “parent” of this model?
Right now, I do it by keeping a list of all characters and a python tag on the model with the character name. When the model is clicked, I call a function which checks for the name in the list and returns a reference to the character object.
It works fine, but just wondering if there’s a better /easier way.
EDIT: After reading a second time I guess now I got what you’re after. You have a class and store an actor as an instance attribute. In this case the most simple thing to do is comparing the stored actor and the return value of certain functions.
EDIT2: Or store the instance in an attribute of the actor. Not sure if this works, but it should.
# Store the abstract "parent object" as actor attrribute
self.actor = Actor("whatever")
self.actor.abstract = self
# Get the abstract instance that has this actor as attribute
self.abstract = return_value.abstract
# Now self.abstract.actor should be the same as the return_value
BTW, i wouldn’t speak of a “parent” here. People easily get it confused with the scene graph.