OnHit Event in 5.1 C++

Is the code around OnHit Event changed in any way in 5.1 compared to UE4?
Asking because I cannot get it working in C++. In Blueprint it works as before.

There have been some changes to the OnHit event in Unreal Engine 5 compared to UE4, but they are mostly related to the physics system and how it handles collisions. The basic structure and usage of the event in C++ should still be the same.

Without more information about the specific issues you are encountering, it’s difficult to say exactly what might be causing the problem. However, some common reasons why the OnHit event might not be working in C++ include:

  1. Missing or incorrect collision settings: Make sure that both the object that is being hit and the object doing the hitting have appropriate collision settings enabled. For example, if you are trying to detect hits between two static meshes, both meshes must have “Simulate Physics” disabled and “Generate Overlap Events” enabled.
  2. Incorrect event binding: Make sure that the OnHit event is properly bound to a function or delegate that is defined in your code. This can be done using the OnComponentHit or OnActorHit functions, depending on whether you are detecting hits on a component or an actor.
  3. Incorrect function signature: Make sure that the function or delegate that you are binding to the OnHit event has the correct signature. The function should take three arguments: the UPrimitiveComponent or AActor that was hit, the AActor that did the hitting, and a FVector representing the location of the hit.
  4. Other code issues: Check for any other code issues in your implementation of the OnHit event. For example, make sure that any variables or references you are using are properly initialized and that any necessary includes or declarations are present.

If you are still having trouble getting the OnHit event to work in C++, you may want to provide more specific details about your implementation and any error messages or logs that you are seeing.

You’re only half right here. Simulate Physics only needs to be enabled on one of the meshes involved in the collision for OnHit to register. Furthermore, Simulate Physics doesn’t even need to be enabled for the actor you’re binding your OnHit function in.

I.e. you have a Pawn. You’re binding your OnHit function to OnComponentHit because you want this Pawn to register hit events. Simulate Physics does not need to be enabled on the Pawn, but any actors you want registering hits on this Pawn will need to Simulate Physics. Or vice versa.