Making RootComponent Editable & Attaching SceneComponents Correctly

Hello everyone, I am new to unreal development but not to c++ and I will probably come some now and then and post some questions so I will already thank you all in advance for your patience. I also want to say that I always try to find the answers somewhere else first.

Lets start with the first 2 questions:

  1. How can I make the RootComponent to be editable if I extend an actor from c++ as in class A : public AActor. If I go to the editor after compiling I can not change the Position/Rotation/Scale nor make it static or movable when I select the RootComponent item in the hierarchy. How can I enable that? I fixed it by just creating a local USceneComponent and using it as root but I wonder if other variables I can do the same. The code is below.
-- A.h
class A : public AActor
{
public:
     A();
     UStaticMeshComponent *Mesh;
     ...
}
-- A.cpp
A::A()
{
    Mesh = CreateDefaultSubobject(...);
    Mesh->SetupAttachment(RootComponent);
    ...
}

You can see the grayed out Mobility, Location, Rotation and Scale with ‘Native components are editable when declared as FProperty in C++’. If I just create a normal AActor I can normally edit the grayed out area. Why if I extend I cant suddenly? I thought those settings would also be inherited.

  1. I have an SceneComponent variable in another class. I want this SceneComponent when initialized to have another SceneComponent attached to it. A more concrete example is if I have those classes:
-- A.h
class A : public ACharacter // Player class
{
public:
     A();
     B variableB;
}
-- A.cpp
A::A()
{
    variableB = CreateDefaultSubobject(...);
    variableB->SetupAttachment(RootComponent); // Here I am assigning the RootComponent, not 'this' pointer
                                               // which I know is the correct way to do.
}
-- B.h
class B : public USceneComponent // Hand class
{
public:
    USceneComponent C; // Position where object should be when hand is grabbing
                       // I am creating this on the constructor shown below.
    B();
}
-- B.cpp
B::B()
{
    C = CreateDefaultSubobject<USceneComponent>(...);
    C->SetupAttachment(this); // This line here does not work. I assume that this is some unreal
                              // builder/composer something.
                              // How can I achieve the same behaviour as in the constructor of
                              // A, SetupAttachment(RootComponent)?
                              // I want C to be a child of B.
}

Why this doesnt work?

In your header, you need to use a decorator above the static mesh declaration:

Ex.

UPROPERTY(EditAnywhere)
UStaticMeshComponent *Mesh;

The UPROPERTY macro tells the engine how to handle the variable in the editor. It also tells the engine not the garbage collect the pointer.

More information on those decorators:

1 Like

Hey, thanks for the reply.

I indeed forgot to place the UPROPERTY there in my question but it is in my code, but thats not the issue. You can see I have selected the RootComponent, not the StaticMeshComponent in the image.

I can edit just fine the UStaticMeshComponent, I cannot edit the RootComponent. This below is what I currently have.

-- InteractableDoor.h
private:
	UPROPERTY(EditAnywhere, meta = (DisplayName = "RootComponent", EditCondition = "false"))
	USceneComponent *DoorRootComponent = nullptr;

	UPROPERTY(EditDefaultsOnly)
	class UStaticMeshComponent *StaticMesh = nullptr;

I can edit the UStaticMeshComponent, but I had to create a DoorRootComponent because if I didnt, the image in the original post shows grayed out.

Best,

Your response is very frustrating. By not showing your actual implementation in the first place, anyone trying to help has to waste time searching for issues that might not even exist.

If you still want help:

  • Restate your question. Be clear with your problem statement and expected behaviour
  • Include the full code (header and implementation) that reproduces your problem
  • Narrow down your question to a single problem, if possible

Hi,

Thanks for the reply again.

I agree that I should have placed two separate questions. I will do it next time.

But I have to disagree with you about my questions are not clear. The relevant information is there all along in the first post if you had read my question correctly.

  1. The first question was about the RootComponent, not MeshComponent. The UPROPERTY over the MeshComponent is irrelevant.
  2. I showed a picture where the RootComponent is clearly selected and grayed out.
  3. In the code snippet I only wanted to make explicit that the RootComponent is the one that is declared in AActor class and is available to class A because it extends from AActor.

Again, I appreciate that you tried to help and it is fine if you didnt read it well but this last response complaining that an irrelevant part of the code was not there was not necessary.

For your points:

  • Of couse I still have those questions. I explained with a code snippet, a picture and text. What should I do to state it properly in your view?
  • The relevant code is in there. Simple class that extends AActor.
  • The problem is right after: Cant edit RootComponent from class A if it extends publicly from AActor.

The static mesh component was an example. That’s what Ex. means. In your original question, that you have now modified 5 times, further adding to this mess of a question, you listed many things in your header that did not have the UPROPERTY macro, so I used the static mesh component as an example.

You stated, “The relevant information is there all along in the first post if you had read my question correctly”, but it was not listed in the first post. The important information was listed in your second post. You only provided an abstraction of your code in your first post.

I do not like your tone and I can read just fine. Good luck on solving your problem without my help.

Hi,

Thanks again for your reply.

I want to first say I never said you can not read, simply pointed out that in this particular case and based on your answer you probably looked only at the Ex and the title.

Again, the question is about the RootComponent from AActor, nothing related to any object that is declared on class A. So anything after class A : public AActor { and before }; is irrelevant. So yes, my second post is irrelevant to my question.

I edited my first post 5 times in order to try to make it more and more clear, so no problem there :slight_smile:.

And last, I am just asking a couple of questions. If someone tries to help I appreciate it. I explained the best I could with the time I had but of course it can always be better.

Thanks for your help. I will try to take your advices for the next post I make.