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

Question Serialized array [HideInInspector]

Discussion in 'Editor & General Support' started by ILonion, Jun 20, 2023.

  1. ILonion

    ILonion

    Joined:
    Oct 26, 2015
    Posts:
    51
    Hi,
    serialized array via Inspector (thousands of values); after that added [HideInInspector] like this:

    [HideInInspector]
    public Vector3[] vertices;

    array updating every frame.
    Is this slow for performance or not ?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    What does the profiler tell you?
     
    Ryiah likes this.
  3. ILonion

    ILonion

    Joined:
    Oct 26, 2015
    Posts:
    51
    I need to know - fundamentally.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    When the inspector repaints, inspected assets get serialised and deserialised. So, assets with large amounts of serialised data - even when not viewed - incur a lot of overhead.

    Usually when you're dealing with huge volumes of data, you work with it in a format Unity cannot serialise - such as a binary file - and only specifically read and write the data when needed to avoid this re-serialisation overhead.

    I think UI toolkit doesn't have this same overhead - not 100% sure. This is definitely a thing with IMGUI though.
     
    Last edited: Jun 21, 2023
    icauroboros likes this.
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,083
    Would a private field that isn't marked with SerializeField work too?
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    Should work, but naturally nothing would be drawn in the inspector and no data would persist. That and Unity does serialise private fields not marked with
    [SerializeField]
    in some contexts too (such as domain reloads), so often you want to explicitly mark it with
    [NonSerialized]
    to prevent this too.

    Depends on exactly what OP is trying to do.
     
    danishgoel and Ryiah like this.
  7. ILonion

    ILonion

    Joined:
    Oct 26, 2015
    Posts:
    51
    In other words this situation bad for developer - slow Inspector repaint, slow UI for work, isn't it ?

    What about standalone .exe build for target user same situation?

    Clarify please.
     
  8. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    Only if you don't have the hardware for it, or don't do what I suggested.

    Somewhat unrelated honestly. There's no inspector to be repainting and re-serialising assets. Once assets are loaded (which includes de-serialising), that's it. Larger assets make take longer to de-serialise, but tools like addressables can be used to spread out the overhead with async code.
     
    Ryiah likes this.
  9. ILonion

    ILonion

    Joined:
    Oct 26, 2015
    Posts:
    51