I need to load a panorama texture and change the skybox environment at runtime.
I was doning well at previous steps.
But I failed when trying to convert from UTextureRenderTargetCube to UTextureCube after packaging project.
Here is my code:
#include "UtilityLibrary.h"
#include "Engine/TextureRenderTargetCube.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "UObject/ObjectMacros.h"
#include "UObject/UObjectBaseUtility.h"
void UUtilityLibrary::ConvertToStaticTexture(UTextureRenderTargetCube* renderTarget, FString PackagePath, FString TextureName, bool& success, UTextureCube*& outputTexture)
{
UPackage* mPackage = CreatePackage(NULL, *PackagePath);
UTextureCube* textureCube = renderTarget->ConstructTextureCube(mPackage,
TextureName, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone);
if (textureCube != nullptr) {
outputTexture = textureCube;
success = true;
}
else {
outputTexture = nullptr;
success = false;
}
}
It can run in the editor. but after packaging, it always return nullptr.
I checked several tutorials, they executed the following codes, but I encountered compile error.
textureCube->MarkPackageDirty();
textureCube->GetOuter()->MarkPackageDirty();
FAssetRegistryModule::AssetCreated(textureCube);
I have no idea to solve it now.
I guess my flags settings is wrong or construct texture cube method is only editor support.