# How to change Niagara user defined variable in c++?

**URL:** <https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [July 25, 2023, 2:21pm UTC](https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669 "2023-07-25T14:21:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastianhannula](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sebastianhannula](https://forums.unrealengine.com/u/sebastianhannula)\
**Post date:** [July 25, 2023, 2:21pm UTC](https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669/1 "2023-07-25T14:21:19Z")

</div>

I have a NS that samples a vector field. I have made the vector field user exposed as can be seen here:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/6/7/26793a7423645a9c3347240bc3f9d4ffbb74c7c9.png)

In a blueprint, I have added the NS in question and want to somehow change which vector field it samples. I can access the vector field from the details panel as seen below:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/3/9/a39c5ef3697e94164b2ee249afc27aa14f11bc24.png)

Now I would want to change that in runtime trough the blueprint but there is no pre-defined function for that. Here is the documentation on the functions that do exist: [UNiagaraComponent | Unreal Engine Documentation](https://docs.unrealengine.com/5.0/en-US/API/Plugins/Niagara/UNiagaraComponent/)

I am thinking that if I could somehow access the user parameter from where it has been generated, I could swap out the “field” parameter in that. Is this a good way to achieve this and does anyone know how to do it in that case? I am a new to UE and just today made my first UE c++ script.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![sebastianhannula](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sebastianhannula](https://forums.unrealengine.com/u/sebastianhannula)\
**Post date:** [July 26, 2023, 5:59am UTC](https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669/2 "2023-07-26T05:59:00Z")

</div>

Anyone?

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [July 26, 2023, 8:47am UTC](https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669/3 "2023-07-26T08:47:13Z")

</div>

Long shot here as I know nothing about vector fields.

Looks like it is not a simple parameter but its own object which is a niagara data interface.  
Try accessing it like this :

```cpp
// UNiagaraComponent* Comp
// UVectorField* NewField

auto FieldParam = UNiagaraFunctionLibrary::GetDataInterface<UNiagaraDataInterfaceVectorField>(Comp, "VF0");

FieldParam->Field = NewField;
FieldParam->bTileX = true;

FieldParam->MarkRenderDataDirty();

```

---

<div class="post-metadata">

**Author:** ![sebastianhannula](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sebastianhannula](https://forums.unrealengine.com/u/sebastianhannula)\
**Post date:** [July 27, 2023, 7:25am UTC](https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669/4 "2023-07-27T07:25:39Z")

</div>

Thank you, I am about to test this but I get an error when trying to include NiagaraSystemComponent.h and can’t find documentation on that. Is this the type I should use?

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [July 27, 2023, 8:42am UTC](https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669/5 "2023-07-27T08:42:44Z")

</div>

Sorry it was `UNiagaraComponent`

---

<div class="post-metadata">

**Author:** ![sebastianhannula](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sebastianhannula](https://forums.unrealengine.com/u/sebastianhannula)\
**Post date:** [July 27, 2023, 10:13am UTC](https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669/6 "2023-07-27T10:13:13Z")

</div>

Thank you so much! This solved my problem and I can now change the vector fields in runtime!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [August 26, 2023, 10:13am UTC](https://forums.unrealengine.com/t/how-to-change-niagara-user-defined-variable-in-c/1239669/7 "2023-08-26T10:13:54Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
