For my memory game I want to swap Textures/Pictures at runtime in my Material instance.
I hava a M_Card, with TextureSampleParameter2D
I have MI_Card, that is applied to BP_Card with some default values
Upon function call I want access available Textures/Images and apply it to MI_Card
The intention is, if I add an image (e.g. Image32.jpeg) to my content folder, I can access that in my BP_Card and replace the texture of MI_Card. BP_Card has a value (e.g. 32) and will access and load Image<BP_Card_Value>.jpeg to insert into MI_Card.
Or in general:
How can I achieve asset generation based on the Content folder? Is this even a practice?
However if you are adding images to a folder and you want them to be imported to engine in runtime, thats another thing but can be done too. However I don’t think it is a good practice.
However there is some ways to do it. Here is anotheer practice if you want images imported on runtime since you just created them or they are somehow dynamic
Also in editor you can reimport assets like below however its editor dependent.
void USOMEOBJECT::ReImportImages(UTexture* TextureToImport)
{
if (TextureToImport)
{
// Ensure the texture is updated
TextureToImport->UpdateResource();
// Get the import data and re-import the asset
if (UAssetImportData* ImportData = TextureToImport->AssetImportData) // this is the UTexture
{
FString AssetPath = TextureToImport->GetPathName(); // Lets look its path
if (ImportData->GetFirstFilename() != "") // if the path is not empty
{
if (FReimportManager::Instance()->Reimport(TextureToImport))
{
UE_LOG(LogTemp, Display, TEXT("Importer-> Texture Reimported Successfully."));
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Importer-> Unable to find source file for re-import."));
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Importer-> AssetImportData is invalid for texture."));
}
}
}```