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

NativeString64 can't be found

Discussion in 'Entity Component System' started by Stuckhere, Feb 23, 2020.

  1. Stuckhere

    Stuckhere

    Joined:
    Sep 10, 2017
    Posts:
    4
    Hey all!

    I'm trying to give some NPCs names with a NameComponent, but when I try to use a NativeString64 I run into the error "Assets\Scripts\NameComponent.cs(9,16): error CS0246: The type or namespace name 'NativeString64' could not be found (are you missing a using directive or an assembly reference?)".

    Here's the code that's producing the error:


    Code (CSharp):
    1. using System;
    2. using Unity.Entities;
    3.  
    4. namespace NewUnityProject.ECS
    5. {
    6.     [Serializable]
    7.     public struct Name : IComponentData
    8.     {
    9.         public NativeString64 Description;
    10.     }
    11.  
    12.     public class NameComponent : ComponentDataProxy<Name> { }
    13.  
    14. }
    My other components seem to work fine, I just can't seem to use the NativeString64 type. I'd like to use NativeString64, so if anyone could help me fix this I would be very appreciative! Let me know if there's any other information I should provide!
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Have you got the latest collections package
     
    Stuckhere likes this.
  3. Stuckhere

    Stuckhere

    Joined:
    Sep 10, 2017
    Posts:
    4
    Hmmm, now that you mention it, my collections package looks a little funky.

    If I look under "All Packages" in Package Manager I see that I have Collections Version 0.5.2, with the "up to date" button greyed out.

    But if I look under "In Project" the Collections package doesn't appear.

    Does that sound right?
     
  4. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    209
    I think that means Collections was pulled in as a dependency for another package (probably entities?). If you toggle Advaced -> Show Dependencies it'll show
     
  5. Stuckhere

    Stuckhere

    Joined:
    Sep 10, 2017
    Posts:
    4
    Hmmm, good thinking, but I don't see it listed as a dependency for any of the packages "In Project".
     
  6. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    NativeString* has been replaced with FixedString*, pretty much 1-to-1, although they added more functions to FixedString* to bring them closer in line with string's standard api. They're in the process of phasing out NativeString* but it depends on the package versions you have.
     
  7. Stuckhere

    Stuckhere

    Joined:
    Sep 10, 2017
    Posts:
    4
    Ah so I thought about Tertle's suggestion to look at the Collections package version. Turns out it wasn't a version problem, it was a namespace problem. I just put in "using Unity.Collections;" and it worked! Here's the functioning code:


    Code (CSharp):
    1. using System;
    2. using Unity.Entities;
    3. using Unity.Collections;
    4.  
    5. namespace NewUnityProject.ECS
    6. {
    7.     [Serializable]
    8.     public struct Name : IComponentData
    9.     {
    10.         public NativeString64 Description;
    11.     }
    12.  
    13.     public class NameComponent : ComponentDataProxy<Name> { }
    14.  
    15. }
    I thought NativeString64 was part of the Entities package, my bad!

    Also, thanks for the tip recursive! I was suspecting I might have been stumbling on an outdated string solution in my google searches. Turns out MY problem was a matter of using the right package, but it's good to know about what's to come!
     
  8. DeLannoy04

    DeLannoy04

    Joined:
    Jul 2, 2019
    Posts:
    42
    Thanks man you saved my day!