Issue with parent door and children switches

Godot Version

4.3 (steam)

First off, I know it’s long but thank you for taking the time to read this.

I have a 2D game with a lever switch that uses 2 raycasts to tell if the player can turn it on or off depending on which side of the switch the player is standing. There is also a prompt system that displays ‘press enter’ over the players head when the player is colliding with the raycast.

I have it set up so I can add multiple switches as children to a door so all the switches need activating before the door opens.

All this works. The doors and switches work great and I can add as many children switches as i need. All the switches are duplicates of each other and share the same code.

The parent door code counts the number of children it has and compares it to a number. Each child switch adds or subs 1 to a variable inside the parent door depending on whether it is on or not.
When # of children equal the number of activations then the door opens. Pretty simple, scalable and it all works great.

The issue is not with the doors opening at all. It is with displaying the prompts.

When I have one parent door with one child switch the prompt displays properly.
If I add more children under the door only the bottom most switch in the list of children will display the prompt.
The other switches don’t sow the prompt at all.
The weird part is that the code still works for all the switches as far as activating the switch. They all use the same .gd file.
But the switches all work, they flip on and off properly and they successfully open and close the door.
The only thing that doesn’t work properly is that only one switch in the list of children shows the prompt in game.

It doesn’t feel like a code issue since I’ve tried removing all but one switch that previously didn’t show the prompt. When it’s the only switch left, or if I rearrange them so it is the bottom most switch then it displays the prompt.
I tried rearranging them and it seems to always be the bottom most switch in the list of children that shows the prompt properly. The others don’t show anything.

For testing purposes I’ve added print statements right before the function that display the prompts. The print statements work on all the switches but the prompt still only displays on one child, the bottom most one in the list. I just can’t figure out why.

It’s not game breaking but Just wondering if anyone has seen anything like this and maybe knows what the problem is.

Thanks for your time and any suggestions.

Without see the code and without see the scene organization will be hard to help but if you say only the last one shows correctly that can be the related to the drawing order, the bottom nodes draw first than the top ones, so the other nodes can be ahead of whatever you want to show, try set the z_index to a value bigger than the others nodes to see if works.

Thanks for the reply. It’s not a game breaking thing. Just curious about it. I’m learning so it is a bit of spaghetti code but I got it to work originally meant as just one switch and one door. Later I recoded it to allow for the children to be added. The toggle switch code calls a function in the UI scene, which handles inventory display and player prompts, so that code then makes visible a prompt over the players head so every switch prompt is really inside the player and it’s always the same prompt either made visible or not so graphical z-index seems unlikely. AS I WRITE THIS it has come to me. lol

The toggle switch is responsible for turning the players prompt on and off. I’m guessing when one switch turns the players prompt on the others turn it off immediately since their raycast is not being collided with so I think the prompt turns on and then another switch turns it off immediately and only the last switch doesn’t get interrupted.

I think I can devise a child count check to fix this.

Hey thank you for sparking my brain into action. lol

For anyone curious and to newbies a word of advice. Be careful what you put in the process function.

I fixed the issue of the prompt showing up and immediately being deleted in the process function. As soon as one prompt for one switch would display when the raycast was collided with by the player the other child switch would remove the prompt because it’s raycast wasn’t being collided with by the player. I fixed this by using Area2D with signals to turn on and off the prompts totally bypassing the process function and now it all works.

Simple problem actually, simple fix.

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