CreateDefaultSubobject is supposed to be used in the constructor so the CDO has is set up correctly. You wanna use NewObject for anything that happens on runtime or editor time.
Just call NewObject with your Components and register/attach them manually.
Apparently there’s something I just don’t quite understand, and I’d appreciate if one of you could hear my situation and tell me what I’m falling to understand.
My APlayerCharacter class (APawn) has a pointer to a custom component, PlayerCharacterInventory (AActor). On construction, I CreateDefaultSubobject and this seems to work fine.
My APlayerCharacterInventory class has 5 pointers to skeletal mesh components for headgear, arm gear, etc… On construction, I CreateDefaultSubobject.
My character blueprint, derived of course from APlayerCharacter appears to work great in the blueprint editor. It has spawned the inventory component, inventory component has spawned my gear slots, and my gear slots allow me to spawn my gear meshes correctly.
HOWEVER, when I test this in game, I find that my slots ALL spawn at (0,0,0) regardless of my player’s position.
What am I misunderstanding? Are my components not actually parented correctly? If so, why is it automatically offsetting? And if not, what am I confusing here? As a child, shouldn’t it have the parents location, with offset if specified?
Denny, are you saying I’ll have to use BOTH CreateDefaultSubobject AND New object?
I mean, i have the CreateDefaultSubobject calls in my constructors. My character creates the inventory component, which in turn creates 5 skeletal mesh components. And my character acts fine in the editor, and even at runtime, with the exception of my equipment slots being spawned at 0,0,0.
Denny,
Let me show you my problem right now. It’s a bit different now that I’ve manually attached them. FYI, just moved, no Internet yet so going to have to show 3 screenshots I took with my phone:
I’ve got my inventory component with 5 skeletal mesh components. Only other things are a reference to a data table which houses my item info and a test function for changing armor late . Pretty bare bones.
My character blueprint which is derived from a ACHARACTER custom class contains the inventory component, it listed my equipment slots as None. When I change and compile my changes, it goes back to none.