If I run the Unreal project in debug mode, it will have a breakpoint on BgScriptReader.cs and I want to solve this problem. Has anyone had the same problem as me and solved it?
Here is the call stack of my project’s breakpoint moment.
[Inline Frame] UnrealEditor-Engine.dll!UMaterialInstance::PostLoad::__l5::<lambda_2>::operator()() Line 2981 C++
UnrealEditor-Engine.dll!UMaterialInstance::PostLoad() Line 2981 C++
UnrealEditor-Engine.dll!UMaterialInstanceConstant::PostLoad() Line 49 C++
UnrealEditor-CoreUObject.dll!UObject::ConditionalPostLoad() Line 1269 C++
UnrealEditor-CoreUObject.dll!EndLoad(FUObjectSerializeContext * LoadContext, TArray<UPackage *, TSizedDefaultAllocator<32>> * OutLoadedPackages) Line 2211 C++
UnrealEditor-CoreUObject.dll!LoadPackageInternal::__l102::<lambda_2>::operator()() Line 1751 C++
UnrealEditor-CoreUObject.dll!LoadPackageInternal(UPackage * InOuter, const FPackagePath & PackagePath, unsigned int LoadFlags, FLinkerLoad * ImportLinker, FArchive * InReaderOverride, const FLinkerInstancingContext * InstancingContext, const FPackagePath * DiffPackagePath) Line 1853 C++
UnrealEditor-CoreUObject.dll!LoadPackage(UPackage * InOuter, const FPackagePath & PackagePath, unsigned int LoadFlags, FArchive * InReaderOverride, const FLinkerInstancingContext * InstancingContext, const FPackagePath * DiffPackagePath) Line 2014 C++
UnrealEditor-CoreUObject.dll!LoadPackage(UPackage * InOuter, const wchar_t * InLongPackageNameOrFilename, unsigned int LoadFlags, FArchive * InReaderOverride, const FLinkerInstancingContext * InstancingContext) Line 1987 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::Map_Load(const wchar_t * Str, FOutputDevice & Ar) Line 2708 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::HandleMapCommand(const wchar_t * Str, FOutputDevice & Ar, UWorld * InWorld) Line 6291 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::Exec_Editor(UWorld * InWorld, const wchar_t * Stream, FOutputDevice & Ar) Line 5752 C++
UnrealEditor-Core.dll!FExec::Exec(UWorld * InWorld, const wchar_t * Cmd, FOutputDevice & Ar) Line 18 C++
UnrealEditor-Engine.dll!UEngine::Exec(UWorld * InWorld, const wchar_t * Cmd, FOutputDevice & Ar) Line 4686 C++
UnrealEditor-UnrealEd.dll!UUnrealEdEngine::Exec(UWorld * InWorld, const wchar_t * Stream, FOutputDevice & Ar) Line 662 C++
UnrealEditor-UnrealEd.dll!FEditorFileUtils::LoadMap(const FString & InFilename, bool LoadAsTemplate, const bool bShowProgress) Line 2908 C++
UnrealEditor-UnrealEd.dll!FEditorFileUtils::LoadDefaultMapAtStartup() Line 4946 C++
UnrealEditor-UnrealEd.dll!FUnrealEdMisc::OnInit() Line 371 C++
UnrealEditor-UnrealEd.dll!EditorInit(IEngineLoop & EngineLoop) Line 135 C++
UnrealEditor.exe!GuardedMain(const wchar_t * CmdLine) Line 162 C++
UnrealEditor.exe!LaunchWindowsStartup(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow, const wchar_t * CmdLine) Line 247 C++
UnrealEditor.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * pCmdLine, int nCmdShow) Line 298 C++
When running the Unreal Engine project, a breakpoint is triggered in BgScriptReader.cs. The shared call stack indicates that the issue occurs during the loading of a UMaterialInstance object, specifically in the PostLoad function. This process is part of Unreal Engine’s package and map loading system.
Details from the Call Stack
The UMaterialInstance::PostLoad() function executes, and a lambda function is called, causing the breakpoint to trigger.
The process involves LoadPackage and Map_Load, which are responsible for loading maps in Unreal Engine.
The issue arises during the editor initialization process (EditorInit).
This could be caused by:
Corrupted or Misconfigured Material Settings:
The UMaterialInstance object may reference missing or incompatible assets, causing an error during the PostLoad process.
Faulty Plugin or Script:
The BgScriptReader.cs file might belong to a plugin or custom script that is interfering with the material loading process.
Misconfiguration or incompatibility of the plugin/script could trigger this issue.
Corrupted Project Files:
There might be issues with the map, material, or related assets, such as broken references or corrupted files.
Solutions
1. Examine the Code in BgScriptReader.cs
Open the file and investigate the line where the breakpoint triggers.
Review the output log to gather more details about the error.
2. Verify Material Settings
Check the materials, textures, or shaders referenced by the project.
Specifically, review the UMaterialInstance and UMaterialInstanceConstant objects mentioned in the call stack. Ensure there are no missing or corrupted assets.
3. Update Plugins and Dependencies
If BgScriptReader.cs belongs to a plugin, ensure the plugin is up-to-date and compatible with your version of Unreal Engine.
If an update isn’t available, consider reverting to an earlier, stable version.
4. Clean Temporary Project Files
Clear Unreal Engine’s temporary files to rebuild project data:
In your project directory, delete the Intermediate and Saved folders.
Rebuild the project using the Unreal Editor or your IDE.
5. Change the Default Map
The call stack references FEditorFileUtils::LoadDefaultMapAtStartup(). Try setting a different default map in your project settings to determine if the issue is tied to a specific map.
6. Adjust Debugging Settings
If you want to skip external scripts like BgScriptReader.cs during debugging, enable the “Just My Code” option in Visual Studio under Debugging > Options > General. This will ensure the debugger focuses only on your project code.
7. Search Unreal Engine Forums
If the issue persists, search the Unreal Engine forums for similar issues using keywords like UMaterialInstance::PostLoad or BgScriptReader.cs. You might find a solution or related discussion.
Conclusion
Start by analyzing the code in BgScriptReader.cs to identify why the breakpoint triggers. Clean the project files, ensure your plugins and assets are up-to-date, and test whether the problem is tied to a specific map or material. If the issue continues, adjust debugging settings to bypass external code, or consult Unreal Engine community forums for further assistance.