Emax
January 8, 2025, 1:00am
1
Godot Version
4.3.stable
Question
Hi everyone,
I’m working on a project in Godot 4, and I have a question about structuring scenes.
I’ve created a base scene called Page, which is structured like this:
-Control
--Margin (Container)
---Page (VBox)
----Header (HBox)
-----Title (Label)
-----Back (Button)
----Body (Control)
Now, I want to use this Page scene as a base for other pages like “Options” or “Customization.” For example:
-Control
--Page (instance of the `Page` scene)
---[Custom UI for the page]
However, I want the custom components of each page to automatically appear inside the “Body” node of the Page instance.
I’d like this to work without needing to write code and to see the final structure directly in the editor (not just at runtime).
Currently, I can’t find a way to make the custom components automatically move under the Body node in the editor. Is there a way to achieve this using the editor’s tools, or should I restructure my scenes differently?
P.S. If you’re familiar with frameworks like Vue or React, I’m looking for something similar to a slot, where the custom content is automatically placed inside a specific part of the parent component
Thanks for your help!
wchc
January 8, 2025, 1:29am
2
I haven’t come across something like that. I tried to tinker around with the @tool
scripts, but couldn’t figure it out and I can spend more time on it today unfortunately.
The easiest way to achieve this effect would be to make the children of your scene editable and put your nodes inside like that.
Hope that works for you.
Emax
January 8, 2025, 7:47am
3
I found a PR that solves this problem, it is being developed for version 4.4
godotengine:master
← yahkr:exposed_in_owner
opened 06:40PM - 26 Oct 23 UTC
### Updated 11/1/2024
## Description
This pull request implements a feature … that significantly enhances Godot's scene editing capabilities. It allows specific nodes within a scene to be exposed, making them visible and allowing their properties to be overridden when the scene is instantiated elsewhere. I believe it is an improved version of editable children.
- By exposing only relevant nodes, the scene tree remains uncluttered, which is especially useful for creating reusable scenes (Custom containers, Generic windows).
- This PR adds the ability to expose nodes on import, for use when wanting to expose parts of a scene (such as the hand bone of a character for equipping).
> [!NOTE]
> - Node exposure only propagates up one level of instantiation
> - Nodes that are exposed can be re-exposed
> [!IMPORTANT]
> The use of unique names has been removed from this PR (https://github.com/godotengine/godot/pull/84018#issuecomment-2452057599) as there were too many issues with it, once https://github.com/godotengine/godot/pull/86960 is merged this PR should function like originally planned </h1>
<details>
<summary> <h2> Example 1 </h2></summary>
Lets say we have this window scene that we want to re-use everywhere we can exposed the title label and the content nodes:
![image](https://github.com/user-attachments/assets/61140036-172d-4af3-b04e-fa40e641af3e)
With this PR we can modify the properties of the exposed nodes and append child nodes to them, this lets us create super flexible scenes and use them like so:
![image](https://github.com/user-attachments/assets/15db23a2-f370-4706-a177-0730bdd17d29)
and this is the same scene with editable children enabled. Far messier and poorer UX
![image](https://github.com/user-attachments/assets/81608fe6-4d00-45a4-be92-d6c7e20072e3)
</details>
<details>
<summary><h2>Example 2</h2></summary>
For a simple scene like the following, we expose the Sprite2D, the resulting tscn looks like this:
![image](https://github.com/user-attachments/assets/ba6bcba3-52e6-43a8-a171-d40965c19d95)
![image](https://github.com/user-attachments/assets/90bf1194-f687-4dcc-8117-4146b44237f6)
```diff
[node name="scene_0" type="Node2D"]
[node name="Parent" type="Node2D" parent="."]
[node name="Exposed_0" type="Sprite2D" parent="Parent"]
+ exposed_in_owner = true
texture = ExtResource("1_mdjal")
+[exposed path="Parent/Exposed_0"]
```
In another scene we instantiate this simple scene and override the exposed node's rotation property and add a child node to the exposed node. We also modify the color of the exposed node to orange
![image](https://github.com/user-attachments/assets/e48d4c42-1b6c-4ae3-bd2f-a19e8a3ee39e)
![image](https://github.com/user-attachments/assets/89dca6b5-1eb0-41e8-b9b6-31d8919660e0)
.tscn with this pr using exposed nodes:
```diff
[node name="scene_1" type="Node2D"]
[node name="scene_0_instance" parent="." instance=ExtResource("1_mdjal")]
[node name="Exposed_0" parent="scene_0_instance/Parent" index="0"]
self_modulate = Color(1, 0.666667, 0, 1)
[node name="Child_Of_Exposed" type="Sprite2D" parent="scene_0_instance/Parent/Exposed_0" index="0"]
position = Vector2(100, 30)
scale = Vector2(0.5, 0.5)
texture = SubResource("CompressedTexture2D_3sd7o")
```
.tscn with editable children and doing the same thing:
![image](https://github.com/user-attachments/assets/05112855-52ce-4e09-931d-50955a3bc4a6)
```diff
[node name="scene_1" type="Node2D"]
[node name="scene_0_instance" parent="." instance=ExtResource("1_mdjal")]
[node name="Exposed_0" parent="scene_0_instance/Parent" index="0"]
self_modulate = Color(1, 0.666667, 0, 1)
[node name="Child_Of_Exposed" type="Sprite2D" parent="scene_0_instance/Parent/Exposed_0" index="0"]
position = Vector2(100, 30)
scale = Vector2(0.5, 0.5)
texture = SubResource("CompressedTexture2D_3sd7o")
+ [editable path="scene_0_instance"]
```
</details>
___
## Sample Project
- [mrp.zip](https://github.com/user-attachments/files/17603057/mrp.zip)
## TODO
- Continue to test
___
I think that this pr addresses the following proposals:
- Closes https://github.com/godotengine/godot-proposals/issues/3248
- Closes https://github.com/godotengine/godot-proposals/issues/4265
- Closes https://github.com/godotengine/godot-proposals/issues/9660
- Closes https://github.com/godotengine/godot-proposals/issues/5475
- Closes https://github.com/godotengine/godot-proposals/issues/8266
- Closes (?) https://github.com/godotengine/godot-proposals/issues/7803
- Closes (?) https://github.com/godotengine/godot-proposals/issues/9536
1 Like