Changing Area2D CollisionShape in Instanced Scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WarDev

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!

:bust_in_silhouette: Reply From: exuin

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).