How Do I Set A Variable From Another Blueprint?

I’m new to Unreal Engine and I’m having some trouble figuring out how to use the blueprints properly. I’m making a top-down shooter game and I want to make a power-up that temporarily changes the rate of fire from the weapon. Basically I’m trying to change the value of a float variable which controls the rounds per second from my Weapons blueprint in a separate Power-Up blueprint, but I can’t figure out how to get it work.

I’ve tried making the variable public, I’ve tried casting to the Weapon blueprint, and I’ve tried setting the variable in my Power-Up blueprint, but when I play the game, the rounds per second do not change. Here’s how I would like it to work: OnActorOverlap → Set “Rounds Per Second” variable to “New Rounds Per Second” → Destroy Actor → Delay → Respawn Actor

If someone could help me figure out what I’m doing wrong, I would be very grateful. I’ll post a screenshot of the configuration I tried that did not work. Thanks for the help!!

Who is interacting with the item, the character or the weapon?

Or “Other Actor” is not a Weapon or you setting diffrent object then you expecting, best way to solve this problem is to debug via breakpoints. Put a breakpoint on Cast to Weapon (right click the node and you should have option for that), run the game, trigger event and this will stop the game and blueprint will show up with triggered breakpoint. Now hover over “Object” pin and you should have info what it recives. This should open your eyes on issue.

There possibility that you have collisions set up wrong and event is not even triggered.

The character is overlapping and picking up the item, and then the item is changing a variable on the weapon (which is a separate blueprint from the character).

Ok, I tried adding a breakpoint like you suggested, but I’m still not sure what is wrong. I also tried attaching the weapon reference to the “Object” input on the “Cast To Weapon” node. I attached a screenshot of the message log. Thank you for your help!

alt text

@anonymous_user_f5a50610 is correct, you are not getting the reference to your weapon… If you were to run a “Print String” node off of the “Cast Failed” execution you would see that your cast is not happening. That’s what your error is telling you, “Accessed None ‘Weapon’” means exactly that, there was no ‘Weapon’ to access. We need to see more of your code to get a better understanding of what you are doing wrong.

You guys were right. I see now that the Cast has been failing. Sorry for my annoyance, but what are some reasons why the cast might fail? The weapon spawns from the character blueprint and is not technically placed in the level, so could that have something to do with it? I’ve tried getting the weapon and attaching it to the Cast, but that doesn’t do anything. Thank you all for your help! Sorry for not understanding how to fix this!

Does your character have a reference (variable) of the weapon he’s holding? If so, you can call GetWeapon (or whatever your variable is called) on your character.

If your weapon isn’t stored in your character blueprint yet, you could add such a variable and set it right after spawning the weapon.

I’ve tried getting the weapon and attaching it to the Cast, but that doesn’t do anything.

Could you post a screenshot of what you tried?

Because it is not your weapon that triggers the overlap, rather it’s the character. If you cast to your player character, and like @ points out, have a variable that is set when you spawn the weapon to store it’s reference, you can then pull off your cast to player character and retrieve your weapon instance variable and set the weapons variables through that. Seems sort of complex but once you do it once or twice you’ll get the hang of it

Here you go. This is somewhat simplistic - spawn your weapon however you are spawning it, I just did mine as an example.

Then in your pickup blueprint or whatever it is you are overlapping put this:

In my “Weapon” blueprint I have the variable float “RoundsPerSecond” which I can then draw from the instance reference I set from the player character that I set when I spawned the weapon.

Hope this helps! If so, please consider accepting the answer by clicking the check mark located under the arrows next to the answer! Thanks and good luck!

This worked perfectly! Thank you so much! I didn’t know I had to cast to my player character and get the weapon reference from there. Blueprints can be kind of confusing and not intuitive, so I appreciate all the help! You saved me from lots of frustration! Cheers!!

You can see! helpful for you!