sunnuntai 4. kesäkuuta 2023

Unity Job sheduler / Collections / NativeList setup in 2023

Hey, this is just a small story/note about how to get NativeList class to work in unity.

Probably my own fault for having asmdef inside scripts, folder. But live and learn.

So I was trying to get Job system to work, to offload AI calculations to multiple threads, I googled around and watched youtube videos ( https://www.youtube.com/watch?v=C56bbgtPr_w ). 

When coding, my unity installation didn't want to find NativeList class at all, NativeArray it did find inside Core.dll something, I searched and debugged, and updated unity, and upgraded Collections, installed Burst compiler, etc. nothing, forums kept talking about "jobs should only be used with dots" and other BS. Now after 3 hours of debugging, it was assembly references.

To get proper unit testing going on my scripts, I had added Assembly definitions to scripts folder, Scripts.asmdef file. To get Unity.Collections working with this setup, the Collections needs to be added to the asmdef file (from unity inspector or manually).

 

 the file itself contains: {
    "name": "Scripts",
    "rootNamespace": "",
    "references": [
        "GUID:e0cd26848372d4e5c891c569017e11f1"
    ],
    "includePlatforms": [],
    "excludePlatforms": [],
    "allowUnsafeCode": true,
    "overrideReferences": false,
    "precompiledReferences": [],
    "autoReferenced": true,
    "defineConstraints": [],
    "versionDefines": [],
    "noEngineReferences": false
}

so not that useful.. why use hash, when you could have "references": ["Unity.Collection"] .. but guess this is "the unity way, everything is a hash!". bleh.


The forum posts also tell to put "unsafe code" on in player settings.


I did both, and now stuff works.


references: