I’ve spend whole eternity trying to figure out how to do a simple thing - render an actor to a texture?
Not capture with UCaptureSceneComponent2D, but render in it’s own environment.
I’ve found the old code:
Custom GameViewportClient: Render off-screen - Rendering - Unreal Engine Forums
but it works only under Editor.
I’ve tried to investigate Kismet’s DrawMaterialToRenderTarget with following straight simple code:
UTexture2D* OffscreenRender::MakeTexture( const FString& name, UWorld* w )
{
UStaticMesh* plane = LoadObject<UStaticMesh>(nullptr, TEXT("/Engine/BasicShapes/Plane"));
UTextureRenderTarget2D* target = LoadObject<UTextureRenderTarget2D>(w, TEXT("/Game/Target"));
UKismetRenderingLibrary::DrawMaterialToRenderTarget(w, target, plane->GetMaterial(0));
return target->ConstructTexture2D(GWorld, name, EObjectFlags::RF_NoFlags, CTF_DeferCompression);
}
, but it leaves me with a blank texture. And I could not find any example of using it. Also I’ve found a number of similar question with no answers, and I believe this one will queue in the row.
Is there anything to do such a simple task?