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\$
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\$
  • 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\$ – user3797758 Dec 7 '15 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\$ – user3797758 Dec 9 '15 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\$
  • \$\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\$ – user3797758 Jan 15 '16 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.