"If object is hidden" condition


#1

If there’s just ONE thing that I don’t like about GDevelop, it’s that you can still interact with objects even if they’re hidden with the “hide object” action. Now, this can be handy in some cases (Like making collisions for levels), but there are times when you don’t want a hidden object to be interacted with.

For example, in the Tabbed Menu example, I made the following change:


This makes it so that if my cursor clicks over a level button, the sound effect plays. I tested this out, and tabbed the menu to hide the level buttons and clicked over them. Just as I expected, the level buttons played the sound effect, despite being completely invisible. Something like this could definitely cause some issues.

I also tried this in another project, in which I wanted a powerup to be hidden until the player pushes a button to make it appear. However, despite being hidden, the player was still able to pick it up. I wanted to make it so the powerup CANNOT be collected unless it can also be seen as well.

My solution? Add a new condition: “Object is hidden.” This condition will check if the object is currently hidden. If the condition is inverted, it will check is the object is NOT hidden instead.

There! Now you can make those invisible powerups without collecting them out of thin air! Now you can make a proper tabbed menu without the buttons invisibly overlapping each other!

Likewise, to prevent the same thing happening with hidden layers, there should also be a “Layer (LayerName) is hidden” to check if a layer is currently hidden or not (This is the case for the tabbed menu example).

As of right now, the tabbed menu example DOES NOT WORK since the level buttons can still be interacted with even while they’re hidden (Would this be considered more of a bug? Idk). I would love to see this condition added to prevent issues like these popping up without having to create ridiculous workarounds.

What do you all think? Feedback is appreciated ^^


#2

Having 1 condition to check if it is hidden or not is by no means a “ridiculous workaround”

So I don’t like your request, since you still would need this “ridiculous workaround” if you do want to interact with hidden objects. It is also much less intuitive to have an extra condition to be able to interact with objects.

It is a little bit confusing, that an object on a hidden layer does not have a “is hidden” flag, unless you also use an event to hide it.
On the other hand i cannot see a good reason to check visibility of an object, that is on a hidden layer. I don’t remember why i even know this, but i must have needed it at some point to be aware of it.


#3

Maybe I misunderstand something here but what is wrong with the condition to check if object and layer is visible? Or you did not know it is exist?



#4

Okay, I’m pretty dense. I had completely forgotten that this condition existed.
However, I tried this out by adding the condition to the code:


Sadly, it still doesn’t work. The sound still plays when the object is hidden. Inverting the condition will prevent the sound from playing at all even when it’s visible. Am I using it wrong?
(Note: The whole layer is hidden for the level buttons, not each individual object).


#5

As i described, check for visibility of the layer, not the object.
Objects only have the hidden flag, if you hide the object.

I recommend you have the condition layer is visible as your first event and all interactions with that layer as subevents of it.
So you only need it once.


#6

Ah, okay. I got it fixed now. It now works exactly like I needed it to.
Also, the “ridiculous workaround” thing was actually a typo on my part. I meant to say “WITHOUT having to create a ridiculous workaround,” but I accidentally used “and” in place of without (I edited it to fix the issue).
Sorry about the confusion, that’s my bad ^^;

Still, the tabbed menu example should be updated to include the “Layer ‘play’ is visible” condition to make sure the buttons can’t be pressed when they’re tabbed out.


#7

The majority of examples are user created and submitted. While I dont necessarily think the listed change is mandatory, I do think it makes sense. You are welcome to make the change and submit the updated example on github to get it updated/added.


#8

WTH you can use if object is visible and INVERT IT