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"

Regarding actor movement and Root Components

In most of the tutorials I have seen, an empty scene object is used as the Root Component of many actors. I am wondering how should I correctly be moving my actors if my other components are attached to the root, this is my current hierarchy:

 if (!RootComponent)
 {
     RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root Component"));
 }
 
 PaddleMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Paddle Static Mesh"));
 PaddleMeshComponent->SetupAttachment(RootComponent);

I have a static mesh which is attached to an empty scene object. I am adding forces to this actor like so:

 PaddleMeshComponent->AddImpulse(CurrentVelocity, NAME_None, true);

Is this correct?

The reason I ask is because I am currently trying to get a ball actor to follow a paddle actor before the ball is launched, but the ball remains in place and does not move with the following code:

 if (!bIsLaunched)
 {
     BallMeshComponent->SetWorldLocation(Paddle->GetTargetLocation());
 }

However, the ball will follow the paddle if I remove the empty scene component from the paddle and set the static mesh component as the root like so:

 PaddleMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Paddle Static Mesh"));
 RootComponent = PaddleMeshComponent;

I feel like something I'm doing wrong is incorrect, am I correctly setting Root Components? Do I have my movement logic wrong? Any insight would be appreciated.

Product Version: UE 4.21
Tags:
more ▼

asked Mar 13 '19 at 06:37 PM in C++ Programming

avatar image

JayFitz91
1 3 1 5

avatar image Crowley Caine Mar 13 '19 at 08:34 PM

Why do you need a scene component as root? What are you using it for?

avatar image JayFitz91 Mar 13 '19 at 09:34 PM

I've read that the best practice is to make a scene component as root, just as a container to hold all other components. Would you recommend setting the static mesh component as the root?

avatar image Crowley Caine Mar 13 '19 at 09:57 PM

Well just speaking from looking at actual assets from epic, they themselves don't use scene components as root as far as I've seen.

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

1 answer: sort voted first

A good point was made by Crowley Caine, after checking some of the pre-delivered templates, Epic don't appear to use the empty Scene Component as the root.

But I believe the issue I had here was that I was setting the BallMeshComponent Location to the RootComponent of the Paddle, but the paddle movement is done on the PaddleMeshComponent and not the Root, so the code was behaving as expected.

What I should have been doing was setting the ball movement to the PaddleMeshComponent (as this was the actor that moves, not the root) so by changing the code from

 BallMeshComponent->SetWorldLocation(Paddle->GetTargetLocation()); // uses the root of the paddle

to

 BallMeshComponent->SetWorldLocation(Paddle->PaddleMeshComponent->GetComponentLocation()); //uses the paddle mesh component

The ball now moves with the paddle as expected.

more ▼

answered Apr 20 '19 at 12:14 PM

avatar image

JayFitz91
1 3 1 5

(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