This post is related to my last post about storing a pointer to a blueprint in a subsystem. You can read about that here.
The new problem I’ve run into has to deal with my subsystem not responding to assignments or function calls at startup of my program. Here is the blueprint graph, and an explanation on how it works.
I built a small program that gives a multiple choice quiz to the user. I have a blueprint class that is my game instance, and the Event Init is called as soon as the program starts. I have a QuizManager subsystem that holds all the quiz data and a pointer to a Widget Blueprint that has a C++ base class. The Event Init is meant to initialize the UI and store it in the subsystem, as well as tell the Quiz Manager to load the quiz data by reading it from some xml files. I extended a test wire from the init to the start quiz to test if the quiz presentation was working.
The Start Quiz event starts the quiz and presents the questions to the user. My downcast to the blueprint class kept failing for some reason, and after debugging it for a while I realized that for whatever reason all my interactions with the Quiz Manager subsystem were failing. All assignments and function calls are just stepped over when I try to debug and not call my C++ code. This lead to a failed downcast of the Quiz Widget which would prevent the quiz from running. Debugging some more I added a delay between the LoadQuizData call and the Set of the Procedure name. Now my InitQuiz function is being called, but LoadQuizData isn’t being called, and the downcast is still failing. Next I tried to promote the BP_QuizWidget to a variable and store it in the game instance as soon as it’s created instead of the subsystem. This solved the downcasting problem, but it also made it clear that the creation of the widget wasn’t the problem, the problem was trying to store a pointer to it in the subsystem.
So then I moved the delay call to the start of the Init, and deleted the local BP_QuizWidget variable and stored it back in the subsystem. Now everything works perfectly. If I remove the Delay call everything stops working because the subsystem ignores all interactions. I don’t understand why this is behaving the way it is, and I’m hoping that someone here can provide an answer.
A few possible theories:
Subsystems are not initialized on startup?
A race condition between subsystem initialization and blueprint graph execution?
I’m dumb and didn’t implement this correctly?
Any help or insight would be appreciated, thanks in advance!