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 HowTo: NativeText to float ?

Discussion in 'Burst' started by davidwiggins, Jul 11, 2023.

  1. davidwiggins

    davidwiggins

    Joined:
    Mar 27, 2023
    Posts:
    4
    I'm seeing the following error while trying to parse some floats out of some NativeTexts I'm passing into a job via a NativeHashMap.

    Code (csharp):
    1. C:\GitLab\Unity Projects\sim-studio\SimStudio\Assets\Scripts\Simple Earth 3D\SpawnManager.cs(228,1): Burst error BC1016: The managed function `Unity.Collections.NativeText.ToString(Unity.Collections.NativeText* this)` is not supported
    2.  
    3.  at SpawnManager.UpdateSatellitePositionsJob.Execute(SpawnManager.UpdateSatellitePositionsJob* this, int index, UnityEngine.Jobs.TransformAccess transform) (at C:\GitLab\Unity Projects\sim-studio\SimStudio\Assets\Scripts\Simple Earth 3D\SpawnManager.cs:228)
    4.  at UnityEngine.Jobs.IJobParallelForTransformExtensions.TransformParallelForLoopStruct`1<SpawnManager.UpdateSatellitePositionsJob>.Execute(ref SpawnManager.UpdateSatellitePositionsJob jobData, System.IntPtr jobData2, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex)
    5.  
    6. While compiling job:
    7. UnityEngine.Jobs.IJobParallelForTransformExtensions+TransformParallelForLoopStruct`1[[SpawnManager+UpdateSatellitePositionsJob, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null::Execute(SpawnManager+UpdateSatellitePositionsJob&, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null|System.IntPtr, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|System.IntPtr, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|Unity.Jobs.LowLevel.Unsafe.JobRanges&, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null|System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
    Example code of what I'm trying to do

    Code (CSharp):
    1. //*** As input to a job
    2. NativeHashMap<NativeText, NativeText> record = new NativeHashMap<NativeText, NativeText>(3, Allocator.TempJob);
    3. record.Add(new NativeText("abc", Allocator.TempJob), new NativeText("123", Allocator.TempJob));
    4. record.Add(new NativeText("bcd", Allocator.TempJob), new NativeText("234", Allocator.TempJob));
    5. record.Add(new NativeText("cde", Allocator.TempJob), new NativeText("345", Allocator.TempJob));
    6.  
    7.  
    8. //*** Later inside of a job that's Burst compiled
    9. float x = float.Parse(record[new NativeText("abc", Allocator.TempJob)].ToString());
    10. float y = float.Parse(record[new NativeText("bcd", Allocator.TempJob)].ToString());
    11. float z = float.Parse(record[new NativeText("cde", Allocator.TempJob)].ToString());
    12.  
    13. Unity.Mathematics.float3 myVector = new Unity.Mathematics.float3(x,y,z);
    Question
    - Is it possible to pass a string into a burst compiled job and extract a float value from it? How?
     
  2. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    274
    https://docs.unity3d.com/Packages/c..._0__System_Int32__System_Single__System_Char_
    You can easily find the above method by just searching "Parse" in the search box for that package's documentation. Get into the habit of digging around on the internet a bit.