Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Unity.Mathematics.Random missing InitState?

Discussion in 'Scripting' started by SuperFranTV, Nov 4, 2022.

  1. SuperFranTV

    SuperFranTV

    Joined:
    Oct 18, 2015
    Posts:
    140
    Hello guys,

    Base Informations:
    Unity version 2022.1.14f (workes nice for me till this point)
    Mathematics v1.2.6
    using Unity.Mathematics is implemented in script

    The Problem only these 3 options are shown:
    Unity.Mathematics.Random.CreateFromIndex
    Unity.Mathematics.Random.Equals
    Unity.Mathematics.Random.ReferenceEquals

    is this a bug or do i missing something?

    Thanks in advance
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,511
    What do you mean by this?

    You should show your usage. You don't state if you're trying to figure out how to use it or if you've used it correctly in the past but now something has gone wrong with your setup. Are you asking how to use it?

    I presume you've created an instance of the Random class and are calling from that? CreateFromIndex is Static so it's called from the Type.
     
  4. SuperFranTV

    SuperFranTV

    Joined:
    Oct 18, 2015
    Posts:
    140
  5. ronJohnJr

    ronJohnJr

    Joined:
    Mar 5, 2015
    Posts:
    106

    you're not supposed to use mathematics. Delete that line. Random is built into unity engine
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,862
    Well read the docs closer. You're using them like static functions when they're not. You need to make an instance of Unity.Mathematics.Random first, as @MelvMay already pointed out.
     
    MelvMay and Kurt-Dekker like this.
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,511
    You already said that in your first post but hey, don't read/reply to what I wrote. ;)

    I would strongly suggest learning the basics of C#. You should understand that to access methods that are not Static, requires you to create an instance of the type. Static methods are accessed by the Type without the need for an instance as I stated in my first reply.

    Regardless, it should be pretty clear you do:
    Code (CSharp):
    1. var myRandom = new Unity.Mathematics.Random();
    2. myRandom.NextFloat();
     
    SuperFranTV likes this.