Download

Lighting a lamp with a widget

Good evening;
I would like to turn on and off a lamp from a button in an inventory.
I placed a reference of the lamp in the Widget but there is a mistake, I do not understand there what. Could you tell me what is wrong?

Thank you in advance for your help.

How are you setting the reference to the lamp? Are you sure “Lumière Rouge” has a valid reference?

Hello Evil Cleric,

I first added a Bleuprint to the “light point”, then in the Widget I created a variable “type object” in which I referenced the “Lihgt point” that I named “Lumière Rouge”.
Is there a better way?

Bouton et lampe 2.jpg
Bouton et lampe 3.jpg

You only created a variable that will hold the reference. You haven’t set the reference yet.

For example, here I’m assigning the variable Lamp (in your case would be Lumière_Rouge) to a BP_Lamp object (in your case it would be PointLightRouge), right after creating my widget in the gamemode:

](filedata/fetch?id=1775794&d=1592138176)

Thank you very much Evil Cleric, I understand where my mistake comes from!

You could always leverage a blueprint interface, and just connect the OnClick to the “lights on” interface call…

Further, you could modify the interface call to check that Self is the the same as the requested reference, so that you could potentially select different lights to toggle with different buttons.

Thank you Mosthost LA for your intervention,
But… in my state of “newbie”, without a concrete example for me all this remains absolutely abstract.
I’m buying an online teache
:wink:

Perhaps you could share more context here? Choosing a communication method will depend on what you’re trying to achieve.

  • does every lamp have its own widget button?
  • how does the user choose which lamp to switch with the button?
  • or do you literally have 1 lamp and 1 button and that’s it?

It would also help if you told us where you create the widget and how the lamp ended up in the scene - did you drag an actor with a point light into the scene from the Content Browser?

Good morning Everynone,

I am aware that I am leaving you in the interrogation, so I will try to enlighten you as best I can.
I engaged in a small learning exercise, to understand simple principles, the goal being to master the inputs and outputs of variables in the Bleuprint.
For the moment I have placed three lamps and three buttons that are used to turn these lamps on and off, plus a fourth button that displays a number. All this in an inventory Widget.

Here is the montage in pictures:


Where do you create and add the widget to the viewport?

If that’s your question…
I make the Widbget appear by clearing the Num1 key in the level bleuprint

First of all. If you ever feel that you need to use Get All of Something nodes, you’re making a mistake in 99.99% cases. It has its uses but avoid using it unless you understand what it does and what it’s used for best. It leads to bad practices if used for getting references.
[HR][/HR]
So you call Create Widget in the Level Bleurpint and the lamps are in the level as well. In this case it’s all fairly straightforward:

afef38f72c198613f0824348cda0e4a830a80475.jpeg
https://forums.unrealengine.com/core/image/gif;base64
​​

You do not need to do anything in the widget. Remove whatever your buttons do. And instead implement the above.

You can get a reference to your Lamp by selecting it in the scene and drag-dropping it into the graph; or select in the scene and right click in the graph -> Create Reference to Lamp. The above will bind the button’s onClick event and let it toggle the light.

How do you create the reference to the lamp?

It’s in my post:

Sorry I was too quick to read :frowning:

It works well with a lamp, but how do you with two or three?

This should work OK if you have a few lamps:


Consider renaming the custom events to avoid confusion.
[HR][/HR]
This is not so great if you have 100 lamps; I’d recommend something else then.

Okay, thanks a lot for the help. :slight_smile:

In which case can we use “Get All Actor”?

When you do not care about the order of elements. Maybe you want to check how many enemies remain in the level. Or you want to destroy all traps. Or your backpack falls into lava and you lose all items. Still, there’s usually a more efficient way to keep track of things but GetAll can be a (clunky) shortcut.

Folks sometimes use GetAll when they are 100% sure there is only 1 thing they need to get, it’s lazy but hey, it does work, indeed.

Also, read the tooltip of that node, it comes with a warning.

Thank you, I remember that.