# UE4. How to create a reference to the physical material asset (which I create in editor) in C++

Oftenly, when we want to assign asset to the particular component in C++ we write code like that:

.h

UStaticMeshComponent* Body = nullptr;

.cpp

Body = CreateDefaultSubobject<UStaticMeshComponent>("Mesh Component");
// find mesh asset
auto MeshForBody = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT
("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere'"));
if (MeshForBody.Object != nullptr)
{// if asset is finded -> set to the component
Body->SetStaticMesh(MeshForBody.Object);
}


Question: how can I set the PhysicalMaterial in C++ through the reference to the asset in editor? Is it possible?

.h
UPROPERTY(EditDefaultsOnly)
UPhysicalMaterial* MyPhysicalMaterial = nullptr;

.cpp

???


Find this, but still waiting maybe the best solution without casting exists:

auto PhysicalMaterialAsset = ConstructorHelpers::FObjectFinder<UObject>(TEXT(
"PhysicalMaterial'/Game/PhysicsMaterials/MyPhysicsMaterial.MyPhysicsMaterial'"));

if (PhysicalMaterialAsset.Object)
{
Sphere->BodyInstance.SetPhysMaterialOverride((UPhysicalMaterial*)PhysicalMaterialAsset.Object);
}


THNX for any tips in advance ;)

• Find this, but still waiting maybe the best solution without casting: auto PhysicalMaterialAsset = ConstructorHelpers::FObjectFinder<UObject>(TEXT( "PhysicalMaterial'/Game/PhysicsMaterials/MyPhysicsMaterial.MyPhysicsMaterial'")); if (PhysicalMaterialAsset.Object) { Sphere->BodyInstance.SetPhysMaterialOverride((UPhysicalMaterial*)PhysicalMaterialAsset.Object); } Mar 19 '20 at 12:29
• Why are you using FObjectFinder<UObject> rather than FObjectFinder<UPhysicalMaterial>? Apr 7 '20 at 3:10
• Due to the second option gives an error. I wrote before, you can find more about the same problem here: reddit thread. I think, eventually, this error relates with FObjectFinder<T> template implementation. Apr 8 '20 at 10:30

if (MyPhysicalMaterial) {