Weird error when detaching nodes

Hello, I’ve been working on a game project for my class and I’m supposed to detach an object’s node when it collides with a missile, however, I’m getting an error when Destroy Object is getting called and I’m not sure what is causing it. The error is: _error_type != et_not_found at line 668 of panda/src/pgraph/nodepath.cxx

The code for where the error occurs is:

def HandleInto(self, entry):

    fromNode = entry.getFromNodePath().getName()
    print("fromNode: " + fromNode)

    intoNode = entry.getIntoNodePath().getName()
    print("intoNode: " + intoNode)

    intoPosition = Vec3(entry.getSurfacePoint(self.render))
    tempVar = fromNode.split('_')

    print("tempVar: " + str(tempVar))
    shooter = tempVar[0]
    print("Shooter: " + str(shooter))
    tempVar = intoNode.split('-')
    print("tempVar1: " + str(tempVar))
    tempVar = intoNode.split('_')
    print('tempVar2: ' + str(tempVar))
    victim = tempVar[0]
    print("Victim: " + str(victim))

    strippedString = re.sub(r'[0-9]', '', victim)
   


    if 'Drone' in strippedString or 'Planet' in strippedString or 'SpaceStation' in strippedString:
        print(victim, ' hit at ', intoPosition)
        self.DestroyObject(victim, intoPosition)
        
        
        
    if shooter in Missile.Intervals:
        Missile.Intervals[shooter].finish()

    elif shooter in LargeMissile.AltIntervals:
        print(victim, " hit at", intoPosition)
        self.AltDestroyObject(victim, intoPosition)

    
    print(shooter + ' is done.')
    


def DestroyObject(self, hitID, hitPosition):
    nodeID = self.render.find(hitID)
    nodeID.detachNode()
    
    self.setParticles()

    self.explodeNode.setPos(hitPosition)
    self.Explode()

I also have my github for the project public if the full code is needed to be seen:

First of all, greetings, and welcome to the forum! I hope that you find your time here to be positive! :slight_smile:

As to your question…

Well, the error essentially means that your call to “find”, just before the call to “detachNode”, didn’t find what you were looking for.

Looking over your code, what output are you seeing when you print out “victim”? (As I see that you’re doing just before calling “DestroyObject”.)

Presuming that “victim” contains a string that identifies the relevant node, the issue may simply be that your call to “find” will, I think, only examine the immediate children of the “render”-node itself. In order to search below that, you might prepend “**/” to the parameter that you pass to “find”.

Something like this:
nodePath = self.render.find("**/" + hitID)

If the node’s actual name is longer than just the contents of “hitID”/“victim”, then you may want to either add the remainder, or add a single “*” after the contents “hitID”/“victim”. (The “*” is simply a wild-card, and so just indicates that there’s something unspecified after the name that you’ve provided.)

So, something like this, if called for:
nodePath = self.render.find("**/" + hitID + "*")

(As per this manual page, “**/” in find("**/some-node-name") essentially means "look at this node, and any nodes below it.

More specifically, “**” means “any sequence of one or more nodes”–i.e. “not just a child of this node, but a child of this node and any number of nodes below it”.

As to “/”, “/”-characters are used to separate one node from the next in such sequences, so the one in “**/” just separates the sequence of nodes in the “**” section from the node that you’re looking for.)

2 Likes

Thank you for the advice, I’ll keep it in mind for future projects! I added what you suggested and it worked

1 Like

Glad I’m not the only one seeing this error in this class lol!
Fixed my error as well

1 Like