How to move a object when press a button on widget

English:
I am trying to make a widget that when I press a button, an object will move, but I can´t make the communication for the event on click button to call a function on the object I want to move. Example: When I arrive at a point a widget appears with options where I want to move the object

Português:
Estou tentando fazer um widget que quando eu aperto um botão, um objeto se moverá, mas não estou conseguindo fazer a comunicação para no evento on click button chamar uma função no objeto que quero mover. Exemplo: quando eu chego em um ponto aparece um widget com as opções onde eu desejo mover o objeto

Hey Pirrita!

Trust me, I used to have similar issues in blueprints. It can be a little tricky if you don’t know the API.

Thankfully, there are a lot of nodes that can be used to help you resolve your issue!

My best recommendation would be to pass a reference to the object that you want to move when creating the widget.

An example would be something like this:

  • First, you will want to create a
    reference to your object like so:
    Screenshot by Lightshot
    Note : It is
    important to set the instance
    editable and expose on spawn
    properties to true if you do not want
    to pass the reference via interface
    or look it up on the fly.
  • Next, you will want to create the widget and send the reference to the object like so: Screenshot by Lightshot. This can be done on an overlap event using a box collision in another actor or through any means you wish as long as you pass the reference in.
  • Last you would add the widget to the viewport and run your method to move the object on button click.

If you do not have the ability to cleanly gather a reference to your object before the widget is created you can try the GetAllActorsOfClass, GetAllActorsWithTag, or GetAllActorsWithInterface nodes to get a reference to your object like so : Screenshot by Lightshot but this can be tricky if you have multiple objects in the world. If that’s the case, I would give each object a unique identifier and add it to the actors’ Tags array like so : Screenshot by Lightshot.

Thanks it work