x

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"

[C++] Making a custom colliding pawn

I'm struggling to find any information on how to make a custom pawn collidable. As far as I've understood, the easiest way of making pawn colliding with other actors( i.e. walking on ladders, or getting blocked by walls) is to use OnActorBeginOverlap, so do I. I've created a basic function to check if colliding is detected at all, it creates a sphere when collision with other actor happened.

 void ACustomProtogonist::OnOverlapBegin(class AActor* OtherActor)
 { 
     if (OtherActor && (OtherActor != this))
     {
         //Spawn a new component  
         UStaticMeshComponent* VisualComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualComponent")); 
         static ConstructorHelpers::FObjectFinder<UStaticMesh> VisualComponentAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
         if (VisualComponentAsset.Succeeded())
         {
             VisualComponent->SetStaticMesh(VisualComponentAsset.Object);
             VisualComponent->SetRelativeLocation(FVector(0.0f, 0.0f, -90.0f));
             VisualComponent->SetWorldScale3D(FVector(0.7f));
         }
     }
 }

Unfortunately it doesn't work. I can't figure out if it collides at all. I've used

 this->OnActorBeginOverlap.AddDynamic(this, &ACustomProtogonist::OnOverlapBegin);
  SetActorEnableCollision(true);

beforehand.

Product Version: UE 4.9
Tags:
more ▼

asked Sep 02 '15 at 03:23 PM in C++ Programming

avatar image

Unteroid
74 12 17 23

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

1 answer: sort voted first

Honestly, if you want collision it will be way easier to just make a blueprint that inherits from your C++ class. Rolling your own will just give you headaches in the long run. It is trivially easy to handle this with blueprints, and doesn't really have much more overhead than using just a C++ class, and you'll save that overhead by not having a convoluted way of dealing with collision.

If you are dead set on doing it yourself, you'll need to enable collision on your actor, attach a collider to your actor, and assign that collider some collision properties using SetCollisionEnabled or SetResponse. I can not recommend avoiding this enough though.

more ▼

answered Sep 02 '15 at 04:14 PM

avatar image

mrooney
703 40 31 123

avatar image Unteroid Sep 03 '15 at 05:34 PM

Thanks, Sir. The hardest part for me right now is to understand where C++ should be used and where it shouldn't. Mostly people say C++ isn't needed right now at all.

avatar image mrooney Sep 04 '15 at 02:02 PM

Yea, it can be tricky. My rule of thumb is in general anything that you see in the game should have a blueprint. If you want to implement it in C++, then make it a blueprint that inherits from a custom C++ class. If it's not actually visible in the game, you kind of have to guess. If the class leans heavily on engine functionality over your own implementation, I'd probably make a blueprint for it though.

On our project we tend to do a lot of Blueprint inheriting from a C++ base class to keep as much functionality as possible in C++. That's mostly just for consistency. I think if I were starting fresh I'd probably try 100% blueprints and only do C++ implementation when there were either performance or functionality reasons to. It's always easy to convert blueprint to C++ later because they're almost 1:1 as far as general flow goes.

(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