#Object is Class_Name not working as expected

5 messages · Page 1 of 1 (latest)

azure relic
#

EDIT: Solved. I was using a StaticBody2D, so my get_overlapping_bodies() wasn't even triggering. I had a false-positive because the area checking for overlap was a child of an object with a CharacterBody2D. Changing my StaticBody2D to CharacterBody2D fixed my issue.

Pretty much the title.

I am instantiating Dice (with class_name Die) into a scene as children of a DiceManager node in the Main scene.

I have a DiceSlot scene that checks for overlapping bodies.. to see if it's a Die or not.

I use area.get_overlapping_bodies() ->

  if overlap is Die:
    do the thing```

However, using print, it looks like it's registering as a PhysicsBody2D or something.

**What am I missing?**
fathom hatch
#

The is operator should work with custom classes but depending what function you use for printing it may not be able to retrieve custom classes and only retrieves built-ins

last elbow
#

I used to run into this sometimes, is it perhaps that it's the parent of the physicsbody which is the custom class?

placid marsh
#

Is the Die the physics body itself?

azure relic
#

The Die was the body, but I realized I made a mistake. The Die was a StaticBody2D. After changing it to a CharacterBody2D, everything worked as expected. The get_overlapping_bodies() didn't account for StaticBody2D, I assume.

Thanks for your help, everyone 😅🙂