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"

How to properly enable physics in C++

Hi, I'm very new to unreal engine, so I have a simple question. I'm trying to enable physics on a object that has mesh loaded in the constructor, this is the code I use (based on tutorials):

// Sets default values AShape::AShape() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true;

 UStaticMeshComponent* shape = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Shape"));
 static ConstructorHelpers::FObjectFinder<UStaticMesh> shapeAsset(TEXT("/Game/Shape01"));
 if (shapeAsset.Succeeded())
     UE_LOG(LogTemp, Warning, TEXT("Asset found"));
     shape->SetRelativeLocation(FVector(0.f, 0.f, 0.f));
     UE_LOG(LogTemp, Warning, TEXT("Asset NOT found"));


The mesh is properly loaded, but physics is not enabled. I can still enable the physics manually in the editor, and then it works, but I create objects like these procedural I cannot rely on that. Any idea what i'm doing wrong? Thank you!


Product Version: Not Selected
more ▼

asked Apr 25 '15 at 10:06 PM in C++ Programming

avatar image

391 36 36 80

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

1 answer: sort voted first

Hello, BramV

In this situation, please check whether your StaticMeshComponent has been initialized correctly. Also note that in order for physics to work, collision component should be implemented properly too, which means it has an adequate shape and size. This is especially important if you are using a specific mesh object. In this case it is more convenient to add collision in the editor.

There are also different kinds of collision responses in Unreal Engine 4, which means there are different ways collision objects can interact with each other.

If you like to learn more, please check this reference on collision https://docs.unrealengine.com/latest/INT/Engine/Physics/Collision/Reference/index.html

Hope this helped! Cheers!

more ▼

answered Apr 28 '15 at 02:02 PM

avatar image

1.8k 76 19 143

(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