Hello, i wrote loading screen code like “ActionRPG” or “StrategyGame”, in standalone every thing is okay but in packeged project Stextblock is invisible.
TemplateGameInstanceBase.h :
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "TemplateGameInstanceBase.generated.h"
UCLASS()
class TEMPLATE_API UTemplateGameInstanceBase : public UGameInstance
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
void StartLoadingScreen(bool bPlayUntilStop, float PlayTime);
UFUNCTION(BlueprintCallable)
void StopLoadingScreen();
};
TemplateGameInstanceBase.cpp :
#include "TemplateGameInstanceBase.h"
#include "MoviePlayer.h"
#include "SMyWidget.h"
#include "SlateBasics.h"
#include "SlateExtras.h"
void UTemplateGameInstanceBase::StartLoadingScreen(bool bPlayUntilStop, float PlayTime)
{
FLoadingScreenAttributes LoadingScreen;
LoadingScreen.bAutoCompleteWhenLoadingCompletes = !bPlayUntilStop;
LoadingScreen.bWaitForManualStop = bPlayUntilStop;
LoadingScreen.bAllowEngineTick = bPlayUntilStop;
LoadingScreen.MinimumLoadingScreenDisplayTime = PlayTime;
LoadingScreen.WidgetLoadingScreen = SNew(SMyWidget);
GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);
}
void UTemplateGameInstanceBase::StopLoadingScreen()
{
GetMoviePlayer()->StopMovie();
}
SMyWidget.h :
#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"
class TEMPLATE_API SMyWidget : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SMyWidget)
{}
SLATE_ARGUMENT(TWeakObjectPtr<class AMyHUD>, HUDArg);
SLATE_END_ARGS()
void Construct(const FArguments& InArgs);
private:
TWeakObjectPtr<class AMyHUD> OwnerHUD;
TSharedPtr<FSlateDynamicImageBrush> LoadingbarImage;
TSharedPtr<FSlateDynamicImageBrush> BackGroundImage;
};
SMyWidget.cpp :
#include "SMyWidget.h"
#include "SlateOptMacros.h"
#include "SThrobber.h"
#include "Widgets/Images/SImage.h"
#include "Brushes/SlateDynamicImageBrush.h"
#include "SlateBasics.h"
#include "SlateExtras.h"
#include "MoviePlayer.h"
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
#define LOCTEXT_NAMESPACE "Loading"
struct FLoadingImageBrush : public FSlateDynamicImageBrush, public FGCObject
{
FLoadingImageBrush(const FName InTextureName, const FVector2D& InImageSize)
: FSlateDynamicImageBrush(InTextureName, InImageSize)
{
SetResourceObject(LoadObject<UObject>(nullptr, *InTextureName.ToString()));
}
virtual void AddReferencedObjects(FReferenceCollector& Collector)
{
FSlateBrush::AddReferencedObjects(Collector);
}
};
void SMyWidget::Construct(const FArguments& InArgs)
{
OwnerHUD = InArgs._HUDArg;
LoadObject<UObject>(NULL, TEXT("/Game/Loading.Loading"));
LoadObject<UObject>(NULL, TEXT("/Game/Background.Background"));
static const FName LoadingScreenName(TEXT("/Game/Loading.Loading"));
LoadingbarImage = MakeShareable(new FLoadingImageBrush(LoadingScreenName, FVector2D(16, 16)));
static const FName BackGroundImageName(TEXT("/Game/Background.Background"));
BackGroundImage = MakeShareable(new FLoadingImageBrush(BackGroundImageName, FVector2D(1440, 900)));
ChildSlot
[
SNew(SOverlay)
+ SOverlay::Slot()
.HAlign(HAlign_Fill)
.VAlign(VAlign_Fill)
[
SNew(SImage)
.Image(BackGroundImage.Get())
]
+ SOverlay::Slot()
.VAlign(VAlign_Bottom)
.HAlign(HAlign_Right)
.Padding(FMargin(20.0f, 20.0f))
[
SNew(SCircularThrobber)
.PieceImage(LoadingbarImage.Get())
.Radius(32.0f)
]
+ SOverlay::Slot()
.VAlign(VAlign_Bottom)
.HAlign(HAlign_Left)
.Padding(FMargin(20, 0, 0, 70))
[
SNew(STextBlock)
.ShadowColorAndOpacity(FLinearColor::Black)
.ColorAndOpacity(FLinearColor(1, 1, 1, 1))
.ShadowOffset(FIntPoint(-1, 1))
.Font(FSlateFontInfo(FPaths::ProjectContentDir() / TEXT("Font/cambriab.ttf"), 16.0f))
.Text(LOCTEXT("LoadingDescription_1", "TODO Add Description here.\nAnd here.\nAnd So on."))
.Visibility(EVisibility::Visible)
]
];
}
#undef LOCTEXT_NAMESPACE
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
Standalone :
Packaged :