6
\$\begingroup\$

I've been looking for how to figure out when two objects are colliding all day.

If anyone knows how to do it I would be grateful. What I really want is a similar function to Unity's OnCollisionEnter() and a way to get a pointer to the object that I'm colliding with.

\$\endgroup\$

3 Answers 3

6
\$\begingroup\$

I'm not familiar with unreal-4, but perhaps you are looking for OnActorBeginOverlap?

Relevant documenation: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/OnActorBeginOverlap/index.html

The remarks say:

Called when another actor begins to overlap this actor, for example a player walking into a trigger. For events when objects have a blocking collision, for example a player hitting a wall, see 'Hit' events.

Components on both this and the other Actor must have bGenerateOverlapEvents set to true to generate overlap events.

Or perhaps you DO need Hit events:

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Events/index.html#eventhit

This event will execute as long as the collision settings on one of the Actors involved have Simulation Generates Hit Events set to true.

Maybe posting your question on an unreal-4 forum would yield more specific answers. Sorry I can't be more helpful.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Well I tried this after looking at your comment and I can't get the code to trigger. It is probably something stupid that i'm doing because i'm not the good with UE4 (yet :)). I have a collision mesh but nothing happens... Do i have to tell the engine what to call or is this called automatically (which is what i assumed)? \$\endgroup\$ Commented Dec 7, 2015 at 19:34
  • 1
    \$\begingroup\$ Ok, this kind of worked what it turned out to be was that i needed another collision mesh around my other mesh which would then trigger this function. Yeah, really not that good with UE4... :) Thanks \$\endgroup\$ Commented Dec 9, 2015 at 19:59
1
\$\begingroup\$

I don't want to replicate Steven's answer, but I want to include images.

The correct answer is to use OnActorBeginOverlap, as you were marked to. If you are not receiving the correct triggering dispatch, it's almost sure that you don't have the correct layering configuration.

You can do that using the Collision subpanel in the Details panel of your object as is shown in the image from below. This also applies if you are trying to configurate the collision of an element inside a blueprint.

Collision Setup in the Details panel

If you want to handle the event in Blueprints, you can do this, as described in the documentation

enter image description here

If what you need is to handle the collision from C++ and configure the layering, then you can refer to this page in the documentation, where you can find a good example.

EXAMPLE OF COLLISION MANAGMENT IN C++ FOR UE4

\$\endgroup\$
1
  • \$\begingroup\$ As i commented above i just hadn't added a collision mesh to my object which was why OnActorBeginOverlap wasn't being called (yes a very beginner mistake) \$\endgroup\$ Commented Jan 15, 2016 at 11:31
0
\$\begingroup\$

OnComponentHit is equivalent unity OnCollisionEnter

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Can you expand your answer by including some additional information or a link to the official documentation? \$\endgroup\$
    – liggiorgio
    Commented Jun 13, 2021 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .