I have been playing around a bit with the editor and only recently wanted to go at it in earnest with a couple of friends.
As some may have guessed we need to have some manager classes for all kinds of things and for this purpose the UGameInstance class looks really promising.
It is initialized once(not counting running editor) and exists across levels. Info and docs respectively:
It all seems good except there is no tick function on the UGameInstance class. Not only that but after taking a look at the AGameMode class it seems the UGameInstance class could use more than just at tick function. Being able to tell when a level is loaded would be nice as well. I would not regard that as duplicate behavior of the AGameMode class as each of them could/should make use of this. Also the AGameMode seems to only exist on the server side in a multiplayer game.
After some more digging around I learned that the UGameInstance could implement the FTickableGameObject to get a tick function. The other of the tick however cannot be changed and to make matters worse is done so after the actors.
It seems the UGameInstance was only first introduced in 4.4 and as is stated in the links its purpose was for cross-level storage of data and it seems to have been stuck with only that purpose in mind. I have searched around trying to find a solution to this but have been unable to find any (at least properly supported ones). I find game managing and the likes much more obvious and essential than storing some game data across levels which could be handled on disk(not that it should) and the lackluster UGameInstance is odd.
So far I can think of two ways of trying to handle ticking in a UGameInstance subclass.
- Modify the source code and recompile the engine which is something I would rather not. It also seems silly having to do this for something so basic and simple yet essential.
- Create a special tick actor which has components that each calls a different tick function on a custom UGameInstance subclass. With this the tick group can be specified as well. This seems reasonable although the UGameInstance is still lacking and this should really not be neccesariy (I know I have mentioned this several times by now). I can see some issues with this though. One is that there are only a handful of tick groups defined and done so with an enum leaving no option for expansion unless the source code is tinkered with. Unless I remember wrong the first ticking group is in use by the actors among other classes. In other words is is not possible to have a tick before the actors. Another problem is that an actor gets destroyed when a level is unloaded which means the actor would have to be recreated. What happens in between? Would there simply be no ticks? What about having no level loaded at all not regarding a transition. Can this actually happen? What to do about updating a loading bar on level transition? Something somwhere needs to continually refresh it.
I would like to hear opinions of others on this and possible better ideas/solutions for it. I can’t imagine creating a game without this functionality and I find it odd that it wasn’t until 4.4 the UGameInstance class was introduced in the first place. I have used the Unity editor to some degree as well and it too lacks anything like this as well. It did however allow an arbitrary number of ticking groups to be set simply with an integer which despite being a bit ugly did work. Based on this I may just be the odd one here and there are some other better ways for doing said things.
After I wrote this I forgot to mention we are working on this part in c++ not blueprint:P