How to clear material from asset ue4 c++?

Hi Friends,

How does one clear a material from a StaticMeshComponent in UE4 C++?


I know the blueprint equivalent is setting null material which clears any materials


But when I assign “Mesh->SetMaterial(index, NULL)” the editor crashes.
So how are we able to clear a material through UE4 C++?

Thank you for your time!

It worked! Thanks for the info!!!

The signature for UPrimitiveComponent::SetMaterial takes a pointer parameter for the material, not a value. Try providing nullptr instead of NULL and see if that works.

That’s very strange that it worked for the OP. nullptr is just value 0 and is implicitly casted to any pointer type. 0 or NULL is just a integer literal. The code generated from calling SetMaterial(1, 0), SetMaterial(1,NULL) and SetMaterial(1,nullptr) is exactly the same: on x64 Windows it’ll push pointer to the object on which you call it to rcx register, then the first parameter 1 into rdx register and then 0 into an r8 register in all 3 cases of the code.