(Former Unity user here since their monetization “adventures”)
Hi all!
On a tile-based fighting game, I’ve done a significant amount of work in Unity. I’m looking to port most of this into Unreal.
The player operates on a manager authoritative architecture, meaning the player has to ask the Grid Manager to move him. He cannot move by himself.
In Unity, I achieved this by creating a Game Manager instance that would implement a “GetCurrentGridManager()” function. With a serialized field, I gave the player the Game Manager and he would call the function and get back the Grid Manager.
In Unreal, PlayerStart does not allow me to give a reference to my GridManager Actor before the player pawn is instantiated.
The ultimate goal is to have an AGridManager* reference in my Pawn so I can call GridManager’s functions like RequestMove() from my Pawn.
Through Blueprints, I’ve tried to store the GridManager reference in the game state, set its value from the level blueprint, then have the player pawn get it back again from the game state. However, all casts fail and the engine crashes.
How can I fix this ?
(Using the Pawn’s construction script won’t work either. I would also like to avoid using GetAllActorsOfClass since I will have A LOT of managers to reference later on)
It’s kinda hard to tell but I’ve read everywhere that using this « Get Actor of Class » multiple time may be bad for performance. I’ll for sure have more than one manager. This is a 3v3 game, if 6 players use this method to get a reference to a manager, game performance may be compromised.
Through the blueprint, Does setting a UPROPERTY() variable, from the player pawn, to have GridManager_BP (The one in the level blueprint) as a value allow me to call any function the GridManager class has ? Or do I need to expose any GridManager class function with the UFUNCTION() tag?
Create Actor “GridManager”. And then you can either reference that actor and call event in it. Or other way around GridManager finds player controller and calls events there.
Do not use level blueprint if you are not really forced to do it because:
loading order, from level blueprint you are never sure if other actors are loaded
not all can be referenced, not all nodes can be used in it
every new level and you need to make new blueprint script inside
using single actor that keeps all code for some functionality is easier to maintain later
Also with actors you can create dispatchers, add blueprint interfaces, inheritance, CPP base code class etc.