0 votes

In this case, i have a player scene. This player scene is an instanced scene and it's a singleton.
All I want to do is to detect this player if it overlaps an Area2D. I do var player = PlayerSingleton and if Area2D.overlaps_body(player): but it doesnt work. I think, it happened because it detect the original player scene instead of the instanced one. And now I want to detect the instanced player but I dont know how to do it ??

in Engine by (16 points)

1 Answer

0 votes

Instancing a scene will return the instance, save it to a variable and keep that variable around (e.g. by storing it in an auto-loaded script) and you're good to go.

Alternatively you can store the path to where you added the instance in your tree, get the node each time and use that instead. That ensures the scene still exists.

Not sure why you have a PlayerSingleton whatsoever, sounds wrong to me.

If you're having any trouble implementing this, feel free to ask. But as you haven't provided your code, I cannot give you a more concrete example for now.

by (10,580 points)

I think he wants an inherited scene (or "singleton" is his understanding for the inherited scene).

Anyway, if this area2D only detects collisions from one player type then assign a layer to that player and a layer mask to area2d for player. You can do it programmatically if you do the instancing (https://godotengine.org/qa/17896/collision-layer-and-masks-in-gdscript)

The only body then allowed to overlap would be the player instance (well anything with the player layer assigned before), so the bodyentered / bodyexited will react to that, for all other layers it will be as if there is no collision.

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.