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"

SetRelativeLocation not working correctly

I have a .cpp with fragment of possibly-not-working code in initializer of the class (which is APawn):

 APawn_::APawn_()
 {
     PrimaryActorTick.bCanEverTick = true;
 
     innerCircle = CreateDefaultSubobject<UStaticMeshComponent>("inner");
     innerCircle->SetStaticMesh(
         (ConstructorHelpers::FObjectFinderOptional<UStaticMesh>(TEXT("/Game/Flying/Meshes/Player_ShpereArc.Player_ShpereArc"))).Get()
         );
     innerCircle->SetCollisionEnabled(ECollisionEnabled::NoCollision);
 
     collider = CreateDefaultSubobject<USphereComponent>("collider");
 
     outerCircle = CreateDefaultSubobject<UStaticMeshComponent>("outer");
     outerCircle->SetStaticMesh((ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("/Game/Flying/Meshes/Player_Box001.Player_Box001"))).Object);
     outerCircle->SetCollisionEnabled(ECollisionEnabled::NoCollision);
 
     RootComponent = collider;
     //collider->SetRelativeLocation(FVector::ZeroVector);
     innerCircle->SetRelativeLocation(FVector::ZeroVector);
     outerCircle->SetRelativeLocation(FVector::ZeroVector);
     collider->SetSphereRadius(75.f);
     collider->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
     collider->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
     collider->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
     collider->SetSimulatePhysics(true);
 
 }

I need to simply move innerCircle and outerCircle (static meshes) to (0,0,0) relative to root (what is sphere component). But some magic happens and when I start game the pawn spawns and meshes is in center of the map, but the root is there where it spawned. Even if i move code with SetRelativeLocation to Tick function it will not work fine. Game will move meshes only when i click on object (and select it). Overwise AddRelativeRotation is working in Tick correctly in every frame. How does SetRelativeLocation work? What i missed?

Product Version: Not Selected
Tags:
more ▼

asked Mar 06 '15 at 05:56 PM in C++ Programming

avatar image

HungryDoodles
495 29 24 40

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

1 answer: sort voted first

Solved it (just set variable AttachParent):

 APawn_::APawn_()
     {
         PrimaryActorTick.bCanEverTick = true;
     
         collider = CreateDefaultSubobject<USphereComponent>("collider");
     
         RootComponent = collider;
         
         innerCircle = CreateDefaultSubobject<UStaticMeshComponent>("inner");
         innerCircle->SetStaticMesh(
             (ConstructorHelpers::FObjectFinderOptional<UStaticMesh>(TEXT("/Game/Flying/Meshes/Player_ShpereArc.Player_ShpereArc"))).Get()
             );
         innerCircle->SetCollisionEnabled(ECollisionEnabled::NoCollision);
         innerCircle->AttachParent = collider;
     
         outerCircle = CreateDefaultSubobject<UStaticMeshComponent>("outer");
         outerCircle->SetStaticMesh((ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("/Game/Flying/Meshes/Player_Box001.Player_Box001"))).Object);
         outerCircle->SetCollisionEnabled(ECollisionEnabled::NoCollision);
         outerCircle->AttachParent = collider;
     
         //collider->SetRelativeLocation(FVector::ZeroVector);
         collider->SetSphereRadius(75.f);
         collider->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
         collider->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
         collider->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
         collider->SetSimulatePhysics(true);
 
     innerCircle->SetRelativeLocation(FVector::ZeroVector);
     outerCircle->SetRelativeLocation(FVector::ZeroVector);
     }

But i still don't understand why component of this actor suddenly attaches itself to root when i clicking on them in editor?

more ▼

answered Mar 07 '15 at 11:48 AM

avatar image

HungryDoodles
495 29 24 40

avatar image MrMoose2342 Mar 10 '16 at 09:36 AM

Just stumbled across the same thing. Thanks for that answer!

(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