简体   繁体   中英

Unity inspector can't edit public array's values

I want a script that has a public array so that I can modify the values in the inspector. Here's an example script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Foo : MonoBehaviour
{
    public int[] bars;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

When I add the script to a game object, I can see the empty list in the inspector (as expected).

在此处输入图像描述

But when I add elements to the array, the array area is just blank so I can't set the value of each element (or see what the element values are).

在此处输入图像描述

Is this just a bug, or am I doing something wrong?

I'm running Unity 2021.2.5f1 on macOS Monterey 12.0.1.

I had this same problem after upgrading to a new version of Unity, and I discovered that it works if I move the editor window over to a different screen. Maybe because my main screen is widescreen? I dunno, I can't explain it. If I move the editor back to my main screen, they disappear again. So for now, I just adjust the values on my smaller side-screen, then move back when I'm done. If you don't have more than one screen, perhaps try to change the resolution or something.

May be not the best solution but, definin your own serializable int struct may works.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public struct MyInt
{
    public int Int;
}

public class Foo : MonoBehaviour
{
     public MyInt[] bars;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

I'm having the same issue with 2021.2.7f1 and 2021.2.6f for Unity Apple Silicon. For example if I create an array for say animation sprites and want to drag the sprites into the inspector. They don't display in the dropdown. It's just blank like the above screenshot.

Oddly enough I opened another older project that I converted to the newer unity version that was a duplicate of the same project I was rebuilding for practice and the arrays were displaying as they should.

Edit: Wow, so the list displays on my M1 Macbook but not on my external display.

I'll let you know if I find a solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM