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

[SerializeReference] is inaccessible due to its protection level

Discussion in 'Scripting' started by PouetLaBrouette, Mar 18, 2020.

  1. PouetLaBrouette

    PouetLaBrouette

    Joined:
    Jun 2, 2018
    Posts:
    15
    As the title says, I get this error when I try to add this attribute to my List.

    My class :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. [System.Serializable]
    7. public class C_SplineV2 : ScriptableObject
    8. {
    9.     public List<Point> points;
    10. }
    11.  
    I want to add [SerializeReference] to my list but can't because of the error.

    The Point class :

    Code (CSharp):
    1.  
    2. [System.Serializable]
    3. public class Point
    4. {
    5.     [SerializeField] public string asset;
    6.     [SerializeField] public int id;
    7.     [SerializeField] public Vector3 anchor;
    8.     [SerializeField] public Vector3 cp1;
    9.     [SerializeField] public Vector3 cp2;
    10.     [SerializeField] public List<Point> prevPoints = new List<Point>(); // semgent 1
    11.     [SerializeField] public List<Point> nextPoints = new List<Point>(); // segment 2
    12. }
    13.  
    I cannot find anyone with the same issue.
    Help will be very appreciated ! thanks !
     
    fablond likes this.
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    You shouldn't need [SerializeField] on your public members, as they'll be serialized by default if you have System.Serializable on your class.

    That said I don't know why you'd get the error. Can you copy and paste the full error message?
     
  3. PouetLaBrouette

    PouetLaBrouette

    Joined:
    Jun 2, 2018
    Posts:
    15
    Thanks for the tip ! I'll change that.

    upload_2020-3-18_17-22-45.png
    The error I get is no more than what the title says. I only get that..
     
    charmcrescini and fablond like this.
  4. charmcrescini

    charmcrescini

    Joined:
    Sep 9, 2019
    Posts:
    18
    Same issues. Any help?