UMeshComponent specification to Skeletal/Static in children

In my case i try to make a generic UMeshComponent in C++ to further specify whether it will be a Skeletal or a Static mesh in the child classes. (i need half of the children skeletal and half static)

Parent code:

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UMeshComponent* mesh;

Then in a child BP editor, i set the default value to static/skeletal mesh and compile (BP compilation, not C++):

230274-screenshot-2.png

but the compilation resets the default value (type) to None again.

any ideas?

if i set it in C++ constructor like this it does work (but i need it in BP)


 mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("mesh"));

try visibleanywhere

may be TSubclass will help… just guessing

i don’t know how exactly is it relevant to the issue, but anyway it doesn’t work. please delete this answer to attract more views, thank you.

well actually i tried writing that code but its working fine in blueprints here… did you try creating new child BP?

how exactly? as described, C++ version works as it is. The problem is in BP which resets to None on BP recompilation

This is a longstanding blueprint limitation that there is no ideal solution for. An epic staff mentioned wanting to allow this back when I first started using UE4 3 years ago. I wouldn’t hold your breath.

There are various workarounds. The simplest approach is to make your variable VisibleAnywhere, and simply require the component to be added to the child blueprint in the regular way via the AddComponent button. Then in C++ BeginPlay or similar, you find the component using FindComponentByClass (or similar variant) and cache it in your variable for future access. Main drawback to this method is that you can’t cleanly enforce that child blueprints always have the component of an acceptable type added.

It’s possible to go the route you tried with a dropdown instanced property, but it involves kind of going against how the engine deals with components. You need to start overriding PostEditChange to register/unregister the component etc, and there are also potential issues related to construction script like you’ve seen. I’ve found it’s not worth the bother.

good idea. i will try to create a new one and report back with my findings. could be a bugged BP indeed.

thanks for the detailed info, however it is not an instanced property. the dropdown way i try is actually in the child BP defaults (class-wide)
basically overriding

Pretty sure we’re talking about the same thing. All components are marked ‘InstancedByDefault’ and ‘EditInlineNew’, so by making a component property EditAnywhere, you have an instanced property. The issue is that components require special registration, which doesn’t happen automatically when you create it via an instanced dropdown.

hmm interesting. any clues on where can i find more info about registering the components? never heard of this process before.

well nope, doesn’t work.
are you sure you replicate the code correctly?