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

**URL:** <https://forums.unrealengine.com/t/how-to-add-groomcomponent-via-c-and-attach-it-to-skeletal-mesh/605506>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 15, 2022, 10:52am UTC](https://forums.unrealengine.com/t/how-to-add-groomcomponent-via-c-and-attach-it-to-skeletal-mesh/605506 "2022-07-15T10:52:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LzBOM1517](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LzBOM1517](https://forums.unrealengine.com/u/LzBOM1517)\
**Post date:** [July 15, 2022, 10:52am UTC](https://forums.unrealengine.com/t/how-to-add-groomcomponent-via-c-and-attach-it-to-skeletal-mesh/605506/1 "2022-07-15T10:52:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LzBOM1517](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LzBOM1517](https://forums.unrealengine.com/u/LzBOM1517)\
**Post date:** [July 15, 2022, 11:53am UTC](https://forums.unrealengine.com/t/how-to-add-groomcomponent-via-c-and-attach-it-to-skeletal-mesh/605506/2 "2022-07-15T11:53:59Z")

</div>

Hi everyone,

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

---

<div class="post-metadata">

**Author:** ![scttlsk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@scttlsk](https://forums.unrealengine.com/u/scttlsk)\
**Post date:** [September 7, 2023, 5:05pm UTC](https://forums.unrealengine.com/t/how-to-add-groomcomponent-via-c-and-attach-it-to-skeletal-mesh/605506/3 "2023-09-07T17:05:28Z")

</div>

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](https://forums.unrealengine.com/t/niagaradatainterfacephysicsasset-h-and-groomcomponent-h-in-unreal-5-1-header-not-found/718705/2)

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