[BP Comm] Can someone explain this to me?

While working on my inventory system i stumbled across an odd issue.

This works perfectly:

However the following gives out errors after playing in the editor (Accessed none errors pointing to an empty construction script):

This also does not work, and the cast fails:

It’s not an issue since i’ve figured out how to make it work, I’m just wondering if somebody could explain** why** this happens? It compiles just fine.
Does the UMG widget have the player character as an owner, and therefore has to use the reference created inside of the player blueprint?

Did you specify the player when you created the HUD, or let it just choose for itself? I think it defaults to 0.

Completely forgot about this little thing here:


That might explain it?
Really does seem like an ownership thing, with the second setups trying to modify a nonexistent hud belonging to the item, rather than the player’s hud.

In first picture you use the begin overlap to drag your hud for your end overlap set visibility. It may be better to use the one drag from the cast from the end overlap. I have no more idea to help sadly.

While i appreciate the offer of help, please read the thread fully. I’m not looking for help implementing anything, I’m looking for a definitive explanation as to why one method works and the other doesn’t so i can use that knowledge to make further blueprint communication attempts easier / less trial and error.

As is clearly stated above the first image* and* below the final image, i have it working perfectly already.

In regards to the end overlap cast, that cast node is actually gone now as it doesn’t even need to be there at all. If you have started an overlap, that means you’ve already succesfully casted and there’s no way to cause the end overlap event without having previously triggered the start overlap event containing the successful cast.

Ok so I’m going to try and explain why one method works and the other doesn’t. It all boils down to references and variables.

By default when you have a variable of a BP/Actor type they are all ways set to “Null” unless set at some point within the script. In the bottom two images that you said you were having issues with, this is most likely because the variable “GameHUD” has nothing stored in it. When you create variables like these just think of them as empty boxes, they remain empty until you put something in them. This is why you get the “Accessed None” type error message from the first of the two images.

As for the second one I first need to explain what a “Cast To” node actually does to explain why it fails. In UE4 you get a lot of primary class types that all other blueprints build upon.

The best example is “Actor”, this covers things from player character to that dancing road cone you’ve all ways wan’t to make. These them selves will however have there own classes/blueprints that has one of the primary classes as a base class. A “cast to” in a way changes how UE sees the reference, changing it from Actor to say DancingCone. This then allows you to access variables that have been created in the DancingCode BP.

If the Actor reference I’m trying to get UE to see differently has nothing to do with what I’m casting to it’ll fail. It’s like trying to fit a cube through a triangular hole. However in the second imaging this most likely fails because the variable “GameHUD” is just an empty box of “Null” which will always fail a cast as it doesn’t fit through the hole.

In the very first image that worked you getting an “Actor” reference the overlap event spat out and telling UE to see if its actually “MyCharacter” BP. If yes you then tell it to get “GameHUDWidget” (created inside the “MyCharacter” BP) and use the contents of the box as a target. I would imagine you set the variable to the widget you created.

In addition a variable of type “MyCharacter” for example doesn’t need to be “Cast To” “MyCharacter” to access the variables from the reference.

I hope this helps. :slight_smile: I’m still trying to find a good way to explain the whole casting thing so I can make an in depth tutorial, so if you like the explanation let me know.

Okay so basically what i’ve learned is that i need to pay more attention to what I’ve done -_-
At some point, i removed the nodes that were actually setting that variable to my players HUD widget, and the errors it was outputting were pointing me nowhere.

I understand what casting is and how to use it, as i use casting extensively in maaaaaany parts of my game, this was just a dumb mistake that happened because i forgot something i had done. That’s why i was so confused as to why it wasn’t working :stuck_out_tongue: