UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Utility Systems / RandomicListElements System Completed

Utility Systems — UGTK

Randomic List Element System

Summary

The Randomic List Element System is a utility system for managing lists where each element has an associated percentage value. This system ensures that the sum of percentages across all elements in the list always equals 100%, providing a consistent and controlled distribution of values. The system supports functionalities such as adding and removing elements, locking percentages, synchronizing all unlocked percentages, and randomly selecting an element based on its percentage weight using the RandomicList_Extension library.


Content


Modules Dependencies

The Randomic List Element System module requires the following dependencies:

Ensure that Unity's editor scripting is enabled and configured correctly in your project.


Setup

To set up the Randomic List Element System, follow these steps:

Setting Up Percentage Lists

  1. Create or use an existing MonoBehaviour:

  2. In your MonoBehaviour script, define fields of type RandomicList<T> to manage lists of different data types.

  3. Apply the [RandomicList] attribute to these fields to enable custom rendering in the Inspector.

    ```csharp

    public class ExampleUsage : MonoBehaviour

    {

    [RandomicList] public RandomicList<MyStruct> mystructs;
    
    [RandomicList] public RandomicList<GameObject> gameObjects;
    
    [RandomicList] public RandomicList<string> strings;
    

    }

    ```


How To Use

To use the Randomic List Element System, you can interact with the lists directly through the Unity Inspector or programmatically:

  1. Add an Element:

  2. In the Inspector, click the "Add Element" button to add a new item to the list. The system automatically adjusts the percentages of existing elements to accommodate the new item.

  3. Remove an Element:

  4. Click the "Remove" button next to an item in the list to remove it. The percentage previously assigned to the removed item is redistributed among the remaining elements.

  5. Lock/Unlock Percentages:

  6. Toggle the "Lock" checkbox to prevent an element's percentage from being modified. Locked percentages are excluded from automatic adjustments when adding or removing elements.

  7. Sync All Percentages:

  8. Click the "Sync All" button to evenly distribute the percentage among all unlocked elements in the list.

  9. Update Percentages Programmatically:

  10. You can programmatically update the percentage of a specific element using the UpdatePercentage method in your code.

    ```csharp

    mystructs.UpdatePercentage(0, 25f);

    ```

  11. Randomly Select an Element:

  12. Use the RandomicList_Extension.GetRandomElement method to select an element from the list based on their percentage weights.

    ```csharp

    MyStruct randomStruct = RandomicList_Extension.GetRandomElement(mystructs);

    ```


Testing Scene

The scene component is Mn_RandomicListTest, in UtilitySystems/RandomicListElementsSystem/Debug/.

Wire the buttons of the scene to its public methods through their onClick.

What to do, in order:

  1. Fill the table with a few entries, for instance 70 / 25 / 5.

  2. Press Estrai with the default ten thousand draws.

  3. Compare each measured share with its target; press Estrai again to watch the drift shrink.

  4. Change the total so it no longer adds up to 100, and draw again.

Testing a probability table by hand is not testing it: a 5% drop and a 0.5% drop are indistinguishable

over a dozen tries. The component flags any bucket more than two points off its target, and warns when

the total is not 100 — because the draw normalises on the total, so the effective odds stop matching

the numbers written in the inspector.


Technical Info

The following are the main scripts and workflow of the Randomic List Element System. Refer to the script section for detailed structure.

Scripts:


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Depends on 0

  • Standalone: no other module required.

Used by 2

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 0 modules in total.