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

I have a NS that samples a vector field. I have made the vector field user exposed as can be seen here:
image

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:

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

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!

Anyone?

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 :

// UNiagaraComponent* Comp
// UVectorField* NewField

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

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

FieldParam->MarkRenderDataDirty();
2 Likes

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?

Sorry it was UNiagaraComponent

1 Like

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

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