how do I set the user texture parameter for a texture sample? I tried using the set Niagara variable object, but that did not work.I created a Niagara emitter which is using a texture sample to generate particles using the color of the texture sample. the emitter works just fine when I set the texture sample in the Niagara editor. I would like to swap out the image at runtime although, so I created a user parameter and link it to the texture of the texture sample node. when I tried to set the value of the user parameter in a blueprint I don’t see an option for setting the Niagara variable texture sample. Instead I use the one for object, but it does not appear to work because the texture sample parameter Never Get Set correctly. Please let me know how I can accomplish this swapping of the image at runtime. Thank you in advance.
Hey, it has almost been 5 months. Have you been able to find a solution?
The following answer works for me in Editor, but it doesn’t work at all ina packaged build:
https://answers.unrealengine.com/questions/920988/how-do-you-set-a-texture-on-a-niagara-variable-at.html
I just saw your response. I never did find a solution for this.
This seems to work for me. Haven’t tested extensively, but no issues so far.
I have a test scene that flips between two textures on the NiagaraSystem in Playmode and works fine.
void UMyBlueprintLibrary::SetNiagaraVariableTexture(UNiagaraComponent* NiagaraComponent, const FName OverrideName, UTexture* OverrideTexture)
{
if (!NiagaraComponent || !OverrideTexture)
{
UE_LOG(LogTemp, Error, TEXT("NiagaraComponent or Override Texture is NULL!"))
return;
}
UNiagaraDataInterface* DataInterface = UNiagaraFunctionLibrary::GetDataInterface(UNiagaraDataInterface::StaticClass(), NiagaraComponent, OverrideName);
if (!DataInterface)
{
UE_LOG(LogTemp, Error, TEXT("Could not get DataInterface with OverrideName: %s"), *OverrideName.ToString())
return;
}
if (const auto CurrentTextureSample = Cast<UNiagaraDataInterfaceTexture>(DataInterface))
{
CurrentTextureSample->SetTexture(OverrideTexture);
}
else
{
UE_LOG(LogTemp, Error, TEXT("Could not cast to DataInterfaceTexture!"))
}
}
I found a solution. First do the making a material interface like in this post and put that in the Material User Param under Sprite Rendering. Next create a dynamic material instance in BP and use that to set niagara material interface variable with a Set Niagara Variable (Material) node. When anything on this dynamic material instance is changed in the BP it will change on the particle system.