How to enable input on a transient object

Hey all,

I’ve been working on a Phaser 3 project, and one scene maintains a list of text GameObjects. These are supposed to show the status of another game object, and I want you to be able to click on them to view some info about that status.

However, this list is constantly being destroyed and remade each update as the status of the game object it provides info about changes. Sometimes the list is empty, sometimes it is full. I want to enable input on these text objects, but if they get destroyed each update, then the input manager seems to not realize they exist.

Should I move the update to preUpdate or postUpdate? What can I do to make sure the input can be called before these text objects get destroyed next frame?

:wave:

If text objects are created and destroyed in 1 frame then they won’t be able to receive input at all, I think.

I would either keep 1 text object, update its text, and figure out which game object a click refers to (a little tricky) or keep 1 text object per game object and move or hide it as necessary.

These aren’t created and destroyed in the same frame. The start of the update destroys them, and then a new one is made. The next update is when it gets destroyed.

As for the reason I can’t keep them — imagine a list of status effects. You won’t always have a status. You can have many statuses. Each gameobject has its own list of statuses. Only one list is displayed on screen, but it has to refresh constantly, and I want you to be able to click on a status to get a description of it.

I think that may be too brief still.

I would try to keep either 1 text object per status effect (lasting as long as the effect) or 1 text object per line of text.

I guess you can try doing this in

this.input.pluginEvents.on('preupdate', () => {})

Coming back to this, I figured out something on my own time.

These text objects need to exist for more than one frame for input to work on them. However, you can stick them in a different array the next frame, and then delete everything in that array the frame after that. You’ll have two sets: this frame’s text objects, which input doesn’t work on yet, and last frame’s text objects, which input does work on.