x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to create RenderTextureTarget and save to Content from C++?

Hello Friends,

I'm currently trying to generate some Render Targets on play from ue4 c++ on BeginPlay. I've found you can easily generate textures doing the following:

     //testing on begin play
     int i = 0;        
     //get minimap content game folder from content browser
             FString TextureName = TEXT("T_MM_T");
             TextureName += FString::FromInt(i);
             FString PackageName = TEXT("/Game/Textures/");
             PackageName += TextureName;
             UPackage* Package = CreatePackage(NULL, *PackageName);
             Package->FullyLoad();
     
             //create texture
             float TextureWidth = 2048;
             float TextureHeight = 2048;
     
             UTexture2D* NewTexture = NewObject<UTexture2D>(Package, *TextureName, RF_Public | RF_Standalone | RF_MarkAsRootSet);
             NewTexture->AddToRoot();                // This line prevents garbage collection of the texture
             NewTexture->PlatformData = new FTexturePlatformData();    // Then we initialize the PlatformData
             NewTexture->PlatformData->SizeX = TextureWidth;
             NewTexture->PlatformData->SizeY = TextureHeight;
             NewTexture->PlatformData->NumSlices = 1;
             NewTexture->PlatformData->PixelFormat = EPixelFormat::PF_FloatRGBA;
     
             //save texture
             NewTexture->Source.Init(TextureWidth, TextureHeight, 1, 1, ETextureSourceFormat::TSF_BGRA8);
             NewTexture->UpdateResource();
             Package->MarkPackageDirty();
             FAssetRegistryModule::AssetCreated(NewTexture);
             FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
             bool bSaved = UPackage::SavePackage(Package, NewTexture, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError);
             UE_LOG(LogTemp, Warning, TEXT("Generated new texture at %s"), *PackageName);

Now when I try to use this method for UTextureRenderTarget, nothing saves and I get "LogOutputDevice: Error: Class which was marked abstract was trying to be loaded. It will be nulled out on save. RT_MM_RT0 TextureRenderTarget".

Why does this not work?

 UTextureRenderTarget* NewAsset = NewObject<UTextureRenderTarget>(Package, *AssetName, RF_Public | RF_Standalone | RF_MarkAsRootSet);
 
 NewAsset->AddToRoot();                // This line prevents garbage collection of the texture
         NewAsset->CreateResource();
 
 NewAsset->Source.Init(TextureWidth, TextureHeight, 1, 1, ETextureSourceFormat::TSF_BGRA8);
         NewAsset->UpdateResource();
 
         Package->MarkPackageDirty();
         FAssetRegistryModule::AssetCreated(NewAsset);
         FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
         bool bSaved = UPackage::SavePackage(Package, NewAsset, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError);
         UE_LOG(LogTemp, Warning, TEXT("Generated new texture at %s"), *PackageName);



Does anyone have advice for generating TextureRenderTargets from ue4 c++?

Thank you for your time!

Product Version: UE 4.22
Tags:
more ▼

asked Apr 24 '19 at 11:35 PM in C++ Programming

avatar image

anoxxi-dis
6 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question