Set default component values in SceneComponent vs in parent actor constructor

I’d like to set default values for a USceneComponent in the component instead of the C++ actors that uses that component (in contrast, in blueprints it works as intended). Is this possible?

Example

In the constructor of MyScComp : public USceneComponent I set SetVisibility(false);. However when looking at an instance of MyScComp in the UE editor details panel, then Rendering → Visible is still set to true by default.

Furthermore when attaching the Component to a C++ pawn and setting the visibility there (e.g. MySceneComponent->SetVisibility(false);), then the UE editor details panel reflect that setting (Visible default: false).

Is SetVisibility(false); restricted to be set only in the C++ pawn and not the SceneComponent itself? (in contrast, when using the SceneComponent in a blueprint pawn, then setting visibility in the SceneComponent works as expected)

Hey Roi-

After using SetVisibility(false); in your constructor, do you see a yellow arrow next to the Visible option in the component’s details? This is the behavior I’m seeing which indicates that the default value has changed and clicking the yellow arrow will reset the option to your new default (false in this case). If you add another instance of your scene component to the blueprint, it too should be showing your default value as expected. Let me know if you’re experiencing different behavior.

Hello Doug,

thanks for the reply. I’ve checked the “yellow default arrows” before asking the question. :slight_smile: When adding a new instance of the SceneComponent to a Blueprint pawn, then visible is set to false per default, as expected.

However when attaching the SceneComponent to a C++ pawn using C++ (in the pawns constructor CreateDefaultSubobject<USceneComponent>(TEXT("MyScComp"))) and then instancing that C++ pawn, then visible for that SceneComponent is true (by default) - so SetVisibility(false) in the SceneComponent constructor seems to be overwritten or not being invoked.

Though setting this (again) in the pawns constructor helps, it is not how I intended to set the SceneComponent properties.

Where in your Scene Component class are you calling SetVisibility(false);? I tried creating a scene component class and a pawn class that I added my scene component to through code. When I placed an instance of the pawn class in the level, visibility was set to true as expected. However, after adding SetVisibility(false); to the MySceneComponent constructor and compiling the code again, the visibility setting for the scene component on the pawn in the level was updated properly.

From your example code there, you’re instantiating a SceneComponent, not your child MyScComp class.

 (CreateDefaultSubobject<USceneComponent>(TEXT("MyScComp"))

 vs 

CreateDefaultSubobject<MyScComp>(TEXT("MyScComp"))).

Is that just a mistype in the post, or is that actually what’s in the code?

you’re instantiating a SceneComponent, not your child MyScComp class.
Thanks for the hint, this was the cause!

Now it works exactly as expected and as Doug described. :slight_smile: Sorry for the trouble!

Setting default values for component properties works by setting them in the component constructor as well as setting them in the parent actor constructor.

The error in my case was, that I set the wrong class when using

CreateDefaultSubobject<>()

I used the parent USceneComponent instead of MyScComp. Thanks to Teiwaz and Doug!