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

Inconsistent accessibility: List issues

Discussion in 'Scripting' started by will_brett, Jul 3, 2014.

  1. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    Inconsistent accessibility: field type System.Collections.Generic.List<>is less accessible than field.

    Code (CSharp):
    1. [SerializeField]
    2.     public List<ColorBook> colorBook = new List<ColorBook>();
    3.  
    4.     [Serializable]
    5.     class ColorBook
    6.     {
    7.         public string _Name {get;set;}
    8.         public Color _Color {get;set;}
    9.         public string _ColorCode {get;set;}
    10.        
    11.         public ColorBook(string name , Color newColor, string colorCode)
    12.         {
    13.             _Name = name;
    14.             _Color = newColor;
    15.             _ColorCode = colorCode;
    16.         }
    17.     }
    I think this is saying that the list is public but "ColorBook" is not. If this is the case... then how do i make ColorBook public?
    I've tried doing

    Code (CSharp):
    1. [Serializable]
    2.    public class ColorBook
    But this didnt work and just brought up more errors
    Thanks
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    What were they?
     
  3. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    The type or namespace name `ColorBook' could not be found. Are you missing a using directive or an assembly reference?

    The best overloaded method match for `System.Collections.Generic.List<ColorBookSO.ColorBook>.Add(ColorBookSO.ColorBook)' has some invalid arguments
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    On what line?
     
  5. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    The errors are in another script that is trying to reference the first.

    This is the line that is getting the scriptableObject

    Code (CSharp):
    1. ColorBookSO asset = (ColorBookSO)Resources.Load("NewSwatchBook");
    This is the line that I am getting the errors. Its also the line that I am trying to add to the list that is in the ScriptableObject.

    Code (CSharp):
    1. asset.colorBook.Add( new (_newName, _newColor, _newCode));
     
  6. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Ok, so it looks like you have both your colorBook list and your ColorBook class defined inside of ColorBookSO (unless those are totally separate pieces of code that you put in one code block).

    So first of all you need to add public or internal to the class definition for ColorBook.
    Code (csharp):
    1.  
    2. [Serializable]
    3. public class ColorBook
    4.  
    Then, when adding to your list, make sure you specify the type. Since ColorBook is inside of (a nested class of) ColorBookSO, you need to add it like this:

    Code (csharp):
    1.  
    2. asset.colorBook.Add( new ColorBookSO.ColorBook(_newName, _newColor, _newCode));
    3.  
    4.  
     
  7. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    Brilliant that fixed it. Thank you so much.
     
  8. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    You're very welcome. ;)