Search Unity

Bug Visible Button element has a side effect on Random.state

Discussion in 'UI Toolkit' started by jne0xff, Sep 28, 2019.

  1. jne0xff

    jne0xff

    Joined:
    Jul 13, 2015
    Posts:
    7
    Hi! I'm experiencing a rather strange side effect of UIElements.Button: whenever this button is visible Random.state is changed right after the third frame (as if something queries Random.value once). Is it a known behavior or something is wrong here?
    I've checked it on Unity 2019.2.4f1 & 2019.2.6f1 (Windows)

    Just in case, I'm attaching a sample project to demonstrate it. Scene is located in Assets/SampleScene.unity. In the demo I have a single object, which monitors Random.state. Normally, if you would run the game without any opened custom windows, you would see this output in the logs:
    Code (Text):
    1. Frame 0/0: Random.state changed from {"s0":0,"s1":0,"s2":0,"s3":0} to {"s0":123456,"s1":848462657,"s2":1590858150,"s3":479153279}
    But if you open my custom window under "Window/Random State Window" and then hit "Play" with this window opened, you will see an additional line:
    Code (Text):
    1. Frame 0/0: Random.state changed from {"s0":0,"s1":0,"s2":0,"s3":0} to {"s0":123456,"s1":848462657,"s2":1590858150,"s3":479153279}
    2. Frame 2/2: Random.state changed from {"s0":123456,"s1":848462657,"s2":1590858150,"s3":479153279} to {"s0":848462657,"s1":1590858150,"s2":479153279,"s3":328449612}
    The reason I noticed it is because I'm using a Unity Recorder to record the game over and over again (each game run should be identical to the previous). And since Unity Recorder editor uses UIElements, the gameplay becomes different when I open or hide Unity Recorder, which is frustrating
     

    Attached Files:

  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
  3. jne0xff

    jne0xff

    Joined:
    Jul 13, 2015
    Posts:
    7
    Thanks for the clarification! I will be waiting for the fix then and use your suggested alternatives in the meantime