Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Random Material#

Random / Random Material

  • Can Read

  • Cannot Write

Description#

Picks a random Material from the list

Parameters#

Name Description
Materials The list of assets one of them is picked from

Code#

using System;
using System.Collections.Generic;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Random Material")]
    [Category("Random/Material")]

    [Description("Picks a random Material from the list")]
    [Image(typeof(IconMaterial), ColorTheme.Type.Blue, typeof(BadgeDice))]

    [Parameter("Materials", "The list of assets one of them is picked from")]

    [Keywords("Dice", "Constant", "Random", "List", "Array", "Any", "Choose")]

    [Serializable]
    public class TypeMaterialRandom : TypeMaterial
    {
        [SerializeField] private List<Material> m_Materials = new List<Material>();

        public override Material GetPreview(GameObject source) => this.Pick();

        public override Material Get(Args args) => this.Pick();

        private Material Pick()
        {
            int count = this.m_Materials.Count;
            return count > 0 ? this.m_Materials[UnityEngine.Random.Range(0, count)] : null;
        }

        public override string ToString()
        {
            return $"Random Material ({this.m_Materials.Count})";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnEditorChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.