Global variables? Variables with scope?

I wish we had an easier way of changing variables between different BP classes. I just need to define and change global variables but I don’t understand how to do it. I don’t understand the interface tutorials and I don’t understand casting. Can anyone break it down barney style for dummies like me?

How can I define and get/set global variables? How can I define and set and get variables within a scope? How do the terms casting and interfacing relate to scope? My background is in lower level code and I don’t understand these terms or functions and how to use them effectively.

Not even sure you can have true globals variables in pure BPs. You could always set them up yourself in cpp. Here’s the closest thing you’ll get, it works: How create global variable? - Editor Scripting - Unreal Engine Forums

I would suggest not using them if you can though, unless they truly need to be, and are global.

Here’s how casting works: When you successfully cast to a class, you have complete access to all the variables inside said class. To successfully cast, you need a valid reference. There are a millions ways to get a valid ref. I’ll list a few.

  1. If you only plan to have one instance of a class in your world, you can use this method:


  1. If you want to chop a tree and reduce the “remaining wood” the tree has, you can line trace to get the reference. The cast will fail if you don’t successful trace to the tree actor, which would give you an invalid ref:

  1. You can get a reference by overlapping. In this case, the players overlaps a collision box inside CastActor, and CastActor casts to the player to give it a speed boost:

Take the time to figure out casting. It’s essential. After that, figure out interfaces. Also important, but IMO second to casting.