Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Setting a random position for each Entity in the JobHandle. ECS

Discussion in 'Scripting' started by JackProgrammer, Sep 19, 2021.

  1. JackProgrammer

    JackProgrammer

    Joined:
    Apr 7, 2018
    Posts:
    3
    Hello, developers. I am learning ECS but I get a problem with jobHandle.

    My task:
    I have 100.000 asteroids and I want to respawn an asteroid to a random position in a certain area, when the asteroid is far enough from the camera. I am trying to perform a position change inside jobHandle, which should work for each asteroid separately.

    Problem:
    Often asteroids are spawn in the same place at the same time.

    Questions:
    For each entity, in one Update call, the code is processed with the same data, is this caching?
    Is it possible to avoid the problem of spawning objects in the same position if several asteroids should respawn at the same time?

    Thank you!
     

    Attached Files:

  2. JackProgrammer

    JackProgrammer

    Joined:
    Apr 7, 2018
    Posts:
    3
    I have solved the problem. It turned out that the generation of random numbers in the thread does not behave correctly. This video helped: