Where i should initialise a Nakama client?

Hi! As I see in Unreal client tutorial (Unreal client guide - Nakama server) the client is created as a global variable and its tick is called in the actor, but is this logical? The actor is not a permanent entity and is removed from memory upon death / level change, etc, therefore the connection will be interrupted. I am thinking of placing the client’s tick in the gamemode, but I don’t know how long this is a good idea.

Hey @elagin, where you decide to invoke the tick() method is ultimately up to you, but here are some considerations:

(1) Calling the tick method from the gameplay thread (e.g., an actor) is an easy way to get started because when events are dispatched from our client and socket, they can immediately drive gameplay.

(2) Calling the tick method from its own thread can lead to more reliable/predictable performance because you aren’t tying gameplay to networking processing. In Unreal it may make sense to do this earlier in the game dev lifecycle compared to Unity since creating singleton actors does not appear to be an idiom.

As for calling tick from an actor: What I’d do is have an actor in each scene responsible for calling tick. I’d have the network code in a GameInstance or subclass. There will be no interruption of connection due to an actor being garbage collected if an actor in the next scene is ready to keep calling tick.

2 Likes

Hello, I managed to create class “Manager” which is aggregated by GameInstance class and created tick-function in it. Then, I call tick-function of Nakama class, in tick-function of my GameInstanceClass. Hopefully, this solutions is quite legit, no issues occured so far. Thank you for your attention!

King regards, Dmitry.

2 Likes