Getting references from overlap events

Hey there unrealer’s, I’ve been lurking here for a few months as I have been trying to learn unreal and this is the first time that I just cannot find what I’m looking for in a previous question.

I want to use “On Component begin overlap” on an enemy blueprint and I only want it to trigger for my player. Now, I know, that’s a pretty basic question, and I am able to get it to work I just need to know what is the most efficient way to pass a reference to the player, and check if it is indeed that player.

I was able to get this working fine with ‘Cast to’ my players blueprint but… (and here come this big hole in my understanding, which requires a bit of an explanation.) The first Blueprint tutorial series I watched kept telling me casting is bad and I should be using Blueprint Interfaces… I struggled with Interfaces for a few weeks before I could understand what they do, which I pretty much get now. I am sure there is more nuance to casting vs. interfaces but that’s where I’m struggling.

So I switched all of my collisions to check a Blueprint Interface instead of casting, but then I had to go in and add a branch to check if it’s the right pawn overlapping, instead of just using the ‘Cast Failed’ Node. I got it to work either way but this is bugging me like crazy.

Which of these is the better way to go? Cast to looks way cleaner but ‘something about hard references rabble rabble…’.

Or is there an easier way? I’ve made a lot of progress in the past few months but everytime I need to reference another blueprint I feel like I don’t get it and even though I can usually get it to work, I do not understand why.

Here are pics of my 2 different setups, so far as I can tell, they both work.

Hi hoveland008,

Casting isn’t exactly fast - but what you can do is just store a reference of your character in the blueprint that is handling the triggers - and just see if “other actor” equals that - then use that reference for setting your data - then you only need 1 cast, at the begining when you set it up.

Okay, that makes sense I think. I did try just putting a variable inside my enemy and setting the type to be my player blueprint but it wouldn’t work, I didn’t realize that the casting was necessary there.

So if I understand correctly, if I make that variable without casting to fill it up, it is just an empty vessel that knows this other blueprint exists and casting to it is how that variable gets the actual data from the blueprint. Am I close?

Thank you so much for the speedy reply, you guys are the best!

That sounds like you haven’t actually set that variable to point to anything. Also, in that first snapshot you have, you don’t have the Cast “Object” set to anything - are you seeing it print the name? Is that code in BP_Reggie?

This is how I do it - a reference set from somewhere solid would be slightly faster - but this is just quick and easy :slight_smile:

Make the “MyPawn” variable a reference to BP_Reggie and change that “Cast To DefaultPawn” to “Cast to BP_Reggie”.

Also, You may need to replace the “Get Player Pawn” with “Get Player Character” depending on your project…

1 Like

Ok. That makes a lot of sense now. Sorry about the object pin. I did have that linked up, i was just moving things around for the screenshot. Cant believe i missed it. I think i understand things mich better now. Thanks!

2 Likes