# What is the type of this Local variable?

**URL:** <https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744>\
**Category:** C++\
**Tags:** unreal-engine, Scripting, CPP, question\
**Created:** [May 22, 2021, 10:22am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744 "2021-05-22T10:22:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [May 22, 2021, 10:22am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/1 "2021-05-22T10:22:21Z")

</div>

What is the type of this Promoted variable by the name **Skin Met Ref** or how to know the type if you can’t Identify, I need to know the type because I need to declare the variable for C++ **Dynamic Material Instance** and the **int** type is not compatible.

 ![339463-123.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/5/735a96c6d80926b6ec8d468b0d9197f7a8ffbd99.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 22, 2021, 10:25am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/2 "2021-05-22T10:25:17Z")

</div>

You can just click on the ‘return value’ pin and choose ‘promote to variable’, then you get the right kind.

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [May 22, 2021, 10:28am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/3 "2021-05-22T10:28:54Z")

</div>

Friend I am writing the function in C++, I need to declare the Variable for the function.

//create skin material

SkinRef = GetMesh()-\>CreateDynamicMaterialInstance(0, Material.Object, NAME\_None);

GetMesh()-\>SetMaterialByName(“Skin”, SkinRef);

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 22, 2021, 10:31am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/4 "2021-05-22T10:31:50Z")

</div>

How about this?

> **[Creating a dynamic material instance on C++?](https://forums.unrealengine.com/questions/441986/creating-a-dynamic-material-instance-on-c.html)**
>
> Hello there! I have an actor with several meshes. I would like to create a dynamic material and then apply it to the components. However, I can’t seem to find how to do this. Where should the material be instantiated? And, should it be applied on...

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [May 22, 2021, 10:37am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/5 "2021-05-22T10:37:52Z")

</div>

That solution only works when after the begin play and not under in editor.  
What I want to achieve in C++ is:

 ![339113-img-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/7/e/e7ec67b50b2cba24664ee09c43d2e496122dc3b6.png)

My C++ Code:

//this must be in the constructor

```
auto Material = ConstructorHelpers::FObjectFinder<UMaterial>(TEXT("parrent material path"));
 
void initSkeletalMesh()
{
    
    if (Material.Object == nullptr) return;
 
    //create skin material
    SkinRef = GetMesh()->CreateDynamicMaterialInstance(0, Material.Object, NAME_None);
    
    GetMesh()->SetMaterialByName("Skin", SkinRef);
 
    //set master pose
    SKMShoes->SetMasterPoseComponent(GetMesh());
 
    //attach hair
    SKMHair->AttachTo(GetMesh(),TEXT("Head"), EAttachLocation::KeepWorldPosition, true);
}
```

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [May 22, 2021, 10:46am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/6 "2021-05-22T10:46:03Z")

</div>

I tried using float but still not compatible.

 ![339465-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/5/3/05381ac6fa3dd285492a0fa417be24bd5abe7ecf.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 22, 2021, 10:49am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/7 "2021-05-22T10:49:43Z")

</div>

But you’re trying to assign the MID to a float. In the example

 ![339455-screenshot-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/3/d/93d6fb6147b022e2963bd67c1c5455833a32fd7d.png)

the writer is making the type ‘UMaterialInstanceDynamic\*’

This statement

![339456-screenshot-4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/1/8/e182a870080bbdc425a2b12f800be31e369307a6.png)

is setting a float param in the material _after_ it has been made.

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [May 22, 2021, 10:54am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/8 "2021-05-22T10:54:38Z")

</div>

I don’t understand what you mean by this, I don’t see a reference local variable declared for dynamic material instance.

Please post my code back with the fix.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 22, 2021, 10:59am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/9 "2021-05-22T10:59:31Z")

</div>

This is it

 ![339457-screenshot-5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/d/8/9d89ab050b23b1835eae86953d105e4093002628.png)

The local variable is DynMaterial, that’s the material ref.

Then, later, you can adjust a scalar on that material with

![339458-screenshot-6.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/c/0/6c0a05a05e1ff9dfc0eff4a296ac9ecf15bfb966.png)

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [May 22, 2021, 11:43am UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/10 "2021-05-22T11:43:37Z")

</div>

The not-compatible error is fixed and the project compiles successfully, but still the hair mesh is not welded with scalp in the editor.  
Please review the Problem:

> **[How to force the hair mesh to follow animation?](https://forums.unrealengine.com/questions/1031136/view.html)**
>
> How to set the hair mesh to follow the animation? #UE-59094 BUG still not solved. .cpp Hair = CreateDefaultSubobject("Hair"); Hair-\>SetupAttachment(GetMesh()); Hair-\>AttachToComponent(Hair,...

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 22, 2021, 1:49pm UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/11 "2021-05-22T13:49:45Z")

</div>

Now, that part I’m afraid I don’t know about :-/

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [May 22, 2021, 2:55pm UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/12 "2021-05-22T14:55:11Z")

</div>

Ok, But you can explain why using the blueprint is more efficient in this case, I mean when I attach the **hairs** using blueprint, the hairs is welded with **headsocket** in editor and in play mode, but with C++ I don’t know why only welded when playing… but in editor not welded.  
I can only think about the one thing that from where the **BOOL** condition comes in the **AttachComponentToComponent** node, I think this is responsible for this welding.

 ![339487-123.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/3/5/3354c18503a4b614fa6a1cd12cf1f6744b9fca6c.png)

When I make it false the hairs mesh is detached from the head socket while **play game** and in **editor** both.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 22, 2021, 4:01pm UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/13 "2021-05-22T16:01:03Z")

</div>

I assume that sort of functionality is available with C++ ( but don’t actually know ), best to post a new question on that.

---

<div class="post-metadata">

**Author:** ![c0r37py](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/c0r37py/32/559700_2.png) [@c0r37py](https://forums.unrealengine.com/u/c0r37py)\
**Post date:** [May 22, 2021, 4:53pm UTC](https://forums.unrealengine.com/t/what-is-the-type-of-this-local-variable/483744/14 "2021-05-22T16:53:12Z")

</div>

Ok Friend I will post it now.
