Createing a Uobject in a seperate thread

I need to create several large UTexture2D objects at runtime and fill the mipdata. but doing so freezes the game until the have all been created. And I know that Uobjects currently are not thread safe. Is there anyway safe way to do this in a seperate thread?

I don’t think there is a safe way to do this right now. Core Team is currently working on thread-safe UObject creation and destruction, however. I will assign someone who may have more details on this matter (I am desperately waiting for it as well :slight_smile: )

Please do me a favor Gerke and let me know when we have multi-threading + UObject subsystem, that will be a game changing event!

:slight_smile:

Rama

Is there any news on this yet?
I noticed that there was some mention of improvements to Uobjects for 4.6
But im not sure if thats in relation to multi-threading.

According to this thread it’s available, but you still need to be careful about how you interact with them. (Maybe also that your target object won’t be garbage collected during your access.) I can’t find any more information than that.

Hey hey

I managed to solve this issue pretty simply. and now can create threads in blueprints and in them create Uobjects
So here is a hint.

create a structure for jobs to enqueue on the game thread
create a : TQueue jobArray;
have a function that just Enqueue to this queue. then use it in your thread to enqueue jobs in the game thread.
Now in the Tick function have something similar to the following

FJobEnqueueStruct* currentJob=nullptr;
if( JobQueue.Dequeue(currentJob) )
{
  // call a function or a blueprint implementable Ufunction
}

Tqueue is thread safe so there is no concern about it. and this way you can even design you nodes that to be run on the game thread via blueprints

I have solve this issue while writing my own custom Kinect plugin.
create your textures outside of the thread code and in the class which you handle the thread or in the actual thread code just keep a pointer to the texture ( UTexture2D* texture ) this way you can simply modify the texture in your code.

Hey any updated on it ?
I tried spawning UObject/UActorComponent from different thread. While it somewhat worked it was hardly safe as GC just cloudn’t handle it.
Adding hardreferences to rootset somewhat helped, there were still occsional crashes (unrelated to my code, as my test object didn’t do anything special).