Sphere Collision overlap event not working

So since I can’t change Peripheral Vision Angle in BPs I decided to try adding a Sphere Collision to my Flashlight BP in the shape of the spotlight cone radius and added an Overlap Event when it hits my Enemy BP, so that the enemy chases the player.

For some reason it’s not working. I believe it’s something stupid, but naturally I can’t see it.

i think the white pin from the overlap event needs to go into the cast to BP_Flashlight

Hi Pachyderm,

Your Overlap event is failing at the Cast to BP_Enemy node. Not only your Object references are invalid, your nodes are not fully connected. In order for it to work, the white curve which indicates the execution flow must first go through Cast To BP_FlashLight node. Then you should connect its output execution pin to Cast To BP_Enemy and so forth. At this point, you should see the Hello message printed on your screen but your AI Move To node will fail as both Pawn and Target actor are invalid and will never fire. You need to first tell those two nodes what their Input Objects are, as well as making sure that they are executed by passing the execution flow through them. Alternatively, you can first do all your casting when the Overlap event fires, save the output of each of those Casts in a separate variable, and then use those variables. If you don’t want to do that and you’re sure that your Casts will never fail, you can right click on them and convert them to Pure cast (However, I don’t recommend doing this for now unless you know what you’re doing.)

Best,

Vizgin

But then wouldn’t you cast your BP_Flashlight to a BP_Enemy which would fail. I think you need to take the “Other Actor” pin from Event ActorBeingOverlap and put that into the Object for Cast to B_Enemy

You’re absolutely right TaunTButtoN. He’s passing a wrong object into his Cast node as well. Thanks for pointing that out.

I’m not sure what logic you’re trying to implement for this overlap event here, but I assume what you wanna do is to check if the FirstPersonCharacter has entered the Sphere collision area and then have your AI BP_Enemy run towards him. If that is what you’re trying to do, here’s how you do it:

Take the execution pin from ActorBeginOverlap and connect it to Cast To FirstPersonCharacter. Get the Other Actor pin and connect it to Object pin of First Person Character. Whenever someone/something enters this overlap zone, the Event node fires and flows into the Cast node. The Cast node here checks whether the actor who entered the overlap zone is indeed a FirstPersonCharacter. If it is, then it will fire the top execution pin, else it will fire the Cast Failed and you know that it was someone/something other than the FirstPersonCharacter that entered the overlap zone. I suggest you connect each of those Execution pins to a separate Print String to see what is going on here.

Next get your Enemy from somewhere, and pass it to Pawn pin (You probably do NOT need to Cast it to BP_Enemy if you created it based on Pawn blueprint.). Connect the output pin of your FirstPersonCharacter, i.e. As First Person Character into the Target Actor, and the execution pin as well and things should work fine.

Unreal Engine has a steep learning curve and I suggest you start with basics and learn the fundamental of Blueprints first before trying to build any game or implement any logic. Epic has provided a comprehensive and easy to follow documentation on Blueprints that you can start and read from here

I scrapped what I had and started over trying my best to follow your directions. I feel like I’m just overlooking really stupid things because when it comes to me and programming that’s always the case when something isn’t working.

I should have said this before but here’s what I’m trying to do:

  • I’ve got my FirstPersonBP which is holding a flashlight mesh
  • I then made a BP_FlashlightLight which I added into the FirstPersonBP and mounted it to the flashlight
  • I added a sphere collision to the BP_FlashlightLight where the spotlight radius shines out to

What I want is for that sphere collision to draw enemies to the player when it overlaps them; in other words, if the player is shining their flashlight on the enemy, the enemy should move to the player.

Thank you very much, Vizgin. I appreciate your patience with me. I’ll be sure to come back and update this when I have a chance to implement your suggestions.

I feel like I’m closer, but perhaps I’m confusing my execution sequence a bit?

Then your Other Actor pin that comes out of overlap event is the enemy and you must cast it to BP_Enemy instead of FirstPersonCharacter. If the cast succeeds, connect the As BP Enemy to Pawn, and the execution pin to AIMoveTo. Now you need to get your actor from somewhere. In your case, you can even tell your AI to run toward either the Flashlight or FirstPersonCharacter. Right click and type self reference, and get a reference to self and connect it to TargetActor. If your inside the Flashlight blueprint you’ll get a reference to your flashlight and your AI will run towards the flashlight. If your in your FirstPersonCharacter Blueprint, your AI will run towards your character.

You’re welcome. Please don’t forget to mark the question as SOLVED if your issue has been resolved.

Remove the Flashlight Cast and Light Sphere completely. Connect the overlap execution pin to Cast To BP_Enemy instead.

Unfortunately, it is very hard to assist you with this without having access to the full project or seeing your full actor setup. These are also basic stuff so again, I highly suggest you to start with the fundamentals of Blueprints first.

As for my last comment on your question which will hopefully resolve your issue, if you are inside your FirstPersonCharacter and you have added a collision sphere component to it, then select the collision component, on the right side, in the details panel, scroll down and select something like OnComponentOverlap event. It will take you to the Event Graph and you should now see a new Overlap event node added there. Use that node and its execution pin instead of the current EventActorBeginOverlap node.

Good luck and Hope you get it working. And please don’t forget to mark the question as resolved if you managed to fix it.

It still doesn’t seem to be working. My enemies will just stand there. Is it trying to overlap the root scene which is mounted to the flashlight instead of the collision sphere or spotlight cone? That’s why I was trying to cast it to the LightSphere (collision sphere).

I’ve tried applying the logic to the OverlapComponent event from the LightSphere but that also isn’t working.

I managed to stumble upon just that, though it still wasn’t cooperating. Turns out my Collision sphere needed to be about 100x bigger in order to hit my enemy, which looking at the viewport I would not have guessed would be the case.

Thanks again for your help and patience!

You’re welcome. I’m glad you resolved it and I could help as well.