x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

alt text

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?

Product Version: UE 4.18
Tags:
how.png (174.5 kB)
more ▼

asked Mar 04 '18 at 01:13 PM in Blueprint Scripting

avatar image

Inteco Galaxy
0 1 5

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Mar 04 '18 at 04:18 PM

avatar image

ThompsonN13
9.4k 33 8 23

avatar image DjFrex Mar 04 '18 at 04:53 PM

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

avatar image ThompsonN13 Mar 04 '18 at 05:13 PM

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.

avatar image DjFrex Mar 04 '18 at 05:18 PM

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.

(comments are locked)
10|2000 characters needed characters left

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.

more ▼

answered Mar 04 '18 at 01:43 PM

avatar image

DjFrex
66 1 4 8

avatar image Inteco Galaxy Mar 04 '18 at 02:57 PM

alt text

254135215616.png (283.2 kB)
avatar image DjFrex Mar 04 '18 at 03:21 PM

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.alt text

immagine.png (1.2 MB)
(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question