Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

alt text

Product Version: UE 4.10
capture.png (31.7 kB)
more ▼

asked Jan 24 '16 at 06:27 AM in C++ Programming

avatar image

7 4 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first


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.

more ▼

answered Jan 24 '16 at 11:39 AM

avatar image

938 34 27 50

avatar image psychoticpolice Jan 24 '16 at 05:48 PM

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!

avatar image Begounet Jan 25 '16 at 09:29 AM

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

avatar image psychoticpolice Jan 25 '16 at 05:11 PM

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

alt text for now this is working just fine

capture 3.png (12.7 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question