- Home /
Queue and Threading
How would I go about making a queue, I have tried a couple of things but never got it working. So do you have any good points to start on this? :) I am trying to queueing something on another thread and then when it is done it executes some script on the mainThread, and then goes on to the next in the line.
This is a general program$$anonymous$$g question. The Queue generic collection in System.Collections.Generic is perfectly suited for this - usually.
What exactly do you want to put in this queue? Using multiple threads can cause plenty of problems.
The Task class is a reasonable way to do it. There are other ways. Due to Unity's avoidance on threads you won't find too many people here who do heavy multi threading.
How would I assign a type to my queue (in JS) I have tried like this, but without any luck:
class info {
var Test : int;
var Test1 : int;
}
var queue : Queue.<info>;
function Start() {
queue = new Queue.<info>();
}
but when trying to call it like this:
Debug.Log(queue.Peek.Test);
it gives me this error:
BCE0019: 'Test' is not a member of 'function(): info'.
The type of the queue.Peek is:
CompilerGenerated.PT_Update$callable0$210_57
@ExtremePowers:
`Peek()` is a method, so you need to execute it by adding the brackets (the calling operator). However be sure you "queued" something or Peek will fail with an exception.
Answer by ExtremePowers · Nov 06, 2014 at 04:42 PM
Yeah, I know that unity isn't thread safe and so on, but I needed this feature to make the terrain generate without having that 1 second lag.. I don't use Random on the other thread, only on the main thread...
Wow, I feel really stupid now, I could just have used yield null; in the for loop each time z equals heightmapWidth, it would take some time for the terrain to be assigned, but that doesn't matter because the viewdistance isn't far enough to see the new generated terrain, while it is loading.
Your answer
![](https://koobas.hobune.stream/wayback/20220613170823im_/https://answers.unity.com/themes/thub/images/avi.jpg)