Jump to content

[SOLVED] I can't replace the material with a new one


photo

Recommended Posts

Hi!.

The problems i will talk about, refer to the final build version and they don't disappear even if I recompile in visual studio in the release version.In visual studio,everything works,no problems

I've created a node by loading the mesh of an fbx model. But when I assign a new material, different from the original fbx model, the result is a red color material.

Then i've tried this; the new material inherits from the original material and I give it a new texture,but I get a black material. If i use the original material.these problem don't arise.

These are the lines,in AppWorldLogic::init() :

    Unigine::MeshPtr mesh = Unigine::Mesh::create();

    mesh->load("mars.fbx/sphere.mesh");

    Unigine::ObjectMeshStaticPtr obj = Unigine::ObjectMeshStatic::create(mesh); 

    Unigine::MaterialPtr m,mat, mat1;

    Unigine::ImagePtr image;

    mat = Unigine::Materials::loadMaterial("materials/marsmaterial.mat");            // original material (specular workflow)
    mat1 = Unigine::Materials::loadMaterial("materials/jupitermaterial.mat");        // new material (specular workflow)

    image = Unigine::Image::create("textures/jupiter.jpg");                                     // new texture

    m = mat->inherit();
    int num = m->findTexture("diffuse");                          
    m->setTextureImage(num, image);
    

   obj->setMaterial(mat1, "*");                   // i get red material

// obj->setMaterial(ma, "*");                   // i getblack material

I don't know why. Any ideas?

Link to comment

Hello!

When you package the final project, the dependency search feature is activated, which removes all the assets that are not used in the project. Consequently, if any changes are planned to be made afterwards, such files should be added to the exceptions during the build stage, as described in the article below.: https://developer.unigine.com/en/docs/2.16.1/editor2/projects/build_project?rlang=cpp#delete_unused_assets

It appears that you need to force-include *.fbx assets, similar to the example provided below:

image.png

Additionally, it is good practice to perform a pre-check to determine if the material is found and display a console message to alert yourself. This will facilitate error detection and help prevent potential application crashes.

So, you can implement something like the following:

mat = Unigine::Materials::loadMaterial("materials/marsmaterial.mat");   
if (!mat)
Log::error("can not find material materials/marsmaterial.mat\n");

Thanks!

Link to comment
  • bmyagkov changed the title to [SOLVED] I can't replace the material with a new one
×
×
  • Create New...