Placeable Markers
In this section, we'll spawn items like NPCs, power ups etc in our dungeon.
For this, we'll do the following:
Use the
Spawn Item
node in the flow graph. This will add items in the layout graphCreate
Placeable Marker
assets and drop a few of them in the snap modules so that the builder can spawn them at those places when necessaryUse the Theme engine to spawn the actual prefabs at those marker locations
Spawn Items in Flow Graph
Open up our flow graph editor and reassign the Module database in the Editor Settings, as we've done previously
![Ut 09 48 Ut 09 48](dungeon-architect-docs/ut-09-48.png)
Create a new
Spawn Items
node and link it up as shown below:
![Ut 10 01 Ut 10 01](dungeon-architect-docs/ut-10-01.png)
![Ut 10 02 Ut 10 02](dungeon-architect-docs/ut-10-02.png)
Select the
Spawn Items
node and inspect the properties.
![Ut 10 03 Ut 10 03](dungeon-architect-docs/ut-10-03.png)
We want to spawn enemies in the
main
path (green) and thealt
path (orange).Add two entries to the
Paths
array and set the values tomain
andalt
Set the
Item Type
toEnemy
Set the marker name to
Grunt
. Later in the theme file, we'll create a marker node namedGrunt
and place our NPC prefabs under it
![Ut 10 04 Ut 10 04](dungeon-architect-docs/ut-10-04.png)
Rebuild the flow graph
![Ut 10 05 Ut 10 05](dungeon-architect-docs/ut-10-05.png)
The nodes now in the green path (main)
and orange path (alt)
have red enemy items
Add a description to this node
Placeable Markers
A placeable marker is an prefab you create, which you can then drag and drop anywhere on your modules. You can then use the theme file to spawn objects at that location.
A placeable marker prefab can contain more than one marker name. For example, a placeable marker prefab named PM_Enemies
may contain a list of marker names like (Grunt
, FireTroll
, IceTroll
, Goblin
). In your snap module, you'd place these markers in appropriate locations (say 10 different locations within the room module).
If the dungeon builder needs to spawn a Grunt
marker 4 times inside the room, it will first find all the existing and compatible marker assets placed in the room. In this case PM_Enemies
would be compatible since it contains a Grunt
marker. Since we have 10 of these in the room module, it will randomly pick 4 from them and use the theme file to spawn the grunt prefab
Create Prefab
Move to an appropriate folder and create a Placeable Marker prefab from the create menu
Rename it to
PM_Enemies
Select the
PM_Enemies
prefab and inspect the properties. Add aGrunt
marker (since we specified this earlier in theSpawn Items
node). Add a few more markers for future use likeIceTroll
,FireTroll
,Goblin
Add to Snap Modules
Open up the previously created room module
![Ut 10 11 Ut 10 11](dungeon-architect-docs/ut-10-11.png)
![Ut 10 12 Ut 10 12](dungeon-architect-docs/ut-10-12.png)
![Ut 10 13 Ut 10 13](dungeon-architect-docs/ut-10-13.jpg)
We went ahead and added a bit of geometry int he room
![Ut 10 18 Ut 10 18](dungeon-architect-docs/ut-10-18.jpg)
The snap system gives complete freedom to the artist to design the room as they see fit. In that same spirit, the artist should also have control on where the markers spawn. This is where placeable markers come in
Drag drop the placeable marker prefab that you've created before, on to the scene
![Ut 10 14 Ut 10 14](dungeon-architect-docs/ut-10-14.jpg)
This will spawn a placeable marker game object on the scene. When selected, it shows the descripton (Debug Text
) of the placeable marker.
![Ut 10 15 Ut 10 15](dungeon-architect-docs/ut-10-15.png)
Rotate the actor as needed. The red arrow shows the orientation of the marker. When the theme engine spawns an actor here, it will do so with this rotation
![Ut 10 16 Ut 10 16](dungeon-architect-docs/ut-10-16.png)
Add a few more markers. Add at least 4 markers, since we are adding a maximum of 4 enemy items per node in the flow graph using Spawn Item
, but adding more is always better
![Ut 10 17 Ut 10 17](dungeon-architect-docs/ut-10-17.jpg)
We'll add a few more on top of the ramp
![Ut 10 19 Ut 10 19](dungeon-architect-docs/ut-10-19.jpg)
![Ut 10 20 Ut 10 20](dungeon-architect-docs/ut-10-20.jpg)
Do this for all the modules you've created so far that would need this marker in it
Open up the Lift module and add a few more placeable markers there
![Ut 10 21 Ut 10 21](dungeon-architect-docs/ut-10-21.png)
![Ut 10 22 Ut 10 22](dungeon-architect-docs/ut-10-22.png)
![Ut 10 23 Ut 10 23](dungeon-architect-docs/ut-10-23.jpg)
![Ut 10 24 Ut 10 24](dungeon-architect-docs/ut-10-24.jpg)
Open up the 2x1x1
and 2x2x2
Room modules and add the markers there as well
![Ut 10 39 Ut 10 39](dungeon-architect-docs/ut-10-39.png)
![Ut 10 40 Ut 10 40](dungeon-architect-docs/ut-10-40.png)
Rebuild Module Database Cache
If you add / remove a placeable marker from a snap module, you'll need to rebuild the module database cache
Select the Module database asset that we created in the previous section and in the inspector, click Build Module Cache
button. Save the module database asset
![Ut 10 25 Ut 10 25](dungeon-architect-docs/ut-10-25.png)
![Ut 10 26 Ut 10 26](dungeon-architect-docs/ut-10-26.png)
Update Theme File
We'll use a theme file to actually spawn our enemy prefab.
Open Theme Editor
Open up the existing theme file we created in the previous section.
![Ut 10 27 Ut 10 27](dungeon-architect-docs/ut-10-27.png)
Double click on the theme asset to open the theme editor
![Ut 10 28 Ut 10 28](dungeon-architect-docs/ut-10-28.png)
Box select all the marker nodes and delete them
![Ut 10 29 Ut 10 29](dungeon-architect-docs/ut-10-29.png)
![Ut 10 30 Ut 10 30](dungeon-architect-docs/ut-10-30.png)
Create Marker
In the previous section, we assign the marker name of Grunt
in the Spawn Items
node. In the theme file, we'll create a new marker node and name it Grunt
Right click on the graph and choose Add Marker Node
![Ut 10 31 Ut 10 31](dungeon-architect-docs/ut-10-31.png)
Select the marker node and from the inspector, change the Marker name to Grunt
![Ut 10 32 Ut 10 32](dungeon-architect-docs/ut-10-32.png)
![Ut 10 33 Ut 10 33](dungeon-architect-docs/ut-10-33.png)
![Ut 10 34 Ut 10 34](dungeon-architect-docs/ut-10-34.png)
Add Enemy prefab
Add your NPC character prefab here. For this tutorial, we'll add a cube and adjust the size and scale
Navigate to Assets > CodeRespawn > DungeonArchitect_Samples > Demo_Theme_SimpleShapes > Prefabs
and drop in Cube_Red
and connect it the Grunt
marker node to it
![Ut 10 35 Ut 10 35](dungeon-architect-docs/ut-10-35.png)
Select the cube node that you just dropped and adjust the scale and position
![Ut 10 36 Ut 10 36](dungeon-architect-docs/ut-10-36.png)
Save and close the Theme Editor
Build Dungeon
Open the map where we previously configured our dungeon and build it.
You'll see that enemies start to spawn at the locations where you've placed the markers
![Ut 10 37 Ut 10 37](dungeon-architect-docs/ut-10-37.jpg)
![Ut 10 38 Ut 10 38](dungeon-architect-docs/ut-10-38.jpg)
You can use this system to spawn anything (treasure chests, weapon racks, power ups or any gameplay prefab)