2

I'm working with reorderable lists in Unity right now and I can't seem to figure out how to update the 'max items' field that is visible in the inspector from a script. I'm a little new to Unity so I might be missing something easy but I didn't see any way from the listed methods or properties to update this field. Just looking to set the max items in a reorderable list to the size of a Dictionary that I have populated.

Any help would be appreciated. Thanks.

Edit: Just to be clear, the value I'm trying to change is the bottom one in the screenshot below: enter image description here

I've tried things along the lines of listName.maxValue = X, listName.maxSize = X, but (at least out of what Visual Studio Code is showing me) there is no method available to change this value. I even tried opening the Reorderable List script (which is from an imported package) and adding my own method for it but it is still throwing an error after trying to use it.

SgtRats
  • 23
  • 4
  • Please add your code. – derHugo Mar 02 '21 at 13:41
  • There isn't really any relevant code that I have for this in the sense that I'm just not sure what method(s) to use to access and change this value. Just to be clear, I'm using a ReorderableList package that I found on github. – SgtRats Mar 02 '21 at 14:07
  • Please add the link or source code then. In case it's [this one](https://gitlab.stimulate.ovgu.de/Drittel/starccm_to_unityvfx/-/blob/de07a5119e100047df40e92be19dd0694204630b/Assets/unity-ui-extensions/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs) I don't see what's wrong .. please include the exact error(s) you see – derHugo Mar 02 '21 at 16:03
  • Yea I'm using exactly the one that you linked. However whenever I try to do something along the lines of `ReorderableList listname = `listobject.GetComponent();` and then call `listname.maxItems = num`, I am getting an error thrown at me of `ReorderableList does not contain a definition for 'maxItems' ` – SgtRats Mar 02 '21 at 17:01
  • 1
    Are you sure it is the correct `ReorderableList`? Make sure there is no `using UnityEditorInternal;` on top of your file – derHugo Mar 02 '21 at 17:35
  • Aha, I do. Think now we're getting somewhere. I put it in earlier because otherwise I was getting an error from Unity along the lines of `The type or namespace name "ReorderableList" could not be found`. Is there something that I'm missing when using imported packages? `using ReorderableList` also seems to be an invalid namespace – SgtRats Mar 02 '21 at 18:14
  • Nevermind, I found the correct namespace, it was right there on the source code "UnityEngine.UI.Extensions". Thanks a lot for the help. – SgtRats Mar 02 '21 at 18:16

1 Answers1

1

Note that such a class name already exists namely UnityEditorInternal.ReorderableList.

Make sure on top of your file you have

using UnityEngine.UI.Extensions;

instead of

using UnityEditorInternal;
derHugo
  • 49,310
  • 9
  • 37
  • 73