Spline Spawner Documentation

Asset pending release

Documentation is a draft, and does not relate to the preview version.

Spline Spawner
Version: 1.0.0
Review

4.1.Custom Modifier #

Creating one is certainly possible. For instance, you may want to modify spawn points based on some level-specific data. Doing so does require a rudimentary understanding of Unity’s Job system.

Please keep in mind that modifiers first and foremost internally developed for this asset, this means updates may incur breaking changes to your own. This example however will be kept up-to-date with current standards.

To get started, create a runtime script following this format:

using System;
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;

namespace sc.splines.spawner.runtime
{
    [Serializable]
    [Modifier("Custom Modifier", "A custom modifier example", new []
    {
        //Optionally, specify distribution modes this modifier is incompatible with. A warning will be shown in the UI if it is in use.
        DistributionSettings.DistributionMode.Grid
    })]
    public class CustomModifier : Modifier
    {
        //Public parameters
        public float sineFrequency = 0.1f;
        public float sineAmplitude = 10f;
        
        [BurstCompile]
        private struct Job : IJobParallelFor
        {
            private readonly float sineFrequency;
            private readonly float sineAmplitude;
            
            [NativeDisableParallelForRestriction]
            private NativeList spawnPoints;

            public Job(CustomModifier settings, ref NativeList spawnPoints)
            {
                this.spawnPoints = spawnPoints;

                //Copy the parameters from the managed modifier, into the unmanaged job
                this.sineFrequency = settings.sineFrequency;
                this.sineAmplitude = settings.sineAmplitude;
            }

            public void Execute(int i)
            {
                SpawnPoint spawnPoint = spawnPoints[i];
                
                //Skip any spawn points that were previously invalidated
                if(spawnPoint.isValid == false) return;
                
                //Current position of spawn point
                float3 position = spawnPoint.position;
                
                //For the sake of this example, the spawn points are moved up in a 2D sine wave
                float3 offset = new float3(0, (math.sin(position.x * sineFrequency) + math.sin(position.z * sineFrequency)) * sineAmplitude, 0f);
                
                spawnPoint.position += offset;
                
                //Reassign the modified spawn point back
                spawnPoints[i] = spawnPoint;
            }
        }
        
        //This is called by the Spline Spawner component upon processing.
        //You may use the 'spawner' object to fetch an attached component to get some sort of custom data or access the Spline Container being used. Etc...
        //For the vast majority of modifiers, this function will remain identical
        public override JobHandle CreateJob(SplineSpawner spawner, ref NativeList spawnPoints)
        {
            Job job = new Job(this, ref spawnPoints);
            
            JobHandle jobHandle = job.Schedule(spawnPoints.Length, DEFAULT_BATCHSIZE);

            return jobHandle;
        }
    }
}

After which, the custom modifier will appear as an option to add!

In order to draw the modifier’s parameters, a custom PropertyDrawer needs to be created. Create this script in any folder called Editor

using sc.splines.spawner.runtime;
using UnityEditor;
using UnityEngine;

namespace sc.splines.spawner.editor
{
    [CustomPropertyDrawer(typeof(CustomModifier))]
    public class CustomModifierPropertyDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            
            ModifierAttribute attributes = ModifierAttribute.GetFor(property);
            EditorGUILayout.LabelField(new GUIContent(attributes.displayName, attributes.description), EditorStyles.boldLabel);

            EditorGUILayout.PropertyField(property.FindPropertyRelative("sineFrequency"));
            EditorGUILayout.PropertyField(property.FindPropertyRelative("sineAmplitude"));

            EditorGUI.EndProperty();
        }
    }
}

When the modifier is selected, the two fields are now drawn and editable

Modifiers rely on the [SerializedReference] attribute, this means that changing the name of parameters causes their saved values to be lost. If you want to change the class name at any point, you must add this attribute to the modifier class [MovedFrom(true, "sc.splines.spawner.runtime", sourceClassName: "OldName")]

Yes No Suggest edit
Last updated on July 22, 2025
0 of 0 users found this section helpful
If you're familiar with this asset, please consider leaving a review!
Your support is what makes complementary updates possible!
Suggest Edit