Niagara - How to set texture sample user parameter in BP?

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. :frowning:

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.

Try to use SetTextureObject node in blueprint.

3 Likes

I am trying to complete a instructional book and was struggling with this, but I think I have found the correct solution. The solution thread posted by soreal works, but doesn’t contain the full solution for me.

The issue:

If I use a “Set Texture Object” Node with a User Texture Sample Parameter, it changes textures properly in the Editor, but in PIE, the texture reverts back to whatever was set in the Niagara system.

Doesn’t work in PIE:

What worked for me was to create a “Texture” (Object) User Parameter and choose that instead as a “Texture User Parameter”:

Then in the Blueprint, I had the replace the “Set Texture Object” Node with the “Set Niagara Variable (Texture)” Node and add the name of the Texture object that I assigned to Texture User Parameter field:

Now it works in the Editor and in PIE. I’m pretty new to this, so I don’t understand exactly why, or what is the difference is between “Set Niagara Variable (Texture)” and “Set Texture Object”.

If a dev happens upon this, I think this would be a great opportunity for a little housekeeping, or at least some clearer documentation.