Download

Box collision inside another one

Hi,

Is it possible to trigger the “End Overlap” event from box 1 when I enter box 2? (see screenshot below). The idea is as follows: the player enters the large area and obtains an effect, then when he enters the small box he obtains another effect, the old one being deleted. When it goes out of the small box, it will lose the effect of the small box and regain the effect of the large box.

So I have no problem getting the effect of each box, but I cannot remove the effect of the big box when I enter the small one (because the “End Overlap” event is not not called).
Anyone have any idea how to do this?

Thanks in advance.

Nope, you can’t do it like that, because they are still in the large box, so haven’t ended overlap.

I’m going to work on the assumption this is just boxes in the world ( rather than BP components ). I think maybe the easiest way to do it ‘in the world’ is to destroy the outer box when you go into the inner box, and the spawn a new one when you leave the inner box. Not too pretty, right.

Another way ( easier I think ), is to make a BP to do this. In the BP you can make 4 boxes to surround the smaller box ( all boxes are made by clicking on the green ‘Add component…’ top left and choosing collision component ). The outer 4 boxes you can catch all in one go just using the OnBeginOverlap event. For the small inner box, right click on it and look for ‘begin overlap’. That way you can add a special overlap event just for that box.

I hope I explained that ok, not at a machine right now, so can’t draw anything…

You could add a custom event to call the larger box’s EndOverlap code from BeginOverlap on the smaller box (using the ‘priority’ property if needed). Overall, placing active code in custom events which can then be called from any Begin / End Overlap event will make this easier to figure out imo, as it has more to do with ‘game states’ than anything else…

There’s also hybrid options to look at, like using one large box, plus line-traces or the widget-interaction-component (WIC), or a box attached to the player, to trigger the secondary or subsequent events etc. Suggesting the others, as in-game under certain game lighting and certain backgrounds, it can be tricky to gauge actual collision (after activating ‘show collision’ etc).

Thank both of your for your answers.

I actually thought of removing the big box but it seems to me rather improbable that it is the most … drinkable solution I would say.
The idea of the 4 small boxes intrigues me but it poses a concern: if the player enters the box, there will be the activation of the effects (via the event “OnBeginOverlap”) but there will also be the end of effects (via the “OnEndOnverlap” event), unless I didn’t understand the way you present the thing.

Hm indeed it’s a good idea but the concern would then come from the fact that if I go out of the small box, I will no longer get the “OnBeginOverlap” event from the big box because I did not get out of it, and I will not regain its effects.

I also thought of this principle: whether it be via the “OnBeginOverlap” or “OnEndOverlap” event, calling a function which first removes the effects then applies the effects of the current box. I think I can recover the box via the “Get Overlapping Components” function that takes the player’s character as parameter. What do you think about this alternative ?

You don’t necessarily need it… You can use the EndOverlap event of the smaller box to imply you’re now inside the larger box. It won’t work obviously if some part of the smaller box lies outside the larger one. But from the image above it should work. But I prefer your alternative approach. Its more reliable code, that you control!