Access to Loading module crash ue c++

I’m trying to implement a module to a loading screen i used this video as base:

(4) Async Loading Screens and Transition Levels | Unreal Fest Europe 2019 | Unreal Engine - YouTube

When i call the module the UE crash:

Here my call in the main module:

void UMainMenuWidget::NewGame()
{
	UE_LOG(LogTemp, Warning, TEXT("NEW GAME"));
	ILoadingScreenModule& LoadingScreenModule = ILoadingScreenModule::Get();
	LoadingScreenModule.StartInGameLoadingScreen(false, 5);
}

And here my inplementation module:


// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "Modules/ModuleInterface.h"
#include "Modules/ModuleManager.h"

class ILoadingScreenModule : public IModuleInterface
{
public:
	static inline ILoadingScreenModule& Get()
	{
		return FModuleManager::LoadModuleChecked<ILoadingScreenModule>("LoadingScreen");
	}

	virtual void StartInGameLoadingScreen(bool bplayUntilStopped, float playTime) = 0;

	virtual void StopInGameLoadingScreen() = 0;
};
// Copyright Epic Games, Inc. All Rights Reserved.

#include "../Public/LoadingScreen.h"
#include "Modules/ModuleManager.h"
#include "SlateBasics.h"
#include "SlateExtras.h"
#include "MoviePlayer.h"
#include "Widgets/Images/SThrobber.h"


struct LoadingScreenBrush : public FSlateDynamicImageBrush, public FGCObject
{
	LoadingScreenBrush(const FName InTextureName, const FVector2d& InImageSize) : FSlateDynamicImageBrush(InTextureName, InImageSize)
	{
		SetResourceObject(LoadObject<UObject>(NULL, *InTextureName.ToString()));
	}

	virtual void AddReferencedObjects(FReferenceCollector& Collector)
	{
		if (UObject* CachedResourceObject = GetResourceObject())
		{
			Collector.AddReferencedObject(CachedResourceObject);
		}
	}
};


class LoadingScreen : public SCompoundWidget
{
private:
	/** Rather to show the ... indicator */
	EVisibility GetLoadIndicatorVisibility() const
	{
		bool Vis = GetMoviePlayer()->IsLoadingFinished();
		return GetMoviePlayer()->IsLoadingFinished() ? EVisibility::Collapsed : EVisibility::Visible;
	}
	TSharedPtr<FSlateDynamicImageBrush> LoadingImageBrush;

public:
	SLATE_BEGIN_ARGS(LoadingScreen) {}
	SLATE_END_ARGS()
	void Construct(const FArguments& InArgs)
	{
		static const FName LoadingScreenName(TEXT("/Game/Textures/ui/StarSpaceLogo.StarSpaceLogo"));	
		LoadingImageBrush = MakeShareable(new LoadingScreenBrush(LoadingScreenName, FVector2D(1024, 256)));

		FSlateBrush* BGBrush = new FSlateBrush();
		BGBrush->TintColor = FLinearColor(0.034f, 0.034f, 0.034f, 1.0f);

		ChildSlot
			[
				SNew(SOverlay)
				+ SOverlay::Slot()
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Fill)
			[
				SNew(SBorder)
				.BorderImage(BGBrush)
			]
		+ SOverlay::Slot()
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Center)
			[
				SNew(SImage)
				.Image(LoadingImageBrush.Get())
			]
		+ SOverlay::Slot()
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Fill)
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot()
			.VAlign(VAlign_Bottom)
			.HAlign(HAlign_Right)
			.Padding(FMargin(10.0f))
			[
				SNew(SThrobber)
				.Visibility(this, &LoadingScreen::GetLoadIndicatorVisibility)
			]
			]
			];
	}

};


class FLoadingScreenModule : public ILoadingScreenModule
{
public:
	virtual void StartupModule() override
	{		
		// Force load for cooker reference
		LoadObject<UObject>(nullptr, TEXT("/Game/Textures/ui/StarSpaceLogo.StarSpaceLogo"));

		if (IsMoviePlayerEnabled())
		{
			CreateScreen();
		}
	}

	virtual bool IsGameModule() const override
	{
		return true;
	}

	virtual void StartInGameLoadingScreen(bool bPlayUntilStopped, float PlayTime) override
	{
		FLoadingScreenAttributes LoadingScreenInstance;
		LoadingScreenInstance.bAutoCompleteWhenLoadingCompletes = !bPlayUntilStopped;
		LoadingScreenInstance.bWaitForManualStop = bPlayUntilStopped;
		LoadingScreenInstance.bAllowEngineTick = bPlayUntilStopped;
		LoadingScreenInstance.MinimumLoadingScreenDisplayTime = PlayTime;
		LoadingScreenInstance.WidgetLoadingScreen = SNew(LoadingScreen);
		GetMoviePlayer()->SetupLoadingScreen(LoadingScreenInstance);
	}

	virtual void StopInGameLoadingScreen() override
	{
		GetMoviePlayer()->StopMovie();
	}

	virtual void CreateScreen()
	{
		FLoadingScreenAttributes LoadingScreenInstance;
		LoadingScreenInstance.bAutoCompleteWhenLoadingCompletes = true;
		LoadingScreenInstance.MinimumLoadingScreenDisplayTime = 3.f;
		LoadingScreenInstance.WidgetLoadingScreen = SNew(LoadingScreen);
		GetMoviePlayer()->SetupLoadingScreen(LoadingScreenInstance);
	}

};

IMPLEMENT_GAME_MODULE( FDefaultGameModuleImpl, LoadingScreen );

1 Like

@AlanDlucas1 caso não resolva, você poderia postar o erro?
O que você pode confirmar no seu plugin:

Plugin.Build.cs :


		PrivateDependencyModuleNames.AddRange(
			new string[] {
				"MoviePlayer",
				"Slate",
				"SlateCore",
				"InputCore"
			}
		);

Hello @SolidSk, that is my LoadingScreen.Build.CS:

using UnrealBuildTool;

public class LoadingScreen : ModuleRules
{
	public LoadingScreen(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
	
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Slate", "SlateCore", "MoviePlayer" });

		// Uncomment if you are using Slate UI
		// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
		
		// Uncomment if you are using online features
		// PrivateDependencyModuleNames.Add("OnlineSubsystem");

		// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
	}
}

My .uproject to:

{
	"FileVersion": 3,
	"EngineAssociation": "5.0",
	"Category": "",
	"Description": "",
	"Modules": [
		{
			"Name": "StarSpace_UE5",
			"Type": "Runtime",
			"LoadingPhase": "Default",
			"AdditionalDependencies": [
				"Engine",
				"UMG"
			]
		},
		{
			"Name": "LoadingScreen",
			"Type": "ClientOnly",
			"LoadingPhase": "PreLoadingScreen"
		}
	],
	"Plugins": [
		{
			"Name": "ModelingToolsEditorMode",
			"Enabled": true,
			"TargetAllowList": [
				"Editor"
			]
		},
		{
			"Name": "Bridge",
			"Enabled": true,
			"SupportedTargetPlatforms": [
				"Win64",
				"Mac",
				"Linux"
			]
		}
	]
}

The error:

LoginId:bea624a544b383bdd3ea46912c6591f5
EpicAccountId:ac7965edb0a64870858406acd29a0dd4

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0xffffffffffffffff

UnrealEditor_StarSpace_UE5_1647!UMainMenuWidget::PlayGame() [C:\Users\alan.bittencourt\Documents\Personal\Faia\StarSpace_UE5\Source\StarSpace_UE5\UI\MainMenuWidget.cpp:26]
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_StarSpace_UE5_1647!TMulticastScriptDelegate<FWeakObjectPtr>::ProcessMulticastDelegate<UObject>() [D:\Epic\UE_5.0\Engine\Source\Runtime\Core\Public\UObject\ScriptDelegates.h:488]
UnrealEditor_StarSpace_UE5_1647!ColorAnimationUI::CleanMap() [C:\Users\alan.bittencourt\Documents\Personal\Faia\StarSpace_UE5\Source\StarSpace_UE5\UI\AnimationUtils\ColorAnimationUI.cpp:86]
UnrealEditor_StarSpace_UE5_1647!ColorAnimationUI::Tick() [C:\Users\alan.bittencourt\Documents\Personal\Faia\StarSpace_UE5\Source\StarSpace_UE5\UI\AnimationUtils\ColorAnimationUI.cpp:49]
UnrealEditor_StarSpace_UE5_1647!UIAnimationUtils::Tick() [C:\Users\alan.bittencourt\Documents\Personal\Faia\StarSpace_UE5\Source\StarSpace_UE5\UI\AnimationUtils\UIAnimationUtils.cpp:27]
UnrealEditor_StarSpace_UE5_1647!TBaseRawMethodDelegateInstance<0,UIAnimationUtils,bool __cdecl(float),FDefaultDelegateUserPolicy>::Execute() [D:\Epic\UE_5.0\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:453]
UnrealEditor_Core
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll

O que pode ser é na definição do módulo, muda seu código:

IMPLEMENT_GAME_MODULE( FDefaultGameModuleImpl, LoadingScreen );

Para:

IMPLEMENT_GAME_MODULE( FLoadingScreenModule, LoadingScreen );
1 Like

I believe it’s works now, it’s not showing the screen yet but don’t crash the unreal.
The LoadingScreen must apear in Editor to? or just in build?

Ainda não fiz nada tão pesado assim, mas acredito que deveria aparecer se o seu jogo precisar de carregamento.
O Sample do ActionRPG usa um módulo de Async Loading também, você pode confirmar por ele se aparece ou não o carregamento.

1 Like