I’m currently trying to find a proper fix for a crash I am running into. What I’ve done is the following:
- Create a new C++
AHUDclass. The idea is to create a debug visualization HUD, based off ofAAbilitySystemDebugHUD. - The function that registers the drawing callback looks like:
-
FDebugDrawDelegate DrawDebugDelegate = FDebugDrawDelegate::CreateUObject(HUD, &AMyDebugHUD::DrawDebugHUD); // NOTE: GameplayDebug is not an arbitrary name. ShowFlags are defined in ShowFlagsValues.ini. We are reusing an // existing one that's already used for things like the GAS debugger. DrawDebugDelegateHandle = UDebugDrawService::Register(TEXT("GameplayDebug"), DrawDebugDelegate);
-
- Then, inside my
DrawDebugHUD, I call another function I’ve made,DrawIcon:-
void AMyDebugHUD::DrawIcon(FString IconName, float& OffsetX, float& OffsetY) { const FString Path = "/MyPluginConntentFolder/Resources/" + IconName + "." + IconName; if (UTexture* T = LoadObject<UTexture2D>(nullptr, Path)) { if (!ensure(T->GetResource())) return; FCanvasTileItem Icon( FVector2D(OffsetX - 25, OffsetY - 30), T->GetResource(), FVector2D(25, 25), FColor::White ); Canvas->DrawItem(Icon); } }- I call it using
DrawIcon("T_Icon_MapMarker", IconX, Y);, where T_Icon_MapMarker.uasset is a normal texture asset in my content folder. I’ve set its texture type to UI.
- I call it using
-
- Then when I enable my HUD via a console command in PIE, CRASH!
I’ve found a strange workaround for this, which is to
- launch Unreal with the
DrawItemline commented out - PIE, enable the HUD
- It works, as expected – no crash since we aren’t drawing the texture
- Exit PIE
- Uncomment the line, recompile using Live Coding
- PIE, enable the HUD
- Works flawlessly!
Pretty strange. Maybe there’s something missing in LoadObject<UTexture2D> where it doesn’t get fully initialized in the first usage.
I’m going to try some hacky fixes like delaying the drawing one frame and see if that helps.
According to https://issues.unrealengine.com/issue/UE-50111, this bug won’t be fixed since there isn’t a repro for it. Hopefully this helps!