How to make an object invisible in real time?

Hello,

for an object, is it possible to say something like

a.setVisible(false)

…to make it invisible, and then

a.setVisible(true)

…to make it visible again, at will ?

I program a warrior game in which he loses pieces of his armor.
But now I want to collect a powerup and make up the armor full again.
I could endObject the armors and addObject them again, but they are not
properly aligned (they are just very little tiny larger than the body they cover)
and it does not look good. So I would rather hide the armors and re-appear them as needed.

Thank you in advance!

Yes you can.

http://bgepython.tutorialsforblender3d.com/GameObject/setVisible

There is even an actuator that can chang visibility
grafik

Btw. Making the mesh invisible means it is still there. E.g. when your armory is influencing the hitbox (physics) it is still present. You can see it when you enable Show Physics Vizualisation

grafik

Removing and Adding the object can become usefull when you want to change these “clothes” dynamically. You might investigate a bit deeper why the objects are not aligned properly.

Maybe this concept helps you too: How to: change a skin mesh

Have you tried dividing the armor into separate objects and changing their visibility via:
object.visible = True/False

Hello and thank you all :slight_smile:

Yes I should have Googled it I know, sorry !!!

In my game, all visible objects are “no collision” and I use invisible hitboxes for any interaction.
So hiding (or even removing) anything visible, will not affect behavior of other objects.
They are just ghosts . It has proven a good strategy (so far!).