# How to bind to SkeletalMesh-\>GetOnMeshChanged

**URL:** <https://forums.unrealengine.com/t/how-to-bind-to-skeletalmesh-getonmeshchanged/445198>\
**Category:** Character & Animation\
**Tags:** skeletal, unreal-engine, delegates, skeletalmesh, CPP, question\
**Created:** [March 12, 2019, 10:19pm UTC](https://forums.unrealengine.com/t/how-to-bind-to-skeletalmesh-getonmeshchanged/445198 "2019-03-12T22:19:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jm991](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jm991](https://forums.unrealengine.com/u/jm991)\
**Post date:** [March 12, 2019, 10:19pm UTC](https://forums.unrealengine.com/t/how-to-bind-to-skeletalmesh-getonmeshchanged/445198/1 "2019-03-12T22:19:54Z")

</div>

Hi there,

I’m trying to bind a function to [SkeletalMesh OnMeshChanged][1], but I’m having trouble getting my function to bind. My usecase for this function is to be able to update another SkeletalMeshComponent that needs to grab the new skeletal mesh every time the Character’s skeletal mesh is changed.

Here’s what I have in my .h file:

```
public:
    // Editor related code
#if WITH_EDITOR
    UFUNCTION()
    void SetToonSkeletalMesh();
#endif

```

And here’s what’s in my .cpp file (in my constructor):

```
#if WITH_EDITOR
    this->GetMesh()->SkeletalMesh->GetOnMeshChanged().AddUObject(this, &ATdpCharacter::SetToonSkeletalMesh);
#endif

```

and further down in the file, is the implementation of that method

```
#if WITH_EDITOR
void ATdpCharacter::SetToonSkeletalMesh()
{
    ToonOutlineComp->SetSkeletalMesh(this->GetMesh()->SkeletalMesh);
}
#endif

```

This compiles, but the editor crashes immediately on launch. I’m familiar with AddDynamic, but that particular function does not seem to be available here. I wasn’t sure which of these to use (Add, AddUObject, AddUFunction, etc.)

 ![271193-addfunction.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/d/1/5d13983a7722f59aac051220a07d474d11928f02.png)

Does anyone have any pointers on how I can attach my method to the OnMeshChanged event?

---

<div class="post-metadata">

**Author:** ![jm991](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jm991](https://forums.unrealengine.com/u/jm991)\
**Post date:** [March 12, 2019, 10:45pm UTC](https://forums.unrealengine.com/t/how-to-bind-to-skeletalmesh-getonmeshchanged/445198/2 "2019-03-12T22:45:25Z")

</div>

I was also able to do a lambda declaration inline in the .cpp file:

```
    auto OnSkeletalMeshChanged = [this]()
    {
        UE_LOG(LogTemp, Log, TEXT("SkeletalMeshChanged!"));
        ToonOutlineComp->SetSkeletalMesh(this->GetMesh()->SkeletalMesh);
    };

    this->GetMesh()->SkeletalMesh->GetOnMeshChanged().AddLambda(OnSkeletalMeshChanged);

```

This also seems to build fine but crash the editor on start…

---

<div class="post-metadata">

**Author:** ![Elou44](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/elou44/32/738751_2.png) [@Elou44](https://forums.unrealengine.com/u/Elou44)\
**Post date:** [March 13, 2019, 2:27am UTC](https://forums.unrealengine.com/t/how-to-bind-to-skeletalmesh-getonmeshchanged/445198/3 "2019-03-13T02:27:27Z")

</div>

#if WITH\_EDITOR  
this-\>GetMesh()-\>SkeletalMesh-\>GetOnMeshChanged().AddUObject(this, &ATdpCharacter::SetToonSkeletalMesh);  
#endif

is indeed the correct way to bind a function to a multicast delegate but I believe you have to it in the ‘_BeginPlay_’ of your class, not in the constructor.

You can also have a look at the example provided in the [Unreal Engine 4 Scripting with C++ Cookbook](https://books.google.fr/books?id=zZ7cDgAAQBAJ&pg=PA151&lpg=PA151&dq=ue4+AddUObject+in+constructor&source=bl&ots=ZsY51yM3eT&sig=ACfU3U17jfee6yLXR1HjFUjQKTyIqyRadQ&hl=fr&sa=X&ved=2ahUKEwiI26v4hf7gAhVHvxoKHW6pDRYQ6AEwCHoECAYQAQ#v=onepage&q=MyMulticastDelegate.AddUObject&f=false).

Cheers
