Randomizer Tags | Perception | 0.5.0-preview.1
docs.unity3d.com
    Show / Hide Table of Contents

    Randomizer Tags

    RandomizerTags are the primary mechanism by which randomizers query for a certain subset of GameObjects to randomize within a simulation.

    More specifically, RandomizerTags are components that can be added to GameObjects to register them with the active scenario's TagManager. This TagManager is aware of all objects with tags in the scene and can be queried to find all GameObjects that contain a specific tag. Below is a simple example of a ColorRandomizer querying for all GameObjects with a ColorRandomizerTag that it will apply a random material base color to:

    [Serializable]
    [AddRandomizerMenu("Perception/Color Randomizer")]
    public class ColorRandomizer : Randomizer
    {
        static readonly int k_BaseColor = Shader.PropertyToID("_BaseColor");
    
        public ColorHsvaParameter colorParameter;
    
        protected override void OnIterationStart()
        {
            var taggedObjects = tagManager.Query<ColorRandomizerTag>();
            foreach (var taggedObject in taggedObjects)
            {
                var renderer = taggedObject.GetComponent<MeshRenderer>();
                renderer.material.SetColor(k_BaseColor, colorParameter.Sample());
            }
        }
    }
    

    RandomizerTags can also be used to customize how randomizers apply their randomizations to a particular GameObject. Visit Phase 2 of the Perception Tutorial to explore an in depth example of implementing a LightRandomizer that does exactly this.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023