Unreal engine loading staticmesh assets behavior problem

A couple of days ago I created a post called Unreal engine behavior problem

I now wish to report a problem and possible major bug with the unreal engine in regards to a specific problem I am having using the unreal engine.

In short, I am using c++ for my project and I am trying to load static mesh assets into the unreal engine in multiple different classes to spawn during run time. These meshes are loaded within the constructor of one Actor class, and one Character class using the ConstructorHelpers::FObjectFinder function and the line of code

ConstructorHelpers::FObjectFinder<UStaticMesh>voxel_shape(*mesh_path_name);

What was happening was that the project would crash for not apparent reason and at unpredictable times. I could not restart the unreal engine editor (it kept crashing at 71% initialisation) unless I commented out the lines of code to load the staitc mesh assets and recompiled the project. The editor would also crash when trying to open it after closing the editor after a successful coding session without performing this as well. After this,the editor would not crash when restarting. I then uncommented the above code and recompiled so as to continue on with my work. This is now occurring far too often I decided to investigate thoroughly and try to find alternative methods of loading my meshes. The whole problem is with the function

ConstructorHelpers::FObjectFinder

So I began to look for alternatives and the only alternative method available that is a LoadObject function. The line of code using this is

UStaticMesh *voxel_mesh = LoadObject<UStaticMesh>(NULL, *mesh_path_name, NULL, LOAD_None, NULL);

Using this function solved the previous problem with limited success, but again caused problems and crashed the editor.

After much intensive effort I have found this.

When I am compiling newly written code, I noticed messages deleting old .dll files for hot reload would appear in the output message panel in visual studio. When this occurred the ConstructorHelpers::FObjectFinder to load static mesh assets would all of a sudden not be able to load the static meshes it previously could and, and where I was careless and did not test for this, the editor would crash, and not be able to restart unless commenting out as describe earlier was performed.

When the using the LoadObject function to load static meshes, there is 100% success upon the first instance of loading a mesh, but any sub sequence attempt to reload any previously loaded mesh would be unsuccessful, cause a null pointer to be generated, and crash the editor were testing for this condition was not not performed. However I can restart the editor without any of the previous problems that ConstructorHelpers::FObjectFinder was causing.

So I am in a no win situation. I need to load the same mesh asset multiple times and thus cannot use LoadObject. But if I use ConstructorHelpers::FObjectFinder multiple times to load the same mesh, but while compiling code, some old hot reload .dll files could be deleted rendering the ability to find the meshes required to load null and void, and exiting the editor at any stage would crash it when trying to restart it without the commenting, recompile, start editor, uncomment, recompile method mentioned.

I consider this a major flaw and a most probable bug. If no one else has come across this or it is unknown, it would be a surprise to me.

if it is not a bug, I would like to know the correct method to perform the task of loading static meshes into an unreal project to be used multiple times without having the above described problems. I see this as a breaker to what I am doing within my project and cannot proceed much further with this behavior of UE.

I hope I was clear enough about what I have described for it to be resolved, or to inform myself and any other interested parties what is causing this and what, if any workarounds are available to avoid this.

Thanks in advance and much appreciate for any information or help that can be given.

Hello,

We’ve recently made a switch to a new bug reporting method using a more structured form. Please visit the link below for more details and report the issue using the new Bug Submission Form. Feel free to continue to use this thread for community discussion around the issue.

https://epicsupport.force.com/unrealengine/s/

Thanks

Bug report submitted. Hope it helps and I have made a correct submition.

Still having problems replying of making a comment

One thing I forgot to mention, When using LoadObject to load a static mesh, and the play button is pressed to execute the game, upon exiting the game and coming back to the editor, if one was to press the play a second time to run the game, the static mesh would not load. However if one were to close and exit the editor and reopen it, press the play button, all would be good.

In other words, when using LoadObject, I have to close the editor and reopen the project every time I have pressed the play button. Something unexpected. but perhaps a clue to the problem I have come across here.

I am sorry I have not followed up on this since submitting a bug report, and having received a reply that it could not be reproduced. But I have resorted to solving the above problem for the time being by referencing the

UStaticMesh *voxel_mesh = LoadObject(NULL, *mesh_path_name, NULL, LOAD_None, NULL);

function call outside of the constructor and unreal engine BeginPlay, This enabled the editor to behave as expected and not crash upon restarting it. I do have to restart the editor to enable the specified mesh to be loaded and not the default mesh I have set up though. Strange is by that doing the above change, the function

ConstructorHelpers::FObjectFindervoxel_shape(*mesh_path_name);

in my actor class no longer needs to be commented out as mentioned above any more.

This may be a sign that the unreal engine may now be so complex with so many interconnected dependencies and links that it is becoming a too large a beast to confidently be stable and behave as one would expect when coding and compiling in c++. Or maybe there is something I do not understand about what can and cannot be done in the constructor and BeginPlay function of am Actor or Character class.

I have just completed one of my last tests using the slate framework and found switching between huds on the same map level is slow, and deleting the old HUD can vary between a few seconds to 2-3 minutes instead of being almost instantaneous as expected. I spent this whole afternoon trying other methods thinking it was my code that was the problem , until again I realised it was the engine that was at fault, when, on a few occasions I had the editor open and did not exit my testing, found that it was just slow at deleting all the widgets on the HUD I had changed from.

Preliminaries are now over. Despite the above think I can use the UE and proceed to the next stage and continue on.

Regards