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:
- 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.
- 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
orOnActorHit
functions, depending on whether you are detecting hits on a component or an actor. - 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
orAActor
that was hit, theAActor
that did the hitting, and aFVector
representing the location of the hit. - 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.