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"

BeginOverlap event, check if Actor is certain class type

My BeginOverlap method:

 void UWall::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResul) {
     if(OtherActor) {
         // Check if OtherActor is a USpaceBall class
         UE_LOG(LogTemp, Warning, TEXT("A"));
         if(OtherActor->IsA(USpaceBall::StaticClass())) {
             UE_LOG(LogTemp, Warning, TEXT("B"));
         } else {
             UE_LOG(LogTemp, Warning, TEXT("C"));

This event fires up when a SpaceBall actor overlaps a UWall actor.

I always see message A and C in the console.

This is the info I get when debugging about OtherActor argument:

alt text

Product Version: UE 4.22
untitled.png (28.6 kB)
more ▼

asked Apr 30 '19 at 01:28 AM in C++ Programming

avatar image

1 1 2

avatar image HarryHighDef Apr 30 '19 at 08:45 AM


 Cast<USpaceBall>(OtherActor) != nullptr
avatar image KlSKE Apr 30 '19 at 01:56 PM

Same result.

avatar image Lardo Deepdelver May 01 '19 at 07:40 AM

any way you can share the project or parts of the project, Cast(OtherActor) != nullptr should work

avatar image HarryHighDef May 01 '19 at 08:20 AM

Your other actor is an actor spaced ball, does it inherit from USpaceBall. Can you show us this code/BP

avatar image KlSKE May 01 '19 at 02:21 PM

Hey there, I think I'm confusing definitions and that's why maybe I'm doing these things in the wrong way, this is how it looks my actor in the scene.

alt text

If I understand correctly now, is my actor just an actor that has a USpaceBall component (ActorComponent) in it?

The following code works because now I'm checking against the USpaceBall component.

 USpaceBall* spaceBallComponent = reinterpret_cast<USpaceBall*>(OtherActor->GetComponentByClass(USpaceBall::StaticClass()));
 if(spaceBallComponent) {
     if(OtherActor == spaceBallComponent->GetOwner()) {
         UE_LOG(LogTemp, Warning, TEXT("Working"));
avatar image Lardo Deepdelver May 01 '19 at 05:45 PM

oopsly, never read the U in USpaceBall yeah that's just a component and you have to test for that

I was thinking that your objects inherits from ASpaceBall and then the whole actor is a subclass of that and can be casted to.

(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