How to reduce lag when playing in editor viewport

Hello
I’m currently designing a programme that would instruct users where to move an object in real time, but after a set amount of time after I press play, the game lags and I’m not sue what causes it.


As you can see from the image I have widgets demonstrating the direction the object needs to move and have objects describing the distance as well. I am quite new to using unreal so I am sure I have made a mistake with using blueprints in a certain way that would cause large amounts of lag but I can’t find out what the issue is.

Just to add some more information that I just noticed, the lag builds up each time the widgets are recreated after they have been removed. The widgets are created each time the object is moved away from its initial position which can be seen as the translucent version of the object. Is there another way around removing and creating widgets as this may be the cause of the lag

is very hard to help you without see what you did.
Compiled versions always runs a lot faster than PIE but watching your screenshot
is very clear you are doing something wrong and draining all performance of the app.

you don’t need to create and destroy a widget every time you need it.

just create the widget, store in a variable and add to viewport when needed and remove from parent when is not needed but you still have the widget stored in memory this way.

2 Likes

Thank you for the quick response. You comment helped and made me realised that the remove from parent command didn’t delete the widget but removed it from the viewport so each time the widget was removed from the parent, I would make another widget unnecessarily.

actually remove from parent, if you widget is not referenced anywhere else, it will be catched by the garbage collector and destroyed from memory, but anyway each time you do a ‘create new widget’ you are actually creating a new one and using a lot of space and resources in the process. Same happens with spawning actors in the scene. Spawning a lot of actors all the time is very consuming and expensive so you should always try to think into recyclable approaches :slight_smile:

3 Likes