Composition limitation: Issue when customizing simple instanced scenes

Godot Version

4.3 stable

Question

I have been using composition for making “Interaction Components” as StayAtHomeDev does in his FPS tutorial series.
I know composition is praised for modularity and flexibility so I decided to go with it.

I made a Door Interaction Node to add to doors, and a Light switch Interaction Node, both of them are added as children of their scenes and have a bunch of exports (locked, broken, which lights to control, etc.)

My problem stems from the fact that when I instantiate these in a scene, I cannot access the exported values directly. Since the composition Nodes are children of the instanced class, I need to either enable editable children in all of them (which I find to be error-prone) or just add another script that communicates with the interaction node.

I assume that’s the solution, but then why go through the trouble of using composition at all? Using two scripts for a single thing seems overcomplicated.

I just want to know if there are alternatives I’m missing, or if really this is not the use case for composition, and it should be used for more complex scenes that already have parent controller scripts.

I think the way StayAtHomeDev expects you to use this is, to add the composition nodes not directly in the specific scene, but in the level scene as children of the instantiated scenes. This way you dont have to make editable children and you can access the export variables of the composition nodes. This has the downside that you have to add them all manually for every instance.

I personally think there are better ways of using composition, but thats his way.

1 Like

Right, I didn’t think about that. Yeah it’s not my favorite either, but I see how it’s supposed to work now. I think I’ll stick to Inheritance. Thanks for your input!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.