Had a quick question for the devs over at Epic. I know a lot of the community has been asking about this but I wanted to check in to see if the new GameInstance feature has been implemented and also if a fix for the following issue… EditInlineNew not working in editor - UE4 AnswerHub, was resolved in 4.2. The GameInstance is more important to me since I really need it for the prototype I’m trying to nail out over the next 2-3 months but especially for my next milestone that’s due at the end of the month. I can hold out a little longer on the EditInlineNew functionality but that will be extremely helpful once it’s available. However, if GameInstance didn’t make it in, would you suggest simply creating a plugin or module that has class that inherits from UObject and contains a static Singleton/Constructor? Thanks and looking forward to the new build
Dug through the release notes, looks like both of these missed the mark
I’m afraid GameInstance did not make 4.2. The road map indicated ‘work happening in May’ so that was never likely to be the case. Due to some other priorities (fixing some urgent bugs with Child Actor Component), we have had to push it out a bit, probably 4.4 now, sorry about that.
What problem are you trying to solve that you need GameInstance for? It will certainly make some things easier, but there may well be a way to do it already a different way.
The EditInlineNew issue hasn’t been fixed unfortunately. It was sitting on our backlog and we didn’t quite get to it. However, because of the importance I bumped its priority last week, so hopefully one of us will be getting to it soon.
We’ll make sure to post in the AnswerHub thread once it’s resolved so that you can manually pull the fix from GitHub if you want.
Hey James, thanks to you and Mike about getting back to me on these. I really appreciate it guys. 4.4, Ouch… well what I was hoping to use it for was giving the player an option for customization, and then to be able to based off of your selections, for those choices to flow down to the levels. Also, I may use it in other cases where I need data to persist in memory while the game is being run. I believe it was mentioned previously that the PlayerController was persistent across multiple deaths/spawns per level but once you switched levels, that wasn’t persistent any longer.
It’s not incredibly bad, I’m shooting on getting a prototype in its final stages by the end of July and I will be then pitching it come August/Sept to publishers and as well to show off to investors to get my new company started. GameInstance isn’t too detrimental since I could easily create a Singleton-based class that is accessible through Blueprints and if I subverted using a Singleton method, I could create a single instance within my custom GameMode and get access to it there. But then again, if I’m not mistaken, GameMode is instantiated per level, correct? If so, then that probably wouldn’t work. Also, what other classes are there that I could inherit from that do persist over the entire course of a running game instance?
That would be great Mike! I am making a in-game editor tool from Blueprints right now and this will really help in that.
Thanks to both of you, both of you and the entire team are doing a stellar job on UE4. I am blown away not only at your commitment to delivering the best engine/toolset in the industry and evolving it in a very rapid timeline but in your commitment to the community, helping us and being absolutely transparent about it’s development. And for someone like me, who just left his job to finally follow my dreams to start a video game company, I couldn’t be any more confident in taking this risk knowing I’m using UE4 and that people like you guys are making it
Thanks and if you have any thoughts about what you recommend regarding a method to subvert the lack of GameInstance and whether or not you think the options I mention above are valid, that would rock! Thanks again guys.
Assuming you’re using C++ there are a few things that you can currently do.
If you have an Actor class that is referenced somewhere like your custom GameMode you can use the GetSeamlessTravelActorList to specify the actors to maintain across the transition. Obviously you have to be using seamless travel but otherwise this is probably the easiest way to keep something alive level to level.
Another option, if working with a UObject is to add the object to the root so it won’t be garbage collected and then after your transition you can use a TObjectIterator to fish around and find it. This approach is essentially a singleton and has the distinct downside of not working in multi-client PIE, but if that isn’t a feature you’re making use of, it is an option.
Thanks Marc for the response! The second option sounds more in line with what I am looking for. When you mentioned add the object to the root, can you be more specific on what root you are referring to? And to clarify, TObjectIterator<T> will find any running instance of a specified base class that is running anywhere in your running game instance? Also one last question about the GameMode class, is it instantiated per level meaning if I switched to another level that was referencing another GameMode, that the original would be GC’ed at that point and likewise, if I switched to another level with the same referenced GameMode, is that instance destructed and recreated or does the engine persist it knowing the GameMode hasn’t changed? Thanks again for the help.
When we say add to root that is literally calling the function AddToRoot() on the UObject (there is a parallel RemoveFromRoot() function). The Root represents the root set of all objects for garbage collection. Any object in the root set is considered referenced and from there we begin the traverse to determine which objects are referenced and which should be garbage collected.
TObjectIterator is a global search of all objects. In a standalone game then saying that is running with your game instance is acurate. However, when you’re in the editor doing a PIE session this will include all objects in the editor world (the one you’re editing), preview worlds (thumbnails, persona, blueprint components panel, etc.), and all the multiplayer PIE worlds (if you’re using the PIE networking feature). You definitely want to be circumspect when using an object iterator. This particular approach is really not ideal, but it may be what you need to do for the time being until GameInstance which could be used to solve issues like this is a thing available for use.
GameMode is recreated for every level regardless of whether the two worlds reference the same class or not.
Much appreciated Marc and thanks for clearing that up for me.