How to use uuid in burst

as title, when i use System.Guid.NewGuid then burst show one error.

Capture

Capture

Strings aren’t supported in Burst except for specific cases. The error message clearly says the ToString call is the issue.

2 Likes

thanks your reply. someway i can convert from System.Guid to FixedString64Bytes

Based on Hash128 from Entities:

    private static readonly byte[] k_HexToLiteral = {(byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f'};

    public static unsafe FixedString64Bytes FormatHexFixedString64Bytes(Guid value)
    {
        // Guid has 4-byte alignment
        return FormatHexFixedString64Bytes(*(uint4*)&value);
    }

    public static unsafe FixedString64Bytes FormatHexFixedString64Bytes(uint4 value)
    {
        FixedString64Bytes fixedString = default;
        fixedString.Length = 32;
        for (int i = 0; i < 4; i++)
        {
            for (int j = 7; j >= 0; j--)
            {
                uint cur = value[i];
                cur >>= j * 4;
                cur &= 0xF;
                fixedString[i * 8 + j] = k_HexToLiteral[cur];
            }
        }
        return fixedString;
    }

Not the same representation as Guid, but it’s enough for presentation.

2 Likes

sorry but i get another error when use System.Guid
even I dont know where is BCrypt.dll.
when i remove System.Guid the error disappear.

Unable to load plugin BCrypt.dll
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Burst.Compiler.IL.Jit.JitBurstInitializeUtility/<>c__DisplayClass5_0:<InvokeBurstInitializeFunction>b__0 (intptr)
Burst.Compiler.IL.Jit.JitBurstInitializeUtility:InvokeBurstInitializeFunction (intptr,string,intptr)
Burst.Compiler.IL.Client.CompilerClient/LoadedLibrary:EnsureInitialized (intptr)
Burst.Compiler.IL.Client.CompilerClient:CallCallback (Burst.Compiler.IL.Client.CompilerClient/RequestedFunctionPointer,Burst.Compiler.IL.Client.CompilerClient/LoadedFunctionPointer)
Burst.Compiler.IL.Client.CompilerClient:MakeFunctionPointersAvailable (Burst.Compiler.IL.Client.CompilerClient/LoadedLibrary)
Burst.Compiler.IL.Client.CompilerClient:OnLibraryCompiled (Burst.Compiler.IL.Server.CompilationMessage/Types/LibraryCompiledMessage)
Burst.Compiler.IL.Client.CompilerClient/<>c__DisplayClass59_0/<<ScheduleCompilation>b__0>d:MoveNext ()
System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1<bool>:SetResult (bool)
Grpc.Core.AsyncStreamReaderExtensions/<ReadAllAsyncCore>d__11<Burst.Compiler.IL.Server.CompilationMessage>:MoveNext ()
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<bool>:SetResult (bool)
Burst.Compiler.IL.Server.InProcessServerStreamWriter1/<MoveNext>d__11<Burst.Compiler.IL.Server.CompilationMessage>:MoveNext ()
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()

Probably means NewGuid calls into native code somewhere and Burst can’t resolve that. It seems like the Bcrypt in question is a platform library that won’t be resolved because Burst only works with plugins in the project. You’ll need to either generate the GUID outside Burst or find/write your own number generator.

2 Likes