I just started coding with C , and am doing a few tutorials on using C , but when I finished up one part of code I saw that it was erroring:
no instance of overload function "Unigine::ObjectMeshDynamic""setMaterial" matches the argument
Here is my code, and even though I did exactly as I was supposed to, maybe there was something I missed, even after looking at it over and over again (this is in unigine):
int AppWorldLogic::addMeshToScene(const char *file_name, const char *mesh_name, const char *material_name, Math::Vec3 position)
{
MeshPtr mesh = Mesh::create();
ObjectMeshDynamicPtr omd;
if (file_name)
{
if (!mesh->load(file_name))
{
Log::error("\nError opening .mesh file!\n");
mesh.clear();
return 0;
}
else omd = ObjectMeshDynamic::create(mesh);
}
else
{
mesh->addBoxSurface("box_surface", Math::vec3(0.5f));
omd = ObjectMeshDynamic::create(mesh);
}
// setting node material, name and position
omd->setMaterial(material_name, "*");
omd->setName(mesh_name);
omd->setWorldPosition(position);
Objects.append(omd);
Log::message("-> Object %s added to the scene. \n", mesh_name);
mesh.clear();
return 1;
}
CodePudding user response:
If you read Unigine's current (2.15.1) documentation for setMaterial()
(which Unigine::ObjectMeshDynamic
inherits from Unigine::Object
), you will see that it is overloaded to accept only the following parameters:
void setMaterial ( const Ptr<Material> & mat, int surface )
void setMaterial ( const Ptr<Material> & mat, const char * pattern )
You are trying to call SetMaterial()
with 2 strings as input, and there is no such overload available, hence the error.
"*"
is a string literal, which is implemented as a const char[2]
array that decays into a const char*
. So you can safely pass that to the pattern
parameter.
However, you are trying to pass your material_name
variable, which is a const char*
string, to the mat
parameter. A const char*
is not compatible with Ptr<Material>
. setMaterial()
wants a pointer to a Unigine::Material
object instead of a string.
I looked at earlier versions of the documentation, and found that prior to 2.15, there were additional overloads of setMaterial()
, some of which accepted a const char* name
parameter instead of a const Ptr<Material> &mat
parameter. It seems those overloads where removed in 2.15. Which means the code you are trying to use was meant for an earlier version of Unigine, not for the latest version.
It appears that you copied your code from this documentation page, which has apparently not been updated to account for the latest Unigine version. There is obviously now another step involved to get a Material
object from a name string in the latest version. For instance, by calling Materials::findMaterial()
. Or alternatively, using setMaterialPath()
instead of setMaterial()
.
Have a look at the Upgrading to UNIGINE 2.15: API Migration: Materials Changes documentation.