Search Unity

[Solved] NativeList is not found

Discussion in 'Entity Component System' started by sk8terboy4, Apr 12, 2020.

  1. sk8terboy4

    sk8terboy4

    Joined:
    Mar 29, 2013
    Posts:
    29
    I am having issues importing NativeList. It is not able to find the struct. I am able to import NativeArray just fine.

    Here are my imports:
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using Unity.Jobs;
    3. using Unity.Collections;
    4. using Unity.Burst;
    5. using Unity.Mathematics;
    6. using static Unity.Mathematics.math;
    7. using UnityEngine;
    I also noticed that many of the other containers such as NativeQueue, NativeHashmaps, etcs are not there as well. I am using Unity 2019.3.9f1

    Any ideas what could be going wrong?

    Thanks
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    You need the Collections package from package manager.
     
  3. sk8terboy4

    sk8terboy4

    Joined:
    Mar 29, 2013
    Posts:
    29
    Ah thank you. I had to show preview packages to see the collections package.
     
    Wiseman17 likes this.
  4. Feartheway

    Feartheway

    Joined:
    Dec 12, 2017
    Posts:
    92
  5. MobinYaqoob

    MobinYaqoob

    Joined:
    Jun 26, 2014
    Posts:
    12
    In Unity3d 2020 there is no pkg name Collections in pakage manager . So how we can add Collections in Unity3d 2020
     
    jorikito and PrimalCoder like this.
  6. shmafoo

    shmafoo

    Joined:
    Nov 22, 2016
    Posts:
    24
    You have to add the URL manually in the package manager (easier) or edit the manifest file (more error prone).
    There's a good informative video out there:
     
    Mr_Banana12344 and PrimalCoder like this.
  7. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    397
    Also be aware that if you have an assembly set up for your code using NativeList, you will have to reference the Unity.Collections assembly on its list of references. NativeArray, on the other hand, doesn't need it.
     
  8. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    @darkgaze, i'm having this exact issue... Could you explain where I reference it?
     
  9. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    397
    Sure. If you have an assembly defined for the current file (assemblies take whatever is in the same folder or the folders inside it), then click the assembly file in the project view (it is an ".asmdef" file), and in the inspector you will see a section called "Assembly Definition References". You have to add there the Unity.Collections assembly. If it's not available that means you haven't added the Collections package on the Packages Manager window (or whatever the name was before 2019).

    This means : In the files inside this assembly I'm using stuff from this OTHER assembly". Then click apply at the end.
     
  10. rycsim

    rycsim

    Joined:
    May 18, 2018
    Posts:
    1
  11. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    cooln danke
     
  12. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    69
    Even including a "using Unity.Collections" statement, there is no NativeList or NativeList<T> option currently. I've tried all 3 pre-release versions of the Collections package but no NativeList included anymore?
     
  13. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    284
    You need to reference the Unity.Collections assembly. This is different than importing the namespace.

    You can easily verify that the NativeList file is there, look for this file:
    Library/PackageCache/com.unity.collections@0.15.0-preview.21/Unity.Collections/NativeList.cs
     
  14. franco_du_preez

    franco_du_preez

    Joined:
    Dec 26, 2017
    Posts:
    1
    Thanks Darkgaze, this fixed the situation for me where Visualstudio could not recognize NativeList despite the preview Collections package being shown as loaded and available in the Unity Editor and Package Manager. I did not know where to find and existing Assembly Defintion Reference in the project as I have not used them before, so I created a new empty Assembly Definition References file through Project>Create>Assembly Definition Reference in Unity and only included Unity.Collections in it and that worked.
     
    Last edited: Dec 19, 2021
    Darkgaze likes this.
  15. Easterday

    Easterday

    Joined:
    Mar 17, 2015
    Posts:
    5
    I had to enable "allow unsafe code" in the player settings to be able to use Nativelist.
     
    Sabso likes this.
  16. unity_3KAIcHNkHzTZvw

    unity_3KAIcHNkHzTZvw

    Joined:
    Oct 5, 2020
    Posts:
    6
    I have been looking for this one tiny piece of the puzzle for two whole days - thankyou so much.

    To anyone else still struggling, my full process to enable NativeList and other containers in 2020.3 was:
    - In package manager, click + icon top-left, and add Git repo: com.unity.entities
    - In Project settings, under 'Player\Other\Script Compilation' enable 'Allow unsafe code'
    - In IDE add 'using Unity.Collections' statement to script
     
    faustov14, kidi0892, Alex_May and 3 others like this.
  17. Goularou

    Goularou

    Joined:
    Oct 19, 2018
    Posts:
    54
    Entities are NOT needed: your solution works because it will add Collections in addition to a bunch of other packages
    If you don't want to use Entities (but you should someday, very efficient so recommended), just install "Collections" in Package Manager / Unity Registry (select it in the long list, and click on Install (Remove in the screenshot below as mine is already installedon the top-right corner)
    upload_2023-5-6_3-9-39.png
     

    Attached Files:

    MHS2017 likes this.