Hello, I’m another Unity guy trying things out in Unreal.
I’m trying to understand some of my issues, and it feels like I’m missing something very fundamental that my experimentation hasn’t yielded to me yet.
In this example, I have a C++ class called RtUnitBase
. It’s a very simple class that inherits from ACharacter
. In my constructor I create a default sub object for the Root.
ARtUnitBase::ARtUnitBase() : Super()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
}
Then I create a derived Blueprint so that I can play with visuals, like the skeletal mesh and capsule that is automatically created by ACharacter
. My understanding is that because I set the Root component, all the derived Components would be attached to it as well, and Blueprint seems to back that.
vs when I don’t create the RootComponent in my class:
Now when I start the game in editor, however, the derived components from ACharacter
, (The Capsule, Mesh, and Movement components), are NOT attached to the Root component anymore.
This leads to the Mesh, Capsule, and Movement components being at the origin in world space, while my Actor is at whatever location I’ve specified. If I remove the RootComponent creation in my class constructor, they will all be appropriately attached to the actor’s root component and will look correct, though the Root Component for the Blueprint will be the Capsule component, and I can’t attach any other components to it.
NOTE: I have been doing all the changes to the C++ classes when the editor is closed to avoid as many of the CDO corruption bugs as I can, (how do people live with these issues?! I must be missing something, but it seems like if you change the C++ class at all while the editor is running my Blueprints get corrupted and I have to recreate them from scratch.)
So my question is: What the hell am I supposed to do? I want the root component to be a SceneComponent so I can attach other components to my units, (weapons, particle effects, etc), and attach other actors, (my custom camera). Should I be doing something else entirely? Should my unit have a “has-a” relationship with the character instead of a “is-a” relationship?
Any and all feedback/criticism is welcome, treat me like an idiot.