Hi,
I’m trying to add a material to a UStaticMeshComponent in C++. I created a blueprint out of the C++ class and I selected a material. I searched the forum and found similar questions, but the answers are saying the same think I did already. So I think I did everything right, but my debug message still says “No Material”.
This is my code:
BaseBuilding.h
UPROPERTY(EditDefaultsOnly)
UStaticMeshComponent* BuildingMesh;
//The material to use
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UMaterialInterface* Material;
BaseBuilding.cpp
ABaseBuilding::ABaseBuilding(const FObjectInitializer &ObjectInitializer) : Super(ObjectInitializer)
{
...]
if (Material != NULL)
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, FString::Printf(TEXT("Setting Material")));
BuildingMesh->SetMaterial(0, Material);
}
else
{
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Red, FString::Printf(TEXT("No Material")));
}
}
I hope someone can help me with this.