How to add groomcomponent via c++ and attach it to skeletal mesh

Hi everyone,

I have the problem, that i can not properly use a groomcomponent in c++. I added the module HairStrandsCore to my public dependencies. I declare the variable and Create it:

UPROPERTY(EditDefaultsOnly)
class UGroomComponent* Hair;

Hair = CreateDefaultSubobject(TEXT(“Hair”));

I include the Header file:
#include “GroomComponent.h”

it has a red underline and if I hover over it, it says, can not open source file.

If I compile the code I do not get any errors.
If I try to access the Hair variable like this:
Hair->SourceSkeletalMesh = GetMesh();

The code will not compile anymore saying Pointer to incomplete class type not allowed.

How can I access the my Groom Component?

What am I missing here?

Thanks for your answers.
Greetings, Chris

1 Like

Hi everyone,

I solved it. Just go to the .uproject file and generate project files. This will add the missing dependencies.

3 Likes

I had this problem for UE5.2, but regenerating project files didn’t solve it.

Instead I followed:
NiagaraDataInterfacePhysicsAsset.h and GroomComponent.h in Unreal 5.1

I solved it by adding both “HairStrandsCore” and “Niagara” to “PublicDependencyModuleNames” in my .Build.cs file.