Download

Use a Material File

Hi everybody, i am trying to load UMaterial from uassert files using the path, this material aren´t in the editor, only i have the file, this is the code:

||UMaterialInstanceDynamic* Dyn;
FString sPath = FPaths::ProjectDir() + FString(“Materials/00_Mat.00_Mat”);

UMaterial* mat = Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), nullptr, *sPath));

if (mat != nullptr) {
	Dyn = UMaterialInstanceDynamic::Create(mat, Mesh);
	UE_LOG(LogTemp, Warning, TEXT("material "));
}

the problem is never encounter the material but when i add the material to the project works, is it possible use a material witout the material is in the editor?

thanks

The editor processes and packages up all kinds of assets as part of the build process (and while you edit, in the background, so that you can preview these.)
Without having the built asset, you cannot use it in the game.
If you’re making a plugin, plugins can have their own Content directory, where you can put input assets used by classes in that plugin.

Why would you not add the material to the editor?

Thank for your answer,

I am doing a function,which created terrain reading different files, every terrain have a different file and i can create more terrain adding more file, and my idea is, the texture,the material, can be added reading a file because i need the user can add his texture using his texture file for create different terrain without the editor only the proyect after packing.

i need the user can create different terrain without use the editor, but If It is not posible, i Will add different material and i Will get a list with the different material.

Thank you.

You can make the texture be a parameter of the material, and create a dynamic material instance, and then configure a runtime generated (loaded) texture into that material.

A: terrain → material → Dynamic Material Instance (“MID”)
B: texture on disk → bitmap in RAM → Runtime texture
Configure B as the texture parameter on A. Done!

You may need to use a little bit of C++, but there’s reasonable suggestions of a few different approaches:
https://answers.unrealengine.com/questions/205006/is-it-possible-to-load-an-image-at-runtime.html?sort=oldest
It mainly boils down to using something like Ramas plugin (or writing your own similar C++ code):

thank you , i am going to try this night and i tell if i have luck, i would use Ramas plugin but i can´t use anything that i don´t created

Presumably you can learn by reading the code, though!