Change collision shape from outside scene

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

I’m using an Area2D in combination with a collisionShape2D to create an area in my platformer that triggers interactions (e.g. text bubbels).

I don’t want to duplicate it each time so I included this in a scene. The problem is that the collision shape is not the root node of that scene and therefore I cannot change it from the scene where this is linked

SceneA
–Area2D
----CollisionShape2D

SceneB
–SceneA

Is there a way to change the collisionShape2D for each instance of scene A from scene B? I can select editable children but this changes that shape for each instance of sceneA in the same way.

What is driving the need to change the collision shape and who/what has access to that information?

jgodfrey | 2020-11-23 02:34

@jgodfrey For each trigger I would like to have a different collision box. In some places that means a small square while in other locations this means a large rectangle.

It would look like this:

SceneB
--SceneA-instance1 -> small square collision box
--SceneA-instance2 -> large rectangle collision box
--SceneA-instance3 -> circular collision box

takje | 2020-11-25 17:06

:bust_in_silhouette: Reply From: takje

For now I use a the following sequence to achieve the desired effect

  • Link the scene
  • Right-click on the scene and select ‘editable children’
  • Click on the collision object which is now visible
  • In the inspector, click on the shape drowndown and select make unique

The workflow is a bit long but it does the job. You can now modify the collision box separate from other instances of this scene.

Ideally, the scene itself would have enough information to modify its own collision shape when it’s instantiated (though, you really haven’t said what drives that decision). Anyway, if that were the case, when the scene is instantiated, it would simply adjust its own collision box as necessary.

jgodfrey | 2020-11-25 17:27

Indeed I also thought about this. I could have used an export with the coordinates. However, I’m using it mainly in the editor to manually do the level construction. Therefore I was specifically looking for a way where I could use drag and drop to modify the shape. As far as I could find there was no way I could do this with an export.

takje | 2020-11-25 17:30