IMaterial* CDoorPanelBehavior::CreateClonedMaterial( IEntity* pEntity, const int iSlotIndex )
{
	CRY_ASSERT( m_pClonedAnimatedMaterial == NULL );

	IMaterial* pClonedMaterial = NULL;

	IEntityRenderProxy* pRenderProxy = static_cast<IEntityRenderProxy*>(pEntity->GetProxy(ENTITY_PROXY_RENDER));
	if (pRenderProxy)
	{
		IMaterial* pOriginalMaterial = pRenderProxy->GetRenderMaterial(iSlotIndex);
		if (pOriginalMaterial)
		{
			IMaterialManager* pMatManager = gEnv->p3DEngine->GetMaterialManager();
			CRY_ASSERT(pMatManager);

			pClonedMaterial = pMatManager->CloneMaterial( pOriginalMaterial );
			if (pClonedMaterial)
			{
				m_pClonedAnimatedMaterial = pClonedMaterial;
				pClonedMaterial->SetFlags( pClonedMaterial->GetFlags()|MTL_FLAG_PURE_CHILD ); // Notify that its not shared so won't try to remove by name in material manager which removes original material
			}
			else
			{
				GameWarning("CDoorPanelBehavior::CreateClonedMaterial: Failed to clone material");
			}
		}
		else
		{
			GameWarning("CDoorPanelBehavior::CreateClonedMaterial: Failed to get material from slot: %d", DOOR_PANEL_MODEL_NORMAL_SLOT);
		}
	}
	else
	{
		GameWarning("CDoorPanelBehavior::CreateClonedMaterial: Failed getting render proxy");
	}

	return pClonedMaterial;
}