Tell me can Threads Be Used To Modify A Texture On Runtime?
Can Threads Be Used To Move A Gameobject On The Scene?
Consider The Snippet Below:
Class Randomgenerator : Monobehaviour
{
Public Float[] Randomlist;
Void Start()
{
Randomlist = New Float[1000000];
}
Void Generate()
{
System.random Rnd = New System.random();
For(int I=0;i }
}
Improve This Code Using Threads, So The 1000000 Random Number Generation Runs Without Spoiling Performance.?
Submitted by: MuhammadNo. Texture and Meshes are examples of elements stored in GPU memory and Unity doesn't allow other threads, besides the main one, to make modifications on these kinds of data.
No. Fetching the Transform reference isn't thread safe in Unity.
When using threads, we must avoid using native Unity structures like the Mathf and Random classes:
class RandomGenerator : MonoBehaviour
{
public float[] randomList;
void Start()
{
randomList = new float[1000000];
Thread t = new Thread(delegate()
{
while(true)
{
Generate();
Thread.Sleep(16); // trigger the loop to run roughly every 60th of a second
}
});
t.Start();
}
void Generate()
{
System.Random rnd = new System.Random();
for(int i=0;i<randomList.Length;i++) randomList[i] = (float)rnd.NextDouble();
}
}
Submitted by: Muhammad
No. Fetching the Transform reference isn't thread safe in Unity.
When using threads, we must avoid using native Unity structures like the Mathf and Random classes:
class RandomGenerator : MonoBehaviour
{
public float[] randomList;
void Start()
{
randomList = new float[1000000];
Thread t = new Thread(delegate()
{
while(true)
{
Generate();
Thread.Sleep(16); // trigger the loop to run roughly every 60th of a second
}
});
t.Start();
}
void Generate()
{
System.Random rnd = new System.Random();
for(int i=0;i<randomList.Length;i++) randomList[i] = (float)rnd.NextDouble();
}
}
Submitted by: Muhammad
Read Online Unity 3D Developer Job Interview Questions And Answers
Top Unity 3D Developer Questions
☺ | Explain me what Is The Function Of Inspector In Unity 3d? |
☺ | Tell us what Is An Unity3d File And How Can You Open A Unity3d File? |
☺ | Tell us in Unity 3d How Can You Hide Gameobject? |
☺ | Explain me total Sessions Today? |
☺ | Do you know what Is Prefabs In Unity 3d? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |