# MOST Spawn

The ultimate solution for the object generator. You can use it to Spawn Enemies, set game objects' start positions in awake, generate points, create patterns, and a lot more. Also, it comes with a debugging system, so you can set the area or points you want to spawn in. It's easy to set the target area or target point.

## <mark style="color:red;">Import MOST Spawn system</mark>

**1- Create an Empty object in your scene**

**2- Select this object and tap Add Component** &#x20;

**3- Select Most\_Spawn.cs, and now you are ready to go**

<figure><img src="https://1720637334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVjqyL2Am4WC7AkXSTxy%2Fuploads%2FBBiCN1ykFcVtqp9MT1Cc%2FScreenshot%202024-10-22%20at%2011.29.07%E2%80%AFAM.png?alt=media&#x26;token=d1d92def-2df9-4d7f-b60b-fe2a626fcd69" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

* <mark style="color:blue;">**The debugging system uses Gizomos drawer, so make sure it turns on in the scene view**</mark>
* <mark style="color:blue;">**You can change the drawing settings from Most\_Spawn itself**</mark>
* <mark style="color:blue;">**The game object that contains the spawn system will be the center point of the spawn area**</mark>\ <mark style="color:blue;">**(The shaded area is the spawn area)**</mark>
  {% endhint %}

<figure><img src="https://1720637334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVjqyL2Am4WC7AkXSTxy%2Fuploads%2FShqGVTjbRmrNItY8PsVh%2FScreen%20Recording%202024-10-22%20at%2011.34.38%E2%80%AFAM.gif?alt=media&#x26;token=dbaef22f-2963-4ae3-b9da-b77d0aafb55b" alt=""><figcaption><p>The spawn area follows the game object attached to</p></figcaption></figure>

## <mark style="color:red;">Set up the Spawn Area</mark>

<figure><img src="https://1720637334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVjqyL2Am4WC7AkXSTxy%2Fuploads%2FDKUWB5VqiqlM4WvDpJPG%2FScreenshot%202024-10-22%20at%2012.05.49%E2%80%AFPM.png?alt=media&#x26;token=b73595bf-0829-4462-b939-08af03d8c7ab" alt=""><figcaption><p>Spawn Area and position settings</p></figcaption></figure>

<mark style="color:red;">**Spawn shape:**</mark> the spawn area shape is between the inner and outer line.\
Control the scale of this shape using the Inner Scale and Outer Scale.\ <mark style="color:red;">Height</mark> is for 3d shape if you want to build a 3d spawn area.

{% hint style="info" %} <mark style="color:blue;">**Inner and Outer scales for X and Z axis... Height for Y axis.**</mark>
{% endhint %}

<mark style="color:red;">**Ignored positions layers:**</mark> The system checks if the selected point has collided with another object\
If the object is selected by the Ignored position layers, the system will ignore this point and find another\
\
What can you do with <mark style="color:red;">Ignored positions layers</mark>?

* <mark style="color:green;">**Stop the spawn objects from overlapping**</mark>\
  When the spawned object's position collides with the next spawn point, the system will ignore this point and find another to prevent spawned objects from spawning in the same position (or so close to each other)
* <mark style="color:green;">**Prevent Spawning above other objects**</mark>\
  like walls, water, moving objects like characters, and all objects you want to ignore their collision area
* <mark style="color:green;">**Shaping complex spawn areas**</mark>\
  You can use empty objects to draw a complex area and use it to prevent spawning in certain areas inside the spawn area.

<mark style="color:red;">**Snap Position:**</mark>\
Instead of floating point, separate the spawn area into grid points\
Check Enable Snap, and the debugger will draw the new target spawn points

\
Well... It's so easy to modify your shape with the debugger drawer anyway :) You don't have to read all of this

<figure><img src="https://1720637334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVjqyL2Am4WC7AkXSTxy%2Fuploads%2FwjsOURqJCfNfHClsY2XT%2FScreenshot%202024-10-22%20at%2011.12.03%E2%80%AFPM.png?alt=media&#x26;token=4562a667-7ae2-4107-b79a-4e270c6d972e" alt=""><figcaption></figcaption></figure>

## <mark style="color:red;">Spawn cycle and Spawn rate</mark>

<figure><img src="https://1720637334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVjqyL2Am4WC7AkXSTxy%2Fuploads%2Ftl18CTY2k2GwmXDftKBk%2FScreenshot%202024-10-22%20at%2012.45.02%E2%80%AFPM.png?alt=media&#x26;token=0fa62f95-b864-41f6-b6f6-e7a9084b8ee5" alt=""><figcaption><p>Spawn Cycle settings</p></figcaption></figure>

**Let's take a look at Cycle properties**

<mark style="color:red;">**Repeat System:**</mark>**&#x20;spawn cycles controller 1- Loop forever 2- Limited Cycles**

<mark style="color:red;">**Amount System:**</mark>**&#x20;spawned objects flow system**

* <mark style="color:green;">**Divided By Cycle Time:**</mark>**&#x20;means the amount spawned per cycle will be split between the cycle time**
* <mark style="color:green;">**Single Swarm:**</mark>**&#x20;means the amount spawned per cycle will be generated at once at the start of the cycle**&#x20;

<mark style="color:red;">**Spawn Rate Per Cycle:**</mark>**&#x20;the number of objects that will be spawned for each cycle**

<mark style="color:red;">**Cycle Time:**</mark>**&#x20;The cycle time in seconds**

<mark style="color:red;">**Rest Time Between Cycles:**</mark>**&#x20;the cooldown time between cycles (between the end of the current cycle and the start of the new cycle)**

<mark style="color:red;">**Number of Cycles:**</mark>**&#x20;(Only if the Repeat System is Limited Cycles, -1/infinity if loop forever) the number of spawn cycles for this system, and after finishing the spawn system will be terminated (but it can be reworked again "Check API at the end of this page")**

<mark style="color:red;">**First Cycle Delay:**</mark>**&#x20;the delay before activating the spawn system and starting the first cycle (useful at the auto spawn enable and create patterns for multiple spawn systems)**

## <mark style="color:yellow;">Direction of the spawned objects</mark>

<figure><img src="https://1720637334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVjqyL2Am4WC7AkXSTxy%2Fuploads%2F3F4Xf1jWgGnJqMP2DCN8%2FScreenshot%202024-10-23%20at%2012.51.23%E2%80%AFAM.png?alt=media&#x26;token=f1ffa26d-5f91-44b0-b1b9-6709f8b92f11" alt=""><figcaption><p>Spawn object rotation settings</p></figcaption></figure>

The target rotation has four options&#x20;

* <mark style="color:green;">**No Rotation:**</mark> the spawn object rotation will not be affected and will be the same as its prefab
* <mark style="color:green;">**Look At Inside Spawn Area:**</mark> the object will get a random rotation between min and max range starting from the center point of the spawn area
* <mark style="color:green;">**Look At Outside Spawn Area:**</mark> the object will get a random rotation between min and max range starting from the opposite of the center point of the spawn area
* <mark style="color:green;">**No Target Rotation:**</mark> the object will get a random rotation between min and max range

{% hint style="info" %} <mark style="color:blue;">**Note: each range is from -180 to 180, and "Target Rotation" Is just centering the start 0 point.**</mark>
{% endhint %}

<figure><img src="https://1720637334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVjqyL2Am4WC7AkXSTxy%2Fuploads%2F1FDoNBKwa6wHD5iXVweb%2Ftest.png?alt=media&#x26;token=469526ee-c531-4fcc-8469-355e6f996e08" alt=""><figcaption><p>this example shows how "Look At Inside Spawn Area" rotation system works, look outside is the same but reversed</p></figcaption></figure>

## <mark style="color:yellow;">Flow Control</mark>

If the number of objects in the scene reaches the "Max number in the scene," the spawn system will stop spawning until the number of objects gets lower than the maximum value (object destroyed/removed)

> <mark style="color:blue;">**Note: The limit system only counts the active objects (the destroyed/removed objects are not counted)**</mark>

## <mark style="color:yellow;">Event system</mark>

**For each spawning event, you can set your functions and calls**&#x20;

* <mark style="color:green;">**On Cycle Start Event:**</mark>**&#x20;Called at the start of a new cycle.**
* <mark style="color:green;">**On Cycle End Event:**</mark>**&#x20;Called when the current cycle ends.**
* <mark style="color:green;">**On Spawn Called Event:**</mark>**&#x20;Called when the system spawns a new object.**

<figure><img src="https://1720637334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXVjqyL2Am4WC7AkXSTxy%2Fuploads%2Fw0pAPJhHNVAK2G0LT8aa%2FScreenshot%202024-10-23%20at%2012.51.32%E2%80%AFAM.png?alt=media&#x26;token=4ce4c63f-3466-4022-8bff-0f99064ce9f2" alt=""><figcaption><p>Event system for spawning</p></figcaption></figure>

{% hint style="success" %} <mark style="color:yellow;">**Note:**</mark>**&#x20;**<mark style="color:green;">**when the rest time between cycles = zero... "On Cycle End Event" will be called immediately after "On Cycle Start Event".**</mark>

<mark style="color:yellow;">**Another Note:**</mark>**&#x20;**<mark style="color:green;">**"On Spawn Called  Event" will be called once in a single swarm system (multiple objects spawn at the same time).**</mark>

<mark style="color:yellow;">**Another one too**</mark> :smile:<mark style="color:yellow;">**:**</mark>**&#x20;**<mark style="color:green;">**The event system doesn't work with manual spawn calls or manual cycle setter ,and you have to call it manually as well (logically it has to be this way to make it optional), check the API at the end of this page.**</mark>
{% endhint %}

## Examples

**There are unlimited variations of spawn usage. Here are a few examples...**

<figure><img src="https://content.gitbook.com/content/XVjqyL2Am4WC7AkXSTxy/blobs/7W4vL6kbdyDo29WgZLXm/RecordD.gif" alt=""><figcaption><p>in this example: a continuous bull spawns with rotation (look inside with 60/-60 angle range)</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/XVjqyL2Am4WC7AkXSTxy/blobs/xxTHbhWE8ZpljmOO5BJL/RecordA.gif" alt=""><figcaption><p>in this example the spawn system is just one cycle to set game objects random position at the start of the scene</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/XVjqyL2Am4WC7AkXSTxy/blobs/rOoiQ98e4mWFPS50G2hL/RecordB.gif" alt=""><figcaption><p>you can sync multiple spawn systems easily using cycle control for each spawn system to crearte nice patterns, you will find examples in spawn template with explaination</p></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/XVjqyL2Am4WC7AkXSTxy/blobs/5GAHjTrJNrMqKefG4VyX/RecordE.gif" alt=""><figcaption><p>Explosion template showcase: the enemies generator built using Most_Spawn system</p></figcaption></figure>

## <mark style="color:red;">API reference</mark>

{% hint style="success" %} <mark style="color:green;">**All public properties can be updated at runtime, and the changes will be set immediately.**</mark>
{% endhint %}

<pre class="language-csharp"><code class="lang-csharp">// All attributes are set and get, so you can modify or call
// Next to each line shows the return and set data Type 

// Functions
// main behavior enable and disable the controller
<strong>Most_Spawn.EnableState(bool Enable);
</strong>
// Create a custom cycle next to the main spawn system (even if the spawn system is disabled)
Most_Spawn.CreateCustomCycle(int Amount, float DelayBetweenEachSpawn);

// generate a spawn point and return it
Most_Spawn.GeneratePoint(); return Vector3

// generate a spawn rotation in Euler angle and return it
// required the position and return Anigle using the rotation settings from the spawn system
Most_Spawn.GenerateEulerAngle(Vector3 position); return Vector3

// generate a spawn rotation in Quaternion and return it
// required the position and return Quaternion using the rotation settings from the spawn system
Most_Spawn.GenerateQuaternion(Vector3 position); return Quaternion

// return a list of all active spawned objects in the scene
Most_Spawn.GetAllActiveOjectsInScene(); return List&#x3C;GameObject>

// return a list of all active spawned objects from the current Cycle in the scene
Most_Spawn.GetCurrentSpawnedObjects(); return List&#x3C;GameObject>

// return a list of all points generated from the current Cycle
Most_Spawn.GetCurrentSpawnedPoints(); return List&#x3C;Vector3>

// return a list of all rotations generated from the current Cycle
Most_Spawn.GetCurrentSpawnAngles(); return List&#x3C;Vector3>

// return the last active spawned object, if the last spawn is destroyed:
// Send a debug message and return the one before it, and if the list is empty
// send warning message and error message after, you have to check if the spawn list
// is not empty before you call this function
Most_Spawn.GetLastSpawnedObject(); return GameObject

//_______________________________________________________________//
// Attributes ... all are set and get
// Watch attributes guild video
//_______________________________________________________________//

// ReadOnly variable... return bool if the spawn system is active or not
Most_Spawn.Enable; return bool 

// Spawned object settings
Most_Spawn.SpawnObjectList; return or set List&#x3C;GameObject>

Most_Spawn.SelectType; return or set(SelectObjectType.Random or SelectObjectType.Loop)

Most_Spawn.AsChildTo; return or set GameObject

//_______________________________________________________________//
// Spawn Area Settings
Most_Spawn.SpawnShape; return or set (SpawnShapeType.Circle or SpawnShapeType.Cube)

Most_Spawn.InnerScale; return or set float

Most_Spawn.OuterScale; return or set float

Most_Spawn.Hight; return or set float

Most_Spawn.IgnoredPositionsLayers; return or set LayerMask

//_______________________________________________________________//
// Snap Settings
Most_Spawn.EnableSnap; return or set bool

Most_Spawn.GridSize; return or set Vector3

//_______________________________________________________________//
// Core Cycle Settings
Most_Spawn.RepeatSystem; return or set (CyclesType.LoopForever or CyclesType.LimittedCycles)

Most_Spawn.AmountSystem; return or set (SpawnType.SingleSwarm or SpawnType.DividedByCycleTime)

Most_Spawn.SpawnRatePerCycle; return or set float

Most_Spawn.CycleTime; return or set float

Most_Spawn.RestTimeBetweenCycles; return or set float

Most_Spawn.NumberOfCycles; return or set float

Most_Spawn.FirstCycleDelay; return or set float

//_______________________________________________________________//
// Rotation Settings
Most_Spawn.TargetRotation; return or set (RotationSettings.NoRotation 
                           or RotationSettings.LookAtInsideShape 
                           or RotationSettings.LookAtOutSideShape 
                           or RotationSettings.NoTargetPoint_Random)

Most_Spawn.RandomRange_Minimum; return or set float

Most_Spawn.RandomRange_Maximum; return or set float

//_______________________________________________________________//
// Flow Control
Most_Spawn.LimitActiveObjectsInScene; return or set bool

Most_Spawn.MaxNumberInScene; return or set float
</code></pre>
