Making an object disappear after a few seconds with Python (BGE) In Blender Game Engine, I want to have an object (in this case, text in a HUD, but it could be anything) appear when triggered, linger for a couple of seconds, and then disappear. For example, the player hits a key M to change an object from a cube to a sphere (like in my stackexchange question here). Some text in a HUD appears: &quot;Changed to sphere.&quot; The text disappears after a couple seconds, and doesn't come back until the player does something again to warrant a HUD message.
Think of it like how a message like &quot;Picked up health kit (+10 HP)&quot; would display in an FPS, and then disappear after a couple seconds. I know how to generate and display the message, but I don't know how to make it disappear.
Another requirements that may need to be considered: the program can't be stuck during the duration of the fade. So if the user hits M M M in rapid succession, and M cycles between a cube, a sphere, and a cone, I don't want the text to be stuck on &quot;Cube&quot; for 3 seconds regardless, or even the whole program to be stuck until the text goes away. I want it to display the text &quot;Cube&quot; &quot;Sphere&quot; &quot;Cone&quot; in real time as the user hits M, and then when the user hits nothing, &quot;Cone&quot; would fade away after a few seconds.
Here's what I tried so far
My first attempt was this
import bge
import time

def lingerObject(obj,lingertime):
    #Makes object obj (e.g. HUD text) linger for a certain number of seconds, then disappear
    #lingertime should be a time in seconds
    start_time = time.clock()
    end_time = start_time + lingertime
    obj.visible = True
    if time.clock() &gt;= end_time:
        obj.visible = False

&quot;&quot;&quot;Elsewhere in the code, I change the HUD text (successfully)
and call this new function to make the object disappear (unsuccessfully)&quot;&quot;&quot;
def someFunction():
    #These two lines work:
    hudfield = getHUDfield() #getHUDfield is my function that finds the appropriate text object in the HUD scene
    hudfield[&quot;Text&quot;] = &quot;New Message, e.g. Cube&quot;
    #This line (or rather, my function) doesn't:
    lingerObject(hudfield,3)

As I point out in the code comments, it doesn't work. Everything else still works just fine, the text changes every time that it's supposed to, but the text never disappears.
I also tried a while loop instead, and it just made the program run very sluggishly, and eventually the text disappeared and never came back:
import bge
import time

def lingerObject(obj,lingertime):
    #Makes object obj (e.g. HUD text) linger for a certain number of seconds, then disappear
    #lingertime should be a time in seconds
    start_time = time.clock()
    end_time = start_time + lingertime
    while time.clock() &lt;= end_time:
        obj.visible = True
    obj.visible = False

#Elsewhere, lingerObject(obj,lingertime) is called like in the prior code block

I looked around online, I found a lot of HUD tutorials but none on how to have text disappear after a bit. Any help would be appreciated. Thanks in advance!
Making an object disappear after a few seconds with Python (BGE)

Think event driven!
WHEN happens WHAT?
WHEN

after a few seconds

'After' is relative ... checking your details ...

appear when triggered, linger for a couple of seconds, and then disappear

So I guess you mean:
A few seconds after triggered
Solution
when you know the &quot;triggered&quot; event, you can start a timer, counter, whatever that triggers an event after the desired seconds.
Example: Timer Property
Property: &quot;time&quot;, type &quot;Timer&quot; (A timer property constantly increases it's value with each frame with the [configured] duration of the frame.)

When your trigger event happens you set the property to the number of seconds to wait and multiply it with -1 e.g. -3 for 3 seconds.

A property sensor can evaluate when the property &quot;time&quot; is greater than zero. That is the event you are looking for.

WHAT
whatever you want
Remarks

Timer properties are always float (avoid &quot;equal&quot; compare)
Lags will not be measured by timer properties
Timer properties always count upwards
Timer properties count always (it will not stop)
You can explicitly assign new values to timer properties (e.g. for reset)