@, here’s another node that might be useful with the other texture related nodes.
It uses Zoid’s Dynamic Texture update method, and lets you pass in an array of FColors as the texture data.
I have it set here to do the whole texture at once because supposedly sub-regions don’t work, but I haven’t tested that yet. I’ve tested out the updating in general and it does work, though some of the streaming settings on the UTexture2D need to be set (so it may not work on UTexture2Ds that come out of the TextureFromDisk node, without a minor change there).
If sub-regions do work, it’d be really nice to change to pass in the region data (source X/Y, dest X/Y, basically).
If you ever figure out how to raycast and get a UV coordinate, would be the perfect second piece to allow for dynamic decals on skinned meshes (the update happens in the render thread, and is quite fast).
A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums (UpdateTextureRegions is what you want)
/** Updates a UTexture2D* from an FColor array.
* Update texture from color data.
* @param ColorData Array of FColors to update texture with. Array is assumed to be the same dimensions as texture, otherwise call will fail.
* @param Texture Texture to update.
*/
UFUNCTION(BlueprintCallable, Category = "TextureFromDisk")
static void UpdateTextureFromColorData(TArray<FColor>& ColorData, UTexture2D* Texture);
And the definition:
void UTextureFromDiskFunctionLibrary::UpdateTextureFromColorData(TArray<FColor>& ColorData, UTexture2D* Texture)
{
// Sanity checks.
if (!Texture)
return;
if (ColorData.Num() <= 0)
return;
// Update region.
FUpdateTextureRegion2D *region = new FUpdateTextureRegion2D(0, 0, 0, 0, Texture->GetSurfaceWidth(), Texture->GetSurfaceHeight());
// Call the render command.
UpdateTextureRegions(Texture, 0, 1, region, Texture->GetSurfaceWidth() * 4, 4, (uint8*)ColorData.GetTypedData(), false);
}
Right now the way it’s set up it will leak the FUpdateTexture2D - so you may want to change UpdateTextureRegions to free the FUpdateTextureRegion2D but NOT the SrcData pointer, because that refers to your TArray of FColors, which you don’t want freed.
To fix that, change in UpdateTextureRegions
if (bFreeData)
{
FMemory::Free(RegionData->Regions);
FMemory::Free(RegionData->SrcData);
}
to :
if (bFreeData)
{
FMemory::Free(RegionData->Regions);
}
If you change , make sure to change the last parameter for UpdateTextureRegions to be true, so it will actually free the FUpdateTextureRegion2D.