# How can I get skeletal mesh animinstance and then cast it using code?

**URL:** <https://forums.unrealengine.com/t/how-can-i-get-skeletal-mesh-animinstance-and-then-cast-it-using-code/283271>\
**Category:** Character & Animation\
**Tags:** unreal-engine, CPP, Blueprint, question\
**Created:** [May 13, 2014, 11:23pm UTC](https://forums.unrealengine.com/t/how-can-i-get-skeletal-mesh-animinstance-and-then-cast-it-using-code/283271 "2014-05-13T23:23:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_3115d24a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3115d24a](https://forums.unrealengine.com/u/anonymous_user_3115d24a)\
**Post date:** [May 13, 2014, 11:23pm UTC](https://forums.unrealengine.com/t/how-can-i-get-skeletal-mesh-animinstance-and-then-cast-it-using-code/283271/1 "2014-05-13T23:23:11Z")

</div>

![6223-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/c/b5c55f830e7a5650cfbc64ad6808595afe7fe162.png)

I want to create basically a copy of this in code. I can get all the way to the Get AnimInstance part but cannot figure out which class to cast to to get the functionality of the cast in blueprints. Thank you for any help you can give you

```
	/*what do i put here for type*/ *animInstance = Cast</*again*/>(mesh1P->GetAnimInstance);

```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 13, 2014, 11:30pm UTC](https://forums.unrealengine.com/t/how-can-i-get-skeletal-mesh-animinstance-and-then-cast-it-using-code/283271/2 "2014-05-13T23:30:36Z")

</div>

#Basic

```
//default anim class
if(mesh1P)
{
  UAnimInstance* Animation = Cast<UAnimInstance>( mesh1P->GetAnimInstance() );
  if(Animation)
 {
   Animation->Yay();
 }
}

```

#Your Own Anim Instance Class

```
UMyAnimInstance* Animation = Cast<UMyAnimInstance>( mesh1P->GetAnimInstance() );
 if(Animation)
 {
   Animation->Yay();
 }

```

#My UE4 C++ Tutorials on Custom Anim Instance

**wiki 1**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

**wiki 2**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![TiagoLing](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TiagoLing](https://forums.unrealengine.com/u/TiagoLing)\
**Post date:** [July 23, 2015, 10:06pm UTC](https://forums.unrealengine.com/t/how-can-i-get-skeletal-mesh-animinstance-and-then-cast-it-using-code/283271/3 "2015-07-23T22:06:02Z")

</div>

I’m trying to do the same, based on your tutorials but i always get the AnimInstance as null - what am i missing?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f2fa84921](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f2fa84921](https://forums.unrealengine.com/u/anonymous_user_f2fa84921)\
**Post date:** [September 15, 2015, 12:57am UTC](https://forums.unrealengine.com/t/how-can-i-get-skeletal-mesh-animinstance-and-then-cast-it-using-code/283271/4 "2015-09-15T00:57:30Z")

</div>

same here, cast always fails

edit: ahhh it seems the mesh-\>GetAnimInstance() always return null for some reason… see here this guy has the same problem

[link text](https://answers.unrealengine.com/questions/279928/why-does-getmesh-getaniminstance-returns-null.html)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f2fa84921](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f2fa84921](https://forums.unrealengine.com/u/anonymous_user_f2fa84921)\
**Post date:** [September 19, 2015, 7:13pm UTC](https://forums.unrealengine.com/t/how-can-i-get-skeletal-mesh-animinstance-and-then-cast-it-using-code/283271/5 "2015-09-19T19:13:10Z")

</div>

see this link someone has posted the answer

[Answer](https://answers.unrealengine.com/questions/279928/why-does-getmesh-getaniminstance-returns-null.html)
