This is a more detailed inquiry following up on my first post after some further debugging.
To summarize, there are two pieces of code in a project I am working with that are not executed in sequence despite the design clearly intends it to. The base idea is that for “BeginPlay()”, my GameMode Class includes C++ code that reads in data from a json file and stores the strings from each category in public member variables/UProperties of the GameMode Class (which are themselves String Arrays to store the Text lines from said JSON entries)
Subsequently, the Blueprint Function pictured is on a Widget used for one of the Rounds of the Game. Its purpose is to retrieve the RoundTwoQuestions from the GameMode Actor, and copy each index’s value into the Board’s own “Questions” array so they can be loaded during its round.
This “Set Questions” function is called on the Round 2 Board at “Event BeginPlay” by the Player Controller, which includes the BP for creating the various other Widgets needed for Scoring and displaying the other round’s questions and contains a reference to the Round2 Board instance as a Variable.
The issue that I am finding when I check output Logs is that the two functions do not execute in a consistent order between running the project in the Editor and running a Packaged version of the game.
- When run in the Editor, Log functions I included in the C++ code and the “Set Questions” BP indicate that the functions run in the expected order: “MyGameMode” executes its “BeginPlay()” code which Loads the questions from JSON into the corresponding Member Variables, and THEN it runs the “Set Questions” function from “BeginPlay()” in the Blueprints, resulting in the Round 2 Questions being populated to match the JSON file entries.
- Whereas in the Packaged version, the “Set Questions” Log statements appear first, setting the Game Mode’s Round 2 Questions as the “DefaultGame.ini” values, and assigning those to the Round 2 Board Questions array. The “Loading Questions from JSON” statements display on the immediate next Log Lines, suggesting they are executed simultaneously or immediately after, but as a result, the Game Mode loads the JSON questions AFTER it has already assign the defaults to the Board variable and thus they go unused.
What I am thus seeking is a way to ensure the C++ code for the Game Mode’s “BeginPlay()” function executes before the “Event BeginPlay” for the Blueprints (be it the Player Controller or simply the entire project). Anything like an “on event complete” or a project setting that ensures the C++ Code or order to Objects executing such function?
A significant amount of this project and code was built before I began work on it, so ideally I would also like to minimize complex refactoring (changing Blueprints to C++ or vice versa) as opposed to tinkering with Project settings or code within the Blueprints/Editor, to minimize collateral breakage or additional issues that may need fixing later.