Crashes when clicked on created button with LOG error:
LogScript: Warning: Script Msg: No world was found for object (/Engine/Transient.UnrealEdEngine_0:GameInstance_0.PlayerHUD_C_0.Butt_0) passed in to UEngine::GetWorldFromContextObject().
Butt.cpp
void UButt::OnClick()
{
Cast<AThirdPersCharacter>(UGameplayStatics::GetPlayerPawn(this, 0))->OnClicku(this);
}
void UMyUserWidget::NativeConstruct()
{
Super::NativeConstruct();
UniformGridPanel = Cast<UUniformGridPanel>(GetWidgetFromName("UniformGridPanel_0"));
NewObject<UButt>();
UniformGridPanel->AddChild(Butt);
}
ThirdPersCharacter.h
UPROPERTY(BlueprintReadWrite)
UButt* PressedButton;
ThirdPersCharacter.cpp
void AThirdPersCharacter::OnClicku(UButt* ButtRef)
{
UButt* TempUButt = ButtRef;//no crash
CurrentButton = ButtRef;//crash
What should i do?