I want to change the variable in another pawn when I click on the button

I want to change the variable in another pawn when I click on the button. What to attach to object
if I want it to be done when I press a certain button?

The fastest way is to use a “GetAllActorOfClass” and for each actor found you can set the value you want.

If the “StarGun_PU” is your main character you can pass “GetPlayerCharacter” as object.
If the “StarGun_PU” is not your main character but is referenced in it, you can simply “GetPlayerCharacter”, cast it to your Character class and then get the “StarGun_PU” reference from there.

Ok from what I’ve understood, the StartGun is your character’s weapon right?

In your character BP you have already a reference to the gun, that you called FP Gun.
So in your widget you have simply to do this:
“GetPlayerCharacter”->CastToFirstPersonCharacter from there you “Get FP_Gun” and from this variable you can set the values you want.

Note that in your first person character the Cast you are doing will always fail. Indeed the first person character’s class isn’t StarGun so it will always fail.

to change a variable on another pawn you need to get a reference to the other pawn. there are many ways to get a actor reference such as hit and overlap events, variables you set beforehand, and traces. once you have a reference to the actor you want to change the variable on you may need to cast to the actors class. then all you need to to do is get the variable then set it to the new value.

That was exactly what I was trying to explain to “IntecoGalaxy”. Thank for your negative vote!

I said that method was the fast one, supposing he had only one instance of the actor. As soon I finished the sentence I explained better ways to achieve the result he wanted.

you were telling them to use get all actors which would change the variable on everyone of the actors of that class instead of just one specific instance. your answer is wrong and is perpetuating the use of the get all actors of class node in the wrong circumstances so thats the reason for the downvote.