Hello everyone. After nearly a year of developing on Unreal Engine 5 as a complete self-taught, I managed to create a visual novel. Having no knowledge of coding in general, the blueprint system was perfect for me. Everything is going more or less well until I compile my game. It works, but it uses nearly 8GB of RAM at launch! (It’s a visual novel on Unreal Engine!!). Right after launch, it gradually goes down to around 0.5GB used, which is quite acceptable.
The problem with this is that a PC that is not state-of-the-art won’t be able to load my game, causing critical errors.
I had consulted someone who assured me that the problem was due to a plugin I had purchased to help with coding. So, I rebuilt my entire game without this plugin (which managed the dialogues… so I basically remade the entire game). Initially, when there was little content, everything was fine (0.5-0.6GB at launch). I even tested it with all the game’s resources (images and videos, about 2GB in total), and it worked perfectly.
But as I gradually connected the scenes and dialogues, the game suddenly started to spike RAM usage at launch (8GB…). Disconnecting the scenes in the game allows me to reduce this figure.
It seems obvious that I’m doing something wrong with my code, but how can I ensure that the game doesn’t “load” the entire game at startup (which is what it seems to be doing, right)?
Hi! It’s great to hear you managed to create a project just by yourself, that’s impressive! Now, let me state some points here. Maybe I won’t be able to show you anything new, especially if you already consulted someone knowledgeable, but here are my thoughts on this. I think you already know that games or any other app in general uses significantly more RAM at start and this is completely normal. However spiking up to 8 when it was supposed to be 0.5 is definetly an unusual behavior. This might be because:
• Your PC capabilities. Can you also check the VRAM usage? It might be because of insufficient VRAM at the start of your project, thus it moves on by using the normal RAM. And this high RAM consumption might be explained by the difference between RAM and VRAM. Since RAM is slower than VRAM, that 8GB you see might be the equivalent of a smaller VRAM need.
• The project initialization. Even if you don’t manually load assets and algorithms all at the start of your project, you can’t really control how engine does it’s thing. I can assure you that the engine loads some stuff at the start that puts your PC on a high workload, or this issue won’t be happening in the first place. To make sure that it’s about things you’ve added, you can try using level streaming or the Unreal Insights tool to see which parts of your project require a high RAM consuption. Once you spot one, you can try temporarily removing them (including suspicious plugins) and trying launching your project that way. Remember to back up everything before you do that though!!!
If the issue persists, could you also provide your CPU, GPU and VRAM usages along with your new findings? And maybe you can try launching your project on a different PC. I hope I could be helpful, and I’m also curious of the results!
Hello and thank you for your response. I’m not too sure about the VRAM issue, but the problem isn’t with my PC. I can run the game on my PC without any problems because it’s powerful enough. But on older machines, the game crashes at startup with an error message (memory error or critical error).
So yes, I have tested it on another computer. I even tested it on a computer that can run Unreal Engine but not the game once it’s compiled!
I did try removing some content to see if it changed anything, and yes, when I “disconnect” entire parts of the game, the launch requires less RAM (I got it down to 2GB, but I think I can go lower by removing more).
Yes, I think the same. I have around 4000 images and 40 minutes of videos that make up my game. It’s not much when compared to a “big” game, but those usually don’t consume more than 2GB at startup.
I’m almost sure that my game is loading all the content at the beginning, but I don’t know how to prevent it from doing so.
How can I make it load only a part of the game? I’ve only used one “level”—is that my mistake?
Hi!
Using a single level shouldn’t be an issue, but it always comes up to how the logic is built.
How do you store these 4000 images? how do you access them?
For example, do you add these images to a single widget which then shows them based on certain conditions? are these images added to this widget using an array and a ForEachLoop on BeginPlay?
To code my game, I almost exclusively use “user widget” type widgets. I sometimes layer multiple widgets (like the dialogue system with pop-ups or a map for navigation). During dialogues, another widget is opened that handles the dialogue, and at the end, the map widget is reopened. With almost every widget change, I make sure to remove the previous widgets to avoid having too many stacked widgets (but that can’t be the issue since it’s happening at startup).
For your information, when I remove all the game’s resources (images and videos) but keep the code (blueprints and widgets), the game works normally once compiled (no more than 0.5GB of memory at launch).
What I meant was, how do you store their references within the blueprint itself? what happens on event BeginPlay of the widget responsible for showing these images?
Basically, I mainly have one “big” widget that handles almost everything visual, like dialogues, background, interface, and more. The dialogue widgets call this specific widget, and they tell it which image to display as the background, dialogue, etc.
Here’s what you can find in a widget of a dialogue scene :
Each number represents the rank in the dialogue (I could have used a database, but I find it less practical). I use functions that automate the process; for example, when I want to change the background, I use the function “Affichage Background.”
This is how I work throughout the game:
A main widget that manages images and text.
A “current” widget that represents the scene the player is in, which acts on the first widget.
In this widget, there are functions that make coding easier.
Well, that’s a lot, but it still doesn’t have 8GB…
What is the Size Map of your Pawn/Player Controller?
Also try building your project with ONLY the starter map / with a different starter map / empty starter map.
Is the problem still there?
I tried using a blank level, and it’s at 0.6GB at startup.
I did quite a few tests by changing the sizes of textures or removing references, and each time it reduced the RAM spike at startup. I tried changing the reference in my background display function to a soft reference, and I went down to 1.5-2GB of RAM at startup. However, I’m not sure if this is just because the references are no longer working (if this is the right solution, I would indeed need to change everything…).
I don’t want to upset you - but this is really the right decision.
If you have a “storage” of texture references (array, or data table) or other assets - then this is where you need to start optimization making soft references in it.
It’s certainly not exciting, but I’m at least satisfied to have found the cause and, apparently, a solution. I’m going to start making the changes, and I’ll come back to let you know if everything works.
I confirm that it was indeed the problem. I need to use soft references in my game instead of direct references because the latter force the game to load everything connected to them at launch.
Thank you again for your help!