Problem with collision

Hi all

I have a problem with the event “OnComponentHit”:I have a box that can be destroyed by the player only if the player is near the box and press F.

With the event OnEventCollision setted on the box,the player can destroy the box only if when he collides the box he presses also F for destroy it.

The player must be able to destroy the box,also if he is on the box(when “OnComponentHit” is already ended").

I could work on the location of the player and the location of the box(checked with Tick event),but maybe is the worst way :\

Is there another method to do this?

Thanks :slight_smile:

Hello ,

You could do this by setting a boolean to true/false when colliding with the object and then using that boolean to determine if the F key binding should run its logic or not. The only problem with this method is setting the boolean back it its original value when the collision ends.

I would suggest making a trigger box or any type of trigger volume that is slightly larger than the box as one of its children. With this, you can use OnComponentBeginOverlap and OnComponentEndOverlap instead to set and reset the boolean when these events are triggered.

Hello and thank You for answer.

These boxes are generated dynamically by a blueprint class.

How can I set a trigger volume on actors that are generated dynamically?

Hi
Do you have a specific BP for this actor? If yes, go inside it and add a “BoxTrigger”, use the OnComponentBeginOverlap as said by in the Actor Event Graph and cast to your player, the rest is like said.
Good luck

Hi Filipe and thanks for your help

Sorry if I don’t undestand immediatly but I’m new on Unreal Engine.

This is my situation

Have I to create a new variable (box trigger) and set OnComponentBeginOverlap and OnComponentEndOverlap on it?

The thing you need is a Box Collision component, not a variable. Click the “Add Component” button at the top left, type in “Box” and it should come up. After doing that, make sure you have the component selected in the component list and then right-click in the graph. You should be able to add the OnComponentBeginOverlap and OnComponentEndOverlap events from the context menu that appears.

If you have problems getting these events to trigger, ensure that “Generate Overlap Events” is checked in the details panel for both the Box Collision component and the other actors that will be overlapping it.

Well I 've done like You said,but as I set the behavior of OnComponentBeginOverlap is the same of OnComponentHit

your BP got me a little confuse. Did you try something like this?

So, if you Press “F” the actor will be destroyed only if the character is inside the Box collider

I’ve tried out your scheme,but it seems that the variable candestroy after taking a value of true, false returns immediately.

Can we see how you have this all set up in the viewport? There could be some stuff there that we’re not understanding.

Of course
This is the BP DynamicBox

And this one is the character

I’ve added a custom event called DestroyBox=Press E.
I’ve tried to use the DestroyBox in DynamicBox but doesn’t work.
There is another blueprint class that generate boxes in an small volume,but I think that is not the problem.

With this set up, is that F event in DynamicBox ever actually being fired? By default, the DynamicBox isn’t what you’re possessing so it shouldn’t be receiving the input. This should work instead.

First, create two variables on your ThirdPersonCharacter. The first is a boolean to track if the player is overlapping. The second is a reference to a DynamicBox actor (MyBox in my example)

After that, set up the following nodes in DynamicBox.

This sets it up so that the character will know if it is overlapping and what it is overlapping.

Next, we set up the F key event inside the ThirdPersonCharacter blueprint.

This first checks to see if the ThirdPersonCharacter is overlapping the box. It then destroys the box using the reference and then clears that reference (since OnComponentEndOverlap never gets called since the actor has been destroyed). If it fails, it simply prints “Not Overlapping Anything”.

Hope this helps!