Hi again!
Advance Notice = VICTORY!!!
The part I was puzzling over is that you want a tick function, but don’t necessarily have an active UWorld, because levels could be up or down.
I ran some tests using GameInstance + a UObject BP
I am very happy to report
That GameInstance can Run Timers That Last In-Between Level Changes <~~~~~~ (“OMG!” -Rama)
~
Yes!!! These Timers Will Continue Between Level Loads! (was news to me)
Yaaaay!
This is Big and Great News!!!
Especially for Your Goals!
Somebody at Epic was really thinking when they did this part involving timers in GameInstance!
Here’s my GameInstanceBP (no C++ Code)
(JoyFlow = SMROnlineSystems UObject, template code of which is below)
Here’s my UObject, basic C++ of which is below:
Creating a BP of a UObject with a C++ Core
#pragma once
#include "CoreMinimal.h"
//#include "UObject/ObjectMacros.h"
#include "UObject/Object.h"
//#include "UObject/UnrealType.h"
//#include "UObject/ScriptMacros.h"
#include "JoyFlow.generated.h"
//<~~~~ "Blueprintable" This is what allows you to do
// all the Async Logic Flow with Easy-To-Use Delegates and Events in a BP of UObject,
// while running all the C++ Core via BP-Callables as you see below
// ♥ Rama
UCLASS(Blueprintable,BlueprintType)
class UJoyFlow : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Joy Flow")
float YourVarsYouWantAccessToFromBP = 3.333f;
UFUNCTION(BlueprintCallable, Category = "Joy Flow")
void StartSMRVictory()
{
// Functions that can be launched to Your SMR API as soon as GameInstance
// runs Init() and creates this UObject (loooong before any world is even loaded!)
}
UFUNCTION(BlueprintCallable, Category = "Joy Flow")
void FancySMRAPILogics();
};
.cpp
#include "JoyFlow.h"
//other classes you want to use
//#include "JoyBPLibrary.h"
void UJoyFlow::FancySMRAPILogics()
{
}
The above code allows you to create a BP of the UObject base C++ class.
So now you can do all your Flow Logic (including delegates, which are so easy in BP and so necessary with any kind of async response system like Online Systems)
All of your C++ Core can be in the C++ class I showed, the template code with BP-Callable functions, so you can do the Flow of Logic in BP , while the C++ does what it does best, connecting to external systems that you wrote that use C++.
You can then create this BP in your GameInstanceBP, again, with Speed and Ease in the Init() of your GameInstance.
GameInstance can ensure stability of your reference, as your UObject won’t go anywhere, because GameInstance will NEVER go anywhere
As You Know (writing for benefit of other readers):
GameInstance is first and last, the Beginning and the End of Every UE Game
~
The issue is ticking during a level change in my mind…
Rama Update: The Joyous News
The Truly Joyous News (Made My Day Anyway…) is that GameInstance CAN act as
a World Context Object
that is stable during Level Changes
Meaning, GameInstance is having its UWorld updated as Levels change, so I can print out the float without concern of what level’s UWorld GameInstance is using, it is auto-updated for me by
The Awesome Unreal Engine Devs who made GameInstance So Robust!
Proof
As you can see in the console:
I changed my current level multiple times, and the Counter kept steadily increasing of Total GameInstance Time Alive (as opposed to GameState and GameTimeSeconds, which would only report the time for the current level, resetting to 0 with each level change)
So that means, @SMR, That you CAN track the total time your entire Game setup has been alive, even between level loads,
The Total Lifespan of GameInstance Object Can Be Known With One Timer!
And of course, if you know the Total Time Alive of Your Game Instance, you already have everything else,
as Tracking Time Alive Accurately is Everything in a Multi-Part Online System…
Because as long as that float keeps increasing, you know your Systems Are Live!
Of course, I could only see the print out of the current time while a level was loaded, because it prints to the viewport
But the great news in Your Case @SMR ,
is that means you only have to connect to your external architecture once, inside the BP or the C++ Code of your UObject (My template code for you above)
Which was your main focus!
My point is, your SMR Online System UObject created by GameInstance Init,
will last as long as GameInstance,
because Your Custom Object, with all the Ease and Speed of Blueprints, is not dependent for its lifespan on anything other than the UObject reference in the GameInstance itself.
Real Time In Between Levels?
Please note, if you find there’s a gap in the timer during level changes (It looks accurate in my pic, but just in case)
You can use this instead:
FApp:GetCurrentTime()
How Do I Access My OnlineSubsystem Statically, From Anywhere?
I don’t know if this is obvious to You @SMR but for other people’s sakes:
Now that your UObject is live, created and ref stored in Your GameInstance, you can create a One Node Static Accessor , anywhere in BP, by creating a BP Function Library
Now, with 1 node, you have access to Your UObject Online Subsystem that:
-
In C++ has all sorts of fancy code for your External Online System API
-
In BP, is handling the calling of the fancy C++ code with the Joyful Flow of BP Events / Delegates, timers, everything that is so easy and fast to do in BP as compared with C++
-
Lives as long as GameInstance does (the Supreme Life Span for any UObject)
-
Is being ticked by GameInstance on a Timer and given a valid UWorldContext by GameInstance itself (as per a pic above)
-
Is Statically Accessible Anywhere in BP: Level BP, Random Actor Class, PlayerController, etc!
Victory!
Rama