[Solved] NativeList is not found

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:

using System.Collections.Generic;
using Unity.Jobs;
using Unity.Collections;
using Unity.Burst;
using Unity.Mathematics;
using static Unity.Mathematics.math;
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

You need the Collections package from package manager.

12 Likes

Ah thank you. I had to show preview packages to see the collections package.

1 Like

thx!

In Unity3d 2020 there is no pkg name Collections in pakage manager . So how we can add Collections in Unity3d 2020

2 Likes

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:

2 Likes

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.

7 Likes

@Darkgaze , i’m having this exact issue… Could you explain where I reference it?

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.

6 Likes

that 's solve my problem with collection:

1 Like

cooln danke

Even including a “using Unity.Collections” statement, there is no NativeList or NativeList option currently. I’ve tried all 3 pre-release versions of the Collections package but no NativeList included anymore?

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

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.

2 Likes

I had to enable “allow unsafe code” in the player settings to be able to use Nativelist.

1 Like

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
7 Likes

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)

3 Likes

In my project the “allow ‘unsafe’ code” was already enabled. I needed to disable it, then reenable. Strange… But works now, so…