Then, I add set the members of the context (a protected FMVVMViewModelContext in my HUD) and initialize a new ViewModel into the collection.
*Note that UControlsViewModel derives from UMVVMViewModelBase.
Following this, I try to access the Subsystem in a blueprint and using the protected FMVVMViewModelContext structure to recover my global ViewModel, but it does not work and stays "None.
There is still a problem for me, I wonder if you have it as well. The very first time I run the project, its still None, but after I run the game on try 2 and beyond, the ViewModel is properly recovered.
I wonder if there is something about Engine Subsystems that I am missing which would lead to this issue.
But I have found a solution which is to add a Delay until Next Tick as the very first action in my Begin Play of my bpHUD.
I wonder why it appears that the subsystem needs an extra delay to properly initialize itself, but at least I found a “fix” which is really not costly.
Maybe because the BP code I shared was in the bpHUD that is built around the cppHUD who itself deals with this engine subsystem?
This is my assumption as well, since this is the first time handling an Engine subsystem, unless a staff can actually clarify things. I only dealt with GameInstance subsystems before and never had this problem.
You could call a BlueprintImplementableEvent from c++ when it’s ready instead of begin play, or make a delegate can broadcast once it’s ready and all classes listening in would then call their event to access the subsystem.