0 votes


Spent 3 days trying to get this right, hoping someone can help.

I have a 'Being' class. It is the NPC's.
I have a 'BeingHub' which is the canvas layer that is the hud and various menus.
I have a 'mainPlay' class - it is all the nodes together to form the game.

I am trying to implement: When you click on NPC (Being), a little window (BeingHud) pops up. And then when you click on a button on BeingHud, the little window hides. I have the hide working with no issue via a signal between BeingHud and mainPlay.

What I cannot get working ... is when you click on a Being, I need the little window to open. I am for sure - able to get the being selected. I've done this code in the Being script.

func inputevent(viewport, event, shapeidx):
if event is InputEventMouseButton:
if event.button
index == BUTTONLEFT:
print("clicked on " + firstname)

Ive realized, the mainPlay node is not picking up the signal.

Is there a better way to implement such a simple thing?

in Engine by (117 points)

1 Answer

0 votes

I've got this working, but it's fairly sketchy I think.

I created a variable (singleton) in autoload called npcselected

When an npc (being) is selected it's true, other wise it's false.
When it's true - the process(delta) of BeingHud .show() otherwise
it will .hide().

Pretty sketchy. I can't imagine this is proper.

by (117 points)

Somebody sent me a really great reply to this.... I received it in email , but it's not showing here...


Your question on Godot Engine - Q&A has been answered by end

You have omitted in your example how you determine which cha
racter is clicked. You have to ray-cast from the position of the click into
the world and see which objects are intersected by the ray. Then, you may
dispatch the click to the object closest to the ray origin (or have some ot
her logic to determine which object has to accept the click, if multiple ob
jects are intersected). Ray-casting from screen is described here: https://
g-from-screen . The way to organize this in code is, for example, to have a
WorldInputManager that implements unhandledinput() and stores mouse clic
k positions, which are then processed in physicsprocess (which is where r
ay casting should happen). unhandledinput must be used to ensure that you
are not handling clicks that were already processed by UI elements. When W
orldInputManager determines that a ray intersects a clickable object, it di
spatches the event (calls a method) on the object in question. The object m
ay then display a HUD (BeingHud) near its location. To ensure there is only
one HUD shown at a time, showing a HUD would also have to be centralized i
n some kind of UIController.

Your question was:

Simple dial
og box based on clicking an NPC (like in Rimworld game)

If you lik
e this answer, you may select it as the best:


Thank you,

Godot Engine - Q&A

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.