0 votes

get_slide_collision will return a KinematicCollision2D which contain a colliding body. How can I check if this colliding body is a instance of a scene and the scene's parent scene?

in Engine by (75 points)



or something like this

2 Answers

0 votes
Best answer
for i in range(get_slide_count()):
    var collision = get_slide_collision(i)
    var collider = collision.collider
    if collider is MyScene:
        pass # code here
by (4,209 points)
selected by

Thanks for your answer, I tried using is, but get error: Right operand of 'is' is not a class (type: 'PackedScene'). I instead declare a variable to define its type in the scene script, and I just need to use get to check if the colliding object has the variable.

+1 vote

From docs:

When a scene is instanced from a file, its topmost node contains the filename from which it was loaded.

So one of the ways would be:

func is_instanced_from_scene(p_node):
    if not p_node.filename.empty():
        return true
    return false

It doesn't answer whether a node is an instance of a particular scene, though. See other answers.

by (1,378 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.