0 votes

Hi All,

I have a custom Node2D scene that is used to end the game if certain conditions are met. I have extended this Node2D scene so that the condition is that a kinematic body is inside an Area2D. I want to execute the same code that I have written inside the Node2D every time, however I do not want the Area2D to be the same size or shape every time. My workaround for this has been to add the Area2D I want as a child to the Instanced Node2D rather than having the Area2D in the base scene itself so that I can fiddle with it. I cannot make the Node2D object into an Area2D object itself because I have other Node2D objects that I want to execute the same code with different conditions, such as a certain object exiting the scene tree. Is there a better solution to modifying the Area2D inside of the instanced scene?

Thanks for any and all help!

in Engine by (33 points)

1 Answer

0 votes

You don't need a scene for the function that ends the game. You can just have a script by itself since scripts are nodes. I think a singleton might be what you're looking for. Make a singleton that contains the end game function, and then call it from the Area2D script or other scripts when you want (you can use the same script for all of the Area2Ds).

by (8,546 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.