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"

Get Instance from LineTrace HitResult

am working an Attack function that works by using a ShapeTrace to map out a volume and return the Actors is collides with. My goal is to be able to call the classes derived from the actors that collided with the Trace and trigger some functionality specific to that actor, i.e. if destructible, destroy it or make it invisible.

Currently I am able to map out the shape trace from a button mesh and get a FHitResult that returns the Actors information but I want to get the instances class that is derived from that Actor.

 bool isHit = GetWorld()->SweepSingleByChannel(SweepResult, Start, End, FQuat::Identity, ECC_GameTraceChannel1, Shape, CollisionParams);
     if (isHit) {
         if (SweepResult.bBlockingHit) {
             if (GEngine) {
                 GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Red, FString::Printf(TEXT("You are hitting: %s"), *SweepResult.GetActor()->GetName()));
             ADestructableBox* PointerToObjectThatWillMakeFunctionCall = Cast<ADestructableBox>(SweepResult.GetActor());
                 UE_LOG(LogClass, Log, TEXT("Cast Succeeded"));
             else {
                 UE_LOG(LogClass, Log, TEXT("Cast Failed"));

I am aware that in blueprints you can cast an Actor to its derived class using the "Cast To ()" node and I am looking for a solution in C++, due to my casting constantly failing.

Also I am aware of the spelling error with the Casting Class

Product Version: UE 4.18
more ▼

asked Oct 21 '18 at 10:17 PM in C++ Programming

avatar image

3 1 2

avatar image Ali Akbar Oct 22 '18 at 03:30 PM

Try debugging the returned actor class. Print out the class of the hit actor : PointerToObjectThatWillMakeFunctionCall->GetClass()

Maybe you are hitting the player character and need to adjust the start?

avatar image CoffeeLocke Oct 22 '18 at 11:39 PM

Thank you! This was an oversight when I realized the starting vector was still inside the Players Capsule and I was using single instead of multi.

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

0 answers: sort voted first
Be the first one to answer this question
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