Casting object reference not clear

Hey, I’m really new to UE4, so excuse me if this is obvious. I read a lot of documentation before asking this.

I’m casting from a widget to a blueprint class. Specifically, what I intend to do is pass the variable “tolerance” in the image to a blueprint. I get that I’m supposed specify which object of that blueprint class I’m casting to, but how??? I just don’t get how to make an object reference to a blueprint. I found something that works, but the engine seems to think there’s a better way than what I’m doing.

Thanks for anyone willing to help.

This is what my bp looks like.

in that instance you cont need the cast as the the object type is already known and is of the same type as the cast.

the way you have it setup is one way to accomplish getting a reference but it is one of the worst methods in my opinion. its a poor choice because its not explicit in which instance of the class that you are getting. so lets say you had two of the same blueprint in the scene and you used the get all of class node, which on will it return? you never know it could be either one. so instead you want a way to get a reference that is as explicit in which item its getting as possible. there are a few ways to do this and its very situation dependent. the methods include saving a variable that is a reference to what your looking to access, or creating a reference to the blueprint to change when the widget is created, or some other methods that dont come to mind at the moment.

without knowing more about the situation at hand its a bit difficult to help much more than that.

I agree with @ThompsonN13, but I have found instances where I could not avoid using the “Get All Actors of Class” node, my work around for that was I would create an integer variable in the actor BP I was using that node to locate all copies of, then I would assign manually that integer value for any copy I placed in my level, so when I used the “Get All” node I was able to reference a specific copy using a “for each loop” to check each copy in the “Get All” array created and identify the one with a specific integer value I was looking for. Of course depending on the set-up you may not even need a work around like that but there could be a more direct way to access the reference you want. More details would help and screen shots.

Yea, early on in my coding life I did that and I could never understand why the 0 index kept changing…turns out the level BP doesn’t instance each actor the way I placed them 0,1,2,3…it instances them randomly each time the level is created and so the array isn’t consistent. That’s when I figured out the little work around I described above. Which works great as long as you only have a few actors per level, I hear it can get pretty costly if you get into the hundreds and you use that node.

in some cases using a get all of class is the way to go such as if you wanted to open all doors in a dungeon or turn on all the lights in a building. the issue i have with using a get all is that i see it used wrong so often, people using get all then get 0.