Best method to pump online systems

@SMR

Hi again!

Advance Notice = :zap: :zap: :zap: VICTORY!!! :zap: :zap: :zap:

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

:rainbow: I am very happy to report :rainbow:

That GameInstance can Run Timers That Last In-Between Level Changes <~~~~~~ :sparkling_heart: :star2: :sparkling_heart: (“OMG!” -Rama)

~

Yes!!! These Timers Will :zap: Continue Between Level Loads! :zap: (was news to me)

:rose: Yaaaay! :rose:

:star2: :rose: :star2: This is Big and Great News!!! :star2: :rose: :star2:

:star2: Especially for Your Goals! :star2:

Somebody at Epic was :rainbow: really thinking :rainbow: 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 :zap: Flow Logic :zap: (including delegates, which are so easy in BP and so necessary with any kind of async response system like Online Systems)

All of your :star2: C++ Core :star2: can be in the C++ class I showed, the template code with BP-Callable functions, so you can do the :zap: Flow of Logic in BP :zap:, 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 :rose: and the End :blossom: of Every UE Game :rainbow:


~

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

:zap: a World Context Object :zap:

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

:rose: :rose: :rose:The Awesome Unreal Engine Devs who made GameInstance So Robust! :rose: :rose: :rose:

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,

:zap: The Total Lifespan of GameInstance Object Can Be Known With One Timer! :zap:

And of course, if you know the Total Time Alive of Your Game Instance, you already have everything else,

as :zap: Tracking Time Alive Accurately is Everything in a Multi-Part Online System… :zap:

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 :rainbow:Your Case @SMR :rainbow:,

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)

:star2: Which was your main focus! :star2:


My point is, your SMR Online System UObject created by GameInstance Init,

:star2: :zap::zap::zap: will last as long as GameInstance, :zap::zap::zap: :star2:

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 :zap: One Node Static Accessor :zap:, anywhere in BP, by creating a BP Function Library

Now, with 1 node, you have access to Your UObject Online Subsystem that:

  1. In C++ has all sorts of fancy code for your External Online System API

  2. 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++

  3. Lives as long as GameInstance does (the :zap: Supreme Life Span :unicorn: for any UObject)

  4. Is being ticked by GameInstance on a Timer and given a valid UWorldContext by GameInstance itself (as per a pic above)

  5. Is Statically Accessible Anywhere in BP: Level BP, Random Actor Class, PlayerController, etc!

:zap: :unicorn: Victory! :unicorn: :zap:

:heart:

Rama

2 Likes