O'Reilly logo

CryENGINE Game Programming with C++, C#, and Lua by Ruan Pearce-Authers, Carl-Filip Lundgren

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modifying materials at runtime

In this section we're going to modify a material at runtime.

Note

Similar to IStatObj, we can also clone our material to avoid making changes to all of the objects using it currently. To do so, call IMaterialManager::CloneMaterial, which is accessible via gEnv->p3DEngine->GetMaterialManager().

The first thing we need to do is obtain an instance of the material we want to edit. If we have an entity nearby, we can use IEntity::GetMaterial as shown:

IMaterial *pMaterial = pEntity->GetMaterial();

Note

Note that IEntity::GetMaterial returns null if no custom material has been set. If this is the case, you might want to rely on a function such as IStatObj::GetMaterial.

Cloning a material

Note that IMaterial instances can be used ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required