I am trying to read material from Project Settings and set is as Brush Image in my widget.
This code I use for reading material from asset browser
FSlateBrush Brush = FSlateBrush();
const UInteractionSettings* Settings = GetDefault<UInteractionSettings>();
if(Settings && Settings->EmptyCrosshairMaterial != nullptr){
UObject *Material = Cast<UObject>(Settings->EmptyCrosshairMaterial.TryLoad());
if(Material != nullptr){
UE_LOG(LogTemp, Warning, TEXT("Material for Interaction crosshair was read"));
Brush.SetResourceObject(Material);
}
}
Brush.ImageSize = FVector2D(32, 32);
Both log print in console, so I suppose everything is okey.
Next I draw my widget.
ChildSlot
[
SAssignNew(Crosshair, SBorder)
.BorderImage(&Brush)
.Padding(FMargin(20))
];
If I remove .BorderImage(…), everything works, but if I execute this line, my engine crashes with next report.
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000008