Comparing two consective hit results (frames)

Hello, So i have a FHitResult working. I have a reliable hit detection method. However my method is working for every frame. I would like to be able to compare the first Hitresult with the next. If they are the same, i don’t want to do damage, however if different then deal said damage. I have tried creating a FString array, which i then add the HitResult.GetComponent()->GetName()) on one frame. Then on the next frame add the next hit result. Then comparing the two like if(Hitresult[current] != HitResult[before]). But it won’t work. Sometimes it will crash on collision too.
Please any help would be greatly appreciated

75712-capture.png

Hello,

It may crash when the GetComponent return null.
Instead of using FString, you can keep a reference on the object you collide (so have an array of Uobject* or Uactor* or Uactorcomponent*) to make sure you do not have a conflict with the names. When you will make the check to see if a collision already happened, you should use IsValidLowLevel () to be sure that the object/actor/component has not been destroyed during this frame. If it is the case, remove it from your array.
Eventually, the best will be to use an array of Tweakobjectptr. This special pointer will tell you if the object is being destroyed AND if the object has been destroyed.

Woke up, and tried this solution, but i still get crashing. I changed the Tarray to AActors, Can you explain the TweakobjectPTR in more detail please, im going to try the valid low level next instead of !=. ill let you know how it goes thanks again!

Here is an example of implementation with TWeakObjectPtr.

// class
TArray<TWeakObjectPtr<AActor>> ActorsToIgnore;

// in the hit result check function
// Remove destroyed/nulled actors - if the actor has been destroyed or is being destroyed, the Actor.IsValid() will return false.
ActorsToIgnore.RemoveAll([](const TWeakObjectPtr<AActor>& Actor) { return (!Actor.IsValid()); });

// Check if the actor is valid
if (hitResult.Actor != nullptr)
{
	if (!ActorsToIgnore.Contains(hitResult.Actor))
	{
		// Do some special stuff for first collision with this actor
		ActorsToIgnore.Add(hitResult.Actor);
	}
}

Ohhh okay i get it now. Will be useful in a future endeavor,

75909-capture+3.png

for now this is working just fine