Hello dear community.
I am struggling for more than a week already to accomplish next task:
I have a texture (buffer initially, but it’s no trouble to create UTexture2D from it). I need it to be rendered on top of some part of an object. Like a sticker on the wall, or logo on a shirt. What would be the right approach?
Things i tried:
Edit the texture of an object directly by using
UMaterialInterface* OriginalMaterial = GetStaticMeshComponent()->GetMaterial(targetMaterialElementIndexWhichIKnow);
OriginalMaterial->GetUsedTextures(OUT_OriginalTexturesArray, EMaterialQualityLevel::Type::Num, true, ERHIFeatureLevel::Type::Num, true);
No good. As soon as you merely try to read from the original texture buffer, like written here:
at the second option, you get Access Violation exception. Apparently UE lets you to tinker only with buffers of the textures you created YOURSELF through CreateTransient.
I am very confused here, since this seems to be the right approach IMHO.
Another thing i tried was going through UTextureRenderTarget2D API.
No luck here either. Apparently there is no way to designate to UTextureRenderTarget2D to override only part of the texture. It is good for applying sort of mask on all of the texture, but there seems to be no way to designate some texture as part of the UTextureRenderTarget2D or make UTextureRenderTarget2D itself cover only a sub-region.
My current attempt involves Decals. The problems are:
1). I inherited from ADecalActor, but my class ACustomDecalActor doesn’t appear in blueprints no matter what i do.
2). Contrary to StaticMeshActor where you can apply dynamic material easily to it, Decals are not so nice. If anyone knows how to override Decal base texture from c++ please share your knowledge.
3). AFAIK Decals are not that cheap to render, since they are not really integrated into the texture, but rather render thread does extra work of rendering something on top of something already rendered. No?
4). Decals won’t perform great under any angle. There are certain light angle issues.
5). There apparently is no way to attach my custom Decal to the moving object. “Spawn Decal Attached” returns stock Decal, and blueprint attach methods don’t do the job (either due to my missuse, or due to missinterpretation of my custom Decal).
Please help. I will be glad to have at least some direction.
Thank you in advance.