Problem Statement
Ecosystems are a great way to create interesting games, but how would you go about making them and what is required for it to be fun to play with. There are games where Ecosystems get implemented well and they become popular for it. but there are also some that don’t. and some games don’t introduce them while it could totally spice up their world that’s where this research starts from.Aswell as wanting to make one of my own in the way of a sandbox simulation game.
This is also Heavily inspired by the Video By Sebastian Lague[1]where he Simulates an Ecosystem
[[2]](#2)Research question
How can you implement an ecosystem to make playing with virtual creatures in a sandbox simulation fun?
here we get a few questions like: What defines an Ecosystem? What is a Sandbox Simultation? What other Games implement an interactable ecosystem? What makes interactions fun? What counts as interacting with creatures? What do i hope to achieve with this Ecosystem?
What Defines an ecosystem
What is an ecosystem, what makes it an ecosystem, that’s the first thing that should be looked at when trying to simulate one.
At a baseline an ecosystem is a group of entities interacting with eachother in a cycle. but what defines this cycle of interaction. What do these creatures need to continue living.
When it comes to creatures in an enviroment, they would need something to start living in a cycle.
At first creatures need a goal to exist to survive, for this you could give them food or water or something that rewards them for existing, but is also mandatory for the creatures survival.[23]
The needs require consequences to create a cycle, so they should have to die or fail their goals in order for them to strive for improvement or atleast try their best to survive.
For a true cycle, creatures must have a way to reproduce. This might depend on available resources, environmental conditions, or successful pairings. Reproduction adds a layer of strategy and complexity, as creatures that thrive in their environment will pass on traits that help sustain or change the ecosystem over time.
but within an ecosystem it isn’t just the creatures that are apart of it, enviroment also has an effect upon ecosystems as things like water, soil, the overall climate or sunlight might also affect the creatures or plants living within the ecosystem.
Within an ecosystem there are a couple of different roles asigned to the entities living within their cycle, you have things like producers which are usually plants which produce energy for themselves or other entities around them which are usually then Herbivores which eat the plants in order to survive and get trough their energy cycle and to halt those from over production we have carnivores who thering eat the herbivores.
Added to this it’s also possible to nutrients within these cycles, this means that you can have dead creatures increase the soil around them which can help plants strife within their enviroment. or seasons can also change the dynamics within an ecosystem and how it balances around their behaviors.
for the use of these within the game it’s important to also take player interaction in mind, which should be further emphasized within the chapter interaction with creatures.
What is a sandbox simulation?
what a sandbox simulation it uses to different words sandbox and simulation, let’s look at each of them in depth and take the most important information about these pieces of the genre.
Sandbox
first let’s look at the sandbox genre A sandbox videogame is one that allows the player to have a high degree of freedom to explore and interact with the game world in a nonlinear fashion. To explain this further it’s a game where the player doesn’t have a direct goal and is free to explore and interact with their enviroment.
The name itself is derived of off the playground activity, the literal sandbox where you play around in a box full of sand where you are free to play around with the enviroment around you.
The game therefore should allow the player to reach the goal (if there is one) in multiple different ways.[12]
popular games that define the path of sandbox games are
Elite
it’s considered one of the sandbox games, the player is space pilot that explores a randomly generated galaxy engaging in combat and trading resources at various planets to improve the players ship. this lead to games like, The Secen Cities of Gold,Sid Meier’s Pirates!, Star Control and Freelancer
SimCity
This created a free genre within the city building game, where the player is free to create a city to their liking, but with the added challenge of keeping up financially. Simcity lead to other similair games like, Rialroad tycoon, SimIsle and Capitalism.
The Sims
it’s a life simulation game where the player interacts with simulated humans going about their daily household actions. the success of the sims led to further predecesors would arise like Spore.
Grand theft Auto III
grand theft auto is a action advneture where the player is a crook in a large city, this was the first game in the series of grand theft auto to have an open world in 3d space, this was also the first game with a detailed physics engine that the player was free to interact with and play with. this games succes lead to a big rise of open world action adventure games like Saints row, the Assassin’s creed series and the Far cry series.
Minecraft
One of the most known sandbox games is minecraft, a game where you can make whatever you want, you’re free to explore the world however you want. The game at first didn’t have an end goal or a “win condition” it had a loss condition as you could die due to survival circumstances but the end goal was all up to your own imagination. this game had little to no limitation opened up the genre even more.
Metal gear, Hitman and Mount & blade
These games grouped together are games that implement the sandbox genre in the way of implementing procedural Quests that are generated trough play.
Simulation
Simulation as a genre is recreating real world scenario’s or systems in a virtual enviroment. a simulation games main goal is to copy activities based on real life in the form of a game. the direct use for these game can differ from analysis and training to general entertainment. [10]
This genre generated multiple subgenres depending on the type of simulation so you have,
Construction and management simulation
which follows the type of simulation where players could build and expand upon ficitonal communities.
Life simulation
which follows the simulation of life or more accurately artificial life where the player controls artificial life forms.
Sports
this is games that simulate the act of doing a specific sports like soccer or tennis.
The Sumerian Game released in 1964 was the first simulation game which was based on the ancient Sumerian city state of Lagash.
Later arcade games started implementing the simulation genre in a way of motion simulation which was started with the game Space Tactics.
After these started expanding the Sports genre that started with games with “Simulator” in their name would emerge.
Then came the introduction of city building simulations with the rise of SimCity, but before there were games like Fortune Builder but Simcity was the game that gave rise to the now popular City building simulation Genre.
What other Games implement an interactable ecosystem?
some games have ecosystems, but most of them are either predetermined or aren’t interactable, that’s to specify ones that are actually Interactable. Some of the games I’ve found that implement this type of system are:
- Spore [13]
- No Man’s sky[20]
- Nicche: A Genetics Survival Game[14]
- Eco[22]
- Species: Artificial Life, Real Evolution[15]
- The Universim[16]
- Rain World[17]
- Subnautica[19]
- The isle[21]
Some of these games i’ve tried myself or analyzed their gameplay, while others I can give a small synopsis off
Spore
The first game that I personally think of when I think of an interactable Ecosystem is Spore, in this game you get to create your own creature and go trough different stages of life to eventually go to space and conquer the universe.
The main part where you interact interact with the ecosystem the most directly, is the life stage. This is where you get to control the creature walking in the enviroment, the stage before it is the cell stage which also has some effect on the ecosystem but overall your choices don’t impact the overall growth of the enviroment and it’s more a focus on staying alive and eating enough to get onto the next stage.
In the life stage, your focus is similair to the cell stage before it, but with the difference of attacking nests of a certain species which could cause them to go extinct. there is also a chance of running into abandoned nests, which could’ve been existing species that no longer exist or your own that has migrated.
The stage after life is the tribal stage where you lose the direct control over your creature and are instead playing a colony sim type game. here you can still slightly influence the ecosystem as you can collect and kill other creatures that are still doing the life stage or completely destroy other tribes, but this is less direct and has a much smaller impact on the way you play and interact with the ecosystem than the earlier ones.
after that is the Civilization stage which strays even further from the direct control where you are truly playing a civilization sim, instead of controlling creatures on the map you are now controlling their vehicles to create new settlements and start wars and alliances. This is the last stage you spend on your own planet, and your opponents consists of other variants of your own species.
once you’ve conquered the planet in the Civilization stage you enter the space stage this is where you have the entire universe to yourself, here you are free to do whatever you please. you can still technically interact with ecosystems but aren’t affected by it you can go around exploring different planets and civilizations and watch over the stages you went to before from a different perspective. this stage is a full sandbox experience where the player is the freest in their choice.
No mans Sky
No mans sky is most commonly known for their planetary exploration, but it also uses a differse set of ecosystems on these planets.
No man’s sky’s ecosystems are devided in different biomes. Lush, barren, dead, exotic, mega exotic, scorched, frozen, toxic, irradiated, marsh and volcanic
Lush planets are the planets with the most abundent animal life, colorful plant life and mild oxygen atmospheres. these planets are the ones that feel the most like earth. have the most diverse ecosystem of creatures. these types of planets are one of the more safe planets in terms of hazards with only an occasional storm here and there.
Barren planets are like the opposite of lush ones, featuring almost no plant live, though there can be live found, it’s life that’s lived trough the roughest of enviroments. this enviroment is similair to that of desserts in our world.
Dead is a step even further from barren which features no life anymore, it has access to resources and is quite peacefull in terms of hazards, but has no ecosystem to speak of.
Exotic and mega exotic feature very rare and unique type of ecosystems, these are the most out there and special.
Scorched planets are planets known for their heat, this is also seen in their plants and creatures, the life on these planets have adapted to the heat and therefore created unique interactions within the planet, it’s a difficult place for players to explore due to the heat.
Frozen is the opposite of scorched these are cold planets, and have therefore creatures that are resistant and made for the cold, plants are scarce and therefore creating a difficult life for the creatures living there. and making it also difficult for the player.
Toxic planets are planets with noxious gasses and accidic seas, creatures here are adapted to those kind of enviroment and plants tend to be mutated due to these harshly toxic enviroments. this is extra difficult for players if they don’t have the proper protection.
Radioactive or Irradiated planets are planets with high level of raddiation which is affected differently from toxicity. creatures and plants are usually mutated as the cause of this radiactivity.
Marsh’s are wet and humid, the ecosystem also reflects this with featuring more plants that thrive on wet enviroments. the creatures are often more reptilian and amphibian do to these enviroments.
Volcanic planets are planets with a more extreme version of heat compared to scorched planets, these also have alot of volcanic activity. the plants here are sparse, but the Creatures are more likely to have adapted to the heat in special ways, like some could resemble armored insects.
Images from article thegamer.com by Sean Murray
Eco
Eco is a multiplayer game where players work together to build a civilization within a fully simulated system. this game features a multitude of consequences and hazards like pollution and resource depletion this is directly linked to the plant live within the game and can have massive downsides for the overall progression within the game.
The players get constant feedback upon their action and the game is highly interactive with visual feedback upon player actions.
Nicche: A Genetics Survival Game
it’s a turn based survival game with some unique roguelike and simulation elements, shape your species and keep them alive troughout the hazards brought about the game. Evolve fight against predators and Disease.
Species: Artificial Life, Real Evolution
a game where you play around with evolution, the game revolves around evolving creatures in their given enviroment and gives you the option to tinker with their options and what’s natural selection happen.
The Universim
A god game where youguide a civilization trough survival while also keeping up with the enviroments needs. the player controls the ecosystem, depending on the players choices the ecosystem could evolve in good or bad ways.
Rain world
A survival platformer game within a broken ecosystem, you are both a predator and prey. The ecosystem is balanced around a complex series of AI that the player has navigate trough to survive. Every animal behaves differently and you have to figure out who is friend or foe.
Subnautica
An underwater survival game where you have to survive within the existing underwater ecosystem, the player must navigate trough this ecosystem in order to stay alive and progress.
The Isle
A more dinosaur focused survival game, in this game you take the shape of a dinosaur from their age and have to survive based on their specific needs and conflicts.
What is fun?
When is it fun, at what moment is the game fun, it depends depending on the goal of the game/ system or project whatever you’re trying to make fun. I’d say it’s fun when you’re feeling happy playing it and want to continue to keep playing it in a game situation, but what do others say about it.
The concept of fun can be seen in different way depending on the context and different ways of looking at them. fun is very vital to the well being of a person. Fun often provides a break from obligations and this leads to a “Liberating engagement”[8] where people will feel carefree and in the moment. the way of achieving this state doesn’t have a direct source as it depends entirely on the person, but these moments create moments of happiness within a person’s life and mental.[7]
Psychologist also categorize fun in different categories as in “Type I” which is immediate fun, this is what’s the fun you gain from playing video games or watching a movie you like. “Type II”[9] fun is more related to challenging activities these are activities which could also be seen in video games but is more about accomplishing a difficult challenge, this will in turn create long term happiness but also help build resilience and foster personal growth.
For video games Fun comes from a couple of factors including those concepts from the above stated psycholical reasonings, challenge as before mentioned with the Type II fun is important but also player freedom and immersion are just as important.
it’s important to find balance within the difficulty of your game, if it’s too difficult it could end up being too frustrating for the player to continue, while making it too easy can bore the player and not give the player the satisfaction of accomplishment.[11]
objectives are also important, giving the player a goal to strive for gives them a reason to keep being engaged with the game, which also adds with immersion within the game the more the player feels and relates the game the more the player could tend to get lost in the game, which helps with the escapism and fun from games.
constraining but also giving options to the player helps out in creating fun for the player, constraints make it so player can grow while playing the game, while giving options to player allows them to make their own fun.
This is what also allows Sandbox games which is what this game is falling under, sandbox’s fun comes from their design of player freedom, creativity and exploration.
Like the open ended gameplay that sandbox games are designed around gives the player the option to create their own goals to create their own fun, say in a sandbox game like Minecraft you have the option to go out explore and find out new things, or just stay in spawn and create the most beautiful tower you want. the options are endless and the ways these games create Fun is therefore endless.
Creativity also helps in that, you can make up your own stories which also helps for the developer or designer to take less time in the direct immersion, but if there are not immersive handles for players to use their creativity they cannot create the amount of fun they might want out of their game experience.
Exploration is also a key point that makes Sandbox simulation games fun. discovering what’s out there, if it’s things in the enviroment but also things to do and play around with. That thrill that extra feeling of emotion from discovering something can entice a player to keep exploring, keep playing and most important of all have fun.
Dynamic enviroments is an even interesting point to keep in mind, players actions leading to direct consequences, it adds depth to their gameplay. “if there are no consequences to your actions what’s the point of doing them in the first place” is the importance of dynamic enviroments that help create the fun in the sandbox genre or in other games in general.
Multiplayer or social interaction is a point that’s also used for fun in certain Sandbox games, having people work together or engage with eachoter, breeds that extra bit of fun, it gives way of making another way of enjoying the game which you otherwise might overlook if you didn’t have your friends to engage in these paths.
What counts as interacting with creatures?
Interacting with these creatures is being able to change information or behavior of these creatures. it’s for you to be able to physically influence the creatures. May it be giving more food to one creature to keep that one alive, or making them all live of scraps, it’s changing and engaging with the creatures that counts as interacting with creatures.
but that’s not the only interacting that will be apart of this game, the other aspect that is not influenced by the player but more on the games systems, is interacting with the enviroment. Which is doing things like finding food and eating it if it is suitable or breeding with eachother.
Let’s put these methods of interaction in a list of what could be and which could be available and which ones are crucial to the gameplay in the case of simulating an Ecosystem with virtual creatures.
Movement
This is the actions of like moving towards or away from each other or targets, say predators chasing after prey or prey running away from predators. but this can alos moving towards eachother to mate, or looking for a spot of shelter. This is Crucial to be implemented when engaging in simulating an virtual Ecosystem
Combat
combat or the case of attacking is an option of interaction of the creatures, it could be offensive or defensive in nature, engaging creatures trough damaging eachother or the player attacking the creatures is a way of interacting with creatures.
Mating
The act of mating is an interacting that’s quite crucial to a full and balanced ecosystem, this is also a form of interaction with creatures they do it themselves or it could also be possible to make the player force upon the mating qualities depending on the game context.
Resource gathering
This one isn’t directly crucial to delivering an virtual ecosystem though it is also a way of interacting with creatures or more accurately it’s the creatures interacting with the enviroment given to them. it’s the act of gathering food or materials, like foraging or hunting. Which are common behaviors for creatures within our own ecosystem.
Social behavior
Flocking,herding, forming packs for protection or otherwise. That sort of thing is also another way of interaction between creatures. this is given behavior depending on their enviroments and needs and can be created artificially or naturally.
Terrotorial behavior
This is another interaction that creatures could engage whith, which could also directly cause certain other behavior like the social behavior but social behavior could also have been the cause of terrotorial behavior.
Enviromental Interaction
different from direct resource gathering, this is more reactive as to responding to changes within their living enviroment, which is vital if you want an responsive ecosystem. this could include things like seeking shelter due to the weather or avoiding hazardous enviroments.
Communication
A more perceptible way of interaction, it’s creatures using sounds or movements to convey information, like wanting to mate or finding food.
Status effects
things like buffs and debuffs is a way to interact with creatures, like certain creatures moving faster depending on their enviroment or certain creatures affecting others with “poisons” that debuff their opponent.
How do you implement one?
We’ve looked into the different systems and how they work and what is expected of the player so how do we implement it.
Here I give detailed explanation of the code that is used to implement the ecosystem within my sandbox simulation.
Creatures
I use simple spheres for the “Creatures” and make them look for eachother using collider sphers
the creatures are controlled using their own controller with some movement functions but also using a class for the creature and a settings scriptable object to easily update the variables I’ve added predator on prey interaction to create some interesting diversity from the begining and to differentiate creatures early on. which is what the HuntType enum Represents.
public class Creature
{
public float size;
public float speed;
public float VisionRadius;
public HuntType huntType;
public Creature(CreatureSettings settings)
{
this.size = settings.Size;
this.speed = settings.Speed;
this.VisionRadius = settings.VisionRadius;
this.huntType = settings.huntType;
}
}
public enum HuntType
{
Predator, Prey
}
[CreateAssetMenu]
public class CreatureSettings : ScriptableObject
{
public float Size;
public float Speed;
public float VisionRadius;
public HuntType huntType;
}
private void Start()
{
rb = GetComponent<Rigidbody>();
creature = InitiateCreature(settings);
}
public Creature InitiateCreature(CreatureSettings settings)
{
return new Creature(settings);
}
I made a simple function for the creatures to move towards a target using their rigidbody which will be called but their vision cones when they detect others
public void MoveTowards(Vector3 target)
{
rb.MovePosition(Vector3.MoveTowards(transform.position, target, creature.speed * Time.deltaTime));
}
I also made moveaway as an opposite to move towards to create runaway mechanics, which is currently use for predator prey interaction
public void MoveAway(Vector3 target)
{
Vector3 directionAway = (target - transform.position).normalized;
Vector3 newPosition = transform.position - directionAway * creature.speed * Time.deltaTime;
rb.MovePosition(newPosition);
}
this bit will be on their vision circle to get them to move towards or away from eachother.
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Creature")
{
var OpposingCreatureController = other.gameObject.GetComponent<CreatureController>();
if (OpposingCreatureController != null)
{
Creature Opposingcreature = OpposingCreatureController.creature;
bool isSameHuntType = Opposingcreature.huntType == currentCreature.huntType;
bool isHunteronPrey = currentCreature.huntType == HuntType.Predator && Opposingcreature.huntType == HuntType.Prey;
bool isPreyOnHunter = currentCreature.huntType == HuntType.Prey && Opposingcreature.huntType == HuntType.Predator;
if (isSameHuntType && !personalController.hasProcreated && !OpposingCreatureController.hasProcreated)
{
personalController.MoveTowards(OpposingCreatureController.transform.position);
personalController.hasTarget = true;
}
if (isHunteronPrey)
{
personalController.MoveTowards(OpposingCreatureController.transform.position);
personalController.hasTarget = true;
}
if (isPreyOnHunter)
{
personalController.MoveAway(OpposingCreatureController.transform.position);
personalController.hasTarget = true;
}
}
}
}
to make the creatures move around somewhat interestingly they i make them walk around randomly for this the creature also gets the walkrange variable
public float WalkRange;
Vector3 PickRandomDirection()
{
float x = UnityEngine.Random.Range(-creature.WalkRange, creature.WalkRange);
float z = UnityEngine.Random.Range(-creature.WalkRange, creature.WalkRange);
Vector3 newDest = new Vector3(transform.position.x + x, transform.position.y, transform.position.z + z);
if (Physics.Raycast(newDest, Vector3.down, groundLayer))
{
hasRandomTarget = true;
}
return newDest;
}
which gets called when they don’t have a target
private void Update()
{
if (!hasTarget)
{
if (!hasRandomTarget) randomDestination = PickRandomDirection();
if (hasRandomTarget) MoveTowards(randomDestination);
if (hasRandomTarget && Vector3.Distance(transform.position, randomDestination) < 1) hasRandomTarget = false;
}
}
when the creatures collide with eachother they will do different interactions based on their settings like procreate to create a new creature which will be updated using some information from the other creatures or being destroyed when it’s a predator on prey interaction.
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Creature")
{
var OpposingCreatureController = other.gameObject.GetComponent<CreatureController>();
if (OpposingCreatureController != null)
{
Creature Opposingcreature = OpposingCreatureController.creature;
bool isSameHuntType = Opposingcreature.huntType == creature.huntType;
bool isHunteronPrey = creature.huntType == HuntType.Predator && Opposingcreature.huntType == HuntType.Prey;
if (isSameHuntType)
{
if (hasProcreated || !OpposingCreatureController.hasProcreated)
{
hasTarget = false;
}
if (!hasProcreated && !OpposingCreatureController.hasProcreated)
{
hasProcreated = true;
hasTarget = false;
OpposingCreatureController.hasProcreated = true;
Procreate(OpposingCreatureController.creature, creature, OpposingCreatureController, this);
}
}
if (isHunteronPrey)
{
Destroy(other.gameObject);
hasTarget = false;
}
}
}
}
when the creatures procreate they currently take the information of both creatures and increase their size to show interaction it’s also moved a little to the side the plan is for this to start changing other stats based on the information from the parents
public void Procreate(Creature father, Creature mother, CreatureController fatherController, CreatureController motherController)
{
GameObject child = Instantiate(this.gameObject, gameObject.transform.position + new Vector3(1, 1, 1), gameObject.transform.rotation);
CreatureController childController = child.GetComponent<CreatureController>();
childController.InitiateCreature(childController.settings);
Creature childCreature = child.GetComponent<CreatureController>().creature;
childController.hasProcreated = false;
childController.hasTarget = false;
childCreature.size = father.size + mother.size;
}
They interact alright but it’s not anything like a lifecycle yet. first off the creatures will stay alive forever unless they’re prey.
[Video of Predator eating prey](https://www.youtube.com/watch?v=wRHUX88pLGQ)secondly the creatures have no reason to really procreate or keep going what is their purpose in the world, so let’s add food for the creatures.`
public class Food : MonoBehaviour
{
public float HungerValue;
}
the food class which will just to differentiate and add more functionality later then let’s give the creatures a diet (to keep the prey, predator interaction unique) and make the food used for the pray aswell as adding hunger
public Diet diet;
public float Hunger;
public float maxHunger;
public Creature(CreatureSettings settings)
{
this.diet = settings.diet;
this.maxHunger = settings.maxHunger;
Hunger = maxHunger;
}
now let’s make them see food around and increase it while also adding it to the original predator interaction but for the creatures we’ll use the size of the creature for now for the food value.
private void OnTriggerStay(Collider other)
{
if(other.gameObject.tag == "Plant" && personalController.creature.diet == Diet.Herbivore)
{
personalController.MoveTowards(other.transform.position);
personalController.hasTarget = true;
}
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Plant" && creature.diet == Diet.Herbivore || creature.diet == Diet.Omnivore)
{
creature.Hunger += other.gameObject.GetComponent<Food>().HungerValue;
Destroy(other.gameObject);
}
if (isHunteronPrey)
{
Destroy(other.gameObject);
creature.Hunger += Opposingcreature.size;
hasTarget = false;
}
}
this is nice and all but why should they look for it, let’s add a way for them to die by decaying their hunger over time.
[SerializeField] private float HungerDecay;
private void Update()
{
if (creature.Hunger > 0)
{
creature.Hunger -= HungerDecay;
}
if(creature.Hunger > creature.maxHunger)
{
creature.Hunger = creature.maxHunger;
}
if (creature.Hunger <= 0)
{
isDying = true;
creature.Hunger = 0;
dyingTimer = 3;
}
if (isDying)
{
dyingTimer -= 0.1f * Time.time;
}
if (isDying && dyingTimer <= 0)
{
Die();
}
}
die is just destroy but as a function to add more functionality later
public void Die()
{
Destroy(this.gameObject);
}
which is also called now on the predator prey interaction
if (isHunteronPrey)
{
OpposingCreatureController.Die();
}
now they’ll die over time if they die if they don’t find food.
[video of the going after food](https://www.youtube.com/watch?v=y6urNryrkZQ)Procedural Terrain genration
For the creatures to live in different enviroments I also wanted to do some research into terrain generation. For this i used the tutorial made by Sebastian Lague.
Which uses perlin noise to create a heightmap that then gets used to create a map. This one also has chunk loading which I use to make an endless map for the player.
In addition I can use this terrain to also Generate the creatures and plants within it using for example poisson disc sampling within the generated terrain.5
Player interaction with creatures
we now have the creatures, but this is a sandbox simulation and we want players to interact with the creatures. the player will just be flying around using unity’s input system. which I do with a character controller and updating the Rigidbody velocity. to get it to where you don’t have to check the unity inspector so that the functions we want to use can be used in builds like adding creatures and seeing their settings we have to add UI for the player to add the stuff we need.
Displaying of the stats
to show the information of the creatures we use a canvas that will be ontop of the creature that we can see by clicking onto the creature
public class StatDisplay : MonoBehaviour
{
public Canvas canvas;
public Creature creature;
public bool isVisible;
[Header("Text Boxes")]
public TextMeshProUGUI Speed;
public void EnableCanvas()
{
canvas.enabled = true;
isVisible = true;
SetupStats();
}
private void Update()
{
Hunger.text = "Hunger: " + creature.Hunger.ToString();
}
private void LateUpdate()
{
canvas.transform.LookAt(transform.position + Camera.main.transform.rotation * Vector3.forward, Camera.main.transform.rotation * Vector3.up);
}
public void SetupStats()
{
Speed.text = "Speed: " + creature.speed.ToString();
}
public void DisableCanvas()
{
canvas.enabled = false;
isVisible = false;
}
}
Note: I’ve reduced the amount of text box variables to make it simpler to read but they all follow the same method with hunger being the only one constantly updated
this display will be called trough the creature controller
public void DisplayStats()
{
if (!statDisplay.isVisible)
{
statDisplay.EnableCanvas();
}
else
{
statDisplay.DisableCanvas();
}
}
that the player will call
void Update{
InputAction fireAction;
bool hasFiredThisFrame;
if (fireAction.WasPressedThisFrame() && !hasFiredThisFrame)
{
hasFiredThisFrame = true;
Fire();
}
}
void Fire()
{
RaycastHit hit;
if (Physics.Raycast(cameraTransform.transform.position, cameraTransform.transform.forward, out hit))
{
if (hit.transform.tag == "Creature")
{
hit.transform.gameObject.GetComponent<CreatureController>().DisplayStats();
}
hasFiredThisFrame = false;
}
}
we can now keep track of the creatures but what about spawning them.
Spawning creatures
We can use the same fire function to spawn them but let’s use UI to go into the spawn mode [screenshot button]
public Image cursorImage;
public void EnableCreatureSpawner()
{
DisableMenu();
playerCamera.isInSpawnMode = true;
playerCamera.spawnMode = SpawnMode.Creature;
cursorImage.color = Color.green;
}
public LayerMask objectSpawnLayer;
void Fire()
{
if (isInSpawnMode)
{
RaycastHit hit;
if (Physics.Raycast(cameraTransform.transform.position, cameraTransform.transform.forward, out hit, Mathf.Infinity, objectSpawnLayer))
{
if (spawnMode == SpawnMode.Creature)
creatureSpawner.SpawnCreatureAtLocation(hit.point);
hasFiredThisFrame = false;
}
}
}
We use a layermask to make sure we spawn on terrain we have a new creature spawner who uses the stats to spawn a creature on the location, which we can also use for the food.
public void SpawnCreatureAtLocation(Vector3 location)
{
UpdateStats();
var newCreature = Instantiate(creatureBase, location, creatureBase.transform.rotation, parent.transform).GetComponent<CreatureController>();
newCreature.gameObject.name = Name.text;
Creature creature = newCreature.InitiateCreature(creatureToSpawnSettings);
newCreature.creature = creature;
}
the spawner has a UI screen with a couple of input fields for the stats
which is what gets used to update the stats
public void UpdateStats()
{
if (Speed.text != "")
creatureToSpawnSettings.Speed = float.Parse(Speed.text);
if (Size.text != "")
creatureToSpawnSettings.Size = float.Parse(Size.text);
if (VisionRadius.text != "")
creatureToSpawnSettings.VisionRadius = float.Parse(VisionRadius.text);
if (WalkRange.text != "")
creatureToSpawnSettings.WalkRange = float.Parse(WalkRange.text);
if (MaxHunger.text != "")
creatureToSpawnSettings.maxHunger = float.Parse(MaxHunger.text);
creatureToSpawnSettings.diet = (Diet)Diet.value;
creatureToSpawnSettings.huntType = (HuntType)HuntType.value;
}
this gives us the option spawn in creatures how we want. to showcase some creatures before hand in the scene i’ve added an extra boolean that let’s the developer spawn one in beforehand.
public bool isPreSpawned;
private void Start()
{
if (isPreSpawned)
creature = InitiateCreature(settings);
}
in a similair matter let’s make it able for the player to spawn food, the food doesn’t need much UI atm, just somewhere to change the hunger value 
public void SpawnFoodAtLocation(Vector3 location)
{
spawnFood.HungerValue = float.Parse(HungerValue.text);
spawnFood = Instantiate(foodBase, location, creatureBase.transform.rotation, parent.transform).GetComponent<Food>();
}
then the rest is all the same as the creatures just using a different “spawn mode”.
public void EnableFoodSpawner()
{
DisableMenu();
playerCamera.isInSpawnMode = true;
playerCamera.spawnMode = SpawnMode.Food;
cursorImage.color = Color.green;
}
Creature saving and loading
While we can spawn the creatures in, players might want to keep track of the creatures they have or have preloaded ideas for creatures to load in. this is where there’s an added function for the creature spawner to save and load the creatures
Saving
Saving is a bit easier then loading as we just need to keep track of the settings and make a settings object for it.
public List<CreatureSettings> creatureSettings;
public void SaveCreature()
{
var newCreatureSettings = ScriptableObject.CreateInstance<CreatureSettings>();
newCreatureSettings.name = Name.text;
newCreatureSettings.Speed = creatureToSpawnSettings.Speed;
newCreatureSettings.Size = creatureToSpawnSettings.Size;
newCreatureSettings.VisionRadius = creatureToSpawnSettings.VisionRadius;
newCreatureSettings.WalkRange = creatureToSpawnSettings.WalkRange;
newCreatureSettings.maxHunger = creatureToSpawnSettings.maxHunger;
newCreatureSettings.color = creatureToSpawnSettings.color;
newCreatureSettings.diet = creatureToSpawnSettings.diet;
newCreatureSettings.huntType = creatureToSpawnSettings.huntType;
creatureSettings.Add(newCreatureSettings);
}
the creature settings list is used for the loading afterwards, but we basically just save all the settings we added and make a settings out of it, that we then add to the list to access later. this currently only works during the build if the game is closed it will not be kept as scriptable objects will not saved, this will be turned into a json file later.
Loading
for loading we use the list and use screen to show the existing settings using buttons
public void LoadCreature()
{
// Clear existing buttons safely
for (int i = ActiveLoadButtons.Count - 1; i >= 0; i--)
{
Destroy(ActiveLoadButtons[i]); // Destroy the button
ActiveLoadButtons.RemoveAt(i); // Remove from the list
}
foreach (var settings in creatureSettings)
{
LoadButton loadButton = Instantiate(LoadButtonPreset, loadList.transform).GetComponent<LoadButton>();
loadButton.gameObject.name = settings.name;
loadButton.creatureSettings = settings;
loadButton.creatureSpawner = this;
ActiveLoadButtons.Add(loadButton.gameObject);
}
DisableCanvas();
loadList.SetActive(true);
}
then when pressed on one of the buttons it fills the textboxes with the settings
public class LoadButton : MonoBehaviour
{
public CreatureSettings creatureSettings;
public CreatureSpawner creatureSpawner;
public void LoadSettingsIntoSpawner()
{
creatureSpawner.FillTextboxesWithSettings(creatureSettings);
creatureSpawner.EnableCanvas();
creatureSpawner.loadList.SetActive(false);
}
}
public void FillTextboxesWithSettings(CreatureSettings settings)
{
Name.text = settings.name;
Speed.text = settings.Speed.ToString();
Size.text = settings.Size.ToString();
VisionRadius.text = settings.VisionRadius.ToString();
WalkRange.text = settings.WalkRange.ToString();
MaxHunger.text = settings.maxHunger.ToString();
colorPicker.color = settings.color;
Diet.value = (int)settings.diet;
HuntType.value = (int)settings.huntType;
}

Color picker
as a fun thing for players to differentiate the creatures i’ve also added color aswell using a color picker from the assetstore. the way it gets added is similair to everything else 
Creature settings and creature
public Color color;
creature spawner
creatureToSpawnSettings.color = colorPicker.color;
to update it in the creature controller onto the material
private void Start()
{
GetComponent<MeshRenderer>().material.color = creature.color;
}
Conclusion
In the end I ended up creating a bare minimal Ecosystem with creatures that can die eat and procreate, I would love to continue onto this product and introduce more variation for the creatures.
References
[1] S. Lague, Sebastian Lague, YouTube, 02-11-2024. Available: https://www.youtube.com/@SebastianLague
[2] S. Lague, „Coding Adventure: Simulating an Ecosystem“, YouTube, 10-06-2019. Available: https://www.youtube.com/watch?v=r_It_X7v-1E&t=2s
[3] S. Lague, „Procedural Terrain Generation Playlist“, YouTube, 31-01-2016. Available: https://www.youtube.com/playlist?list=PLFt_AvWsXl0eBW2EiBtl_sxmDtSgZBxB3
[4] S. Lague, “Procedural-landmass-Generation”, GitHub, 31-01-2016. Available: https://github.com/SebLague/Procedural-Landmass-Generation
[5] S. Lague, “[Unity] Procedural Object Placement (E01: poisson disc sampling)”, YouTube, 23-11-2018. Available: https://www.youtube.com/watch?v=7WcmyxyFO7o
[6] S. Murray, “No man’s Sky: All planet Types”, TheGamer.com, 02-04-2024. Available: https://www.thegamer.com/no-mans-sky-nms-all-planet-types-explained/#:~:text=No%20Man's%20Sky.-,No%20Man's%20Sky%20Planetary%20Biomes,Irradiated%2C%20Marsh%2C%20and%20Volcanic.
[7] T. Tae Oh, “Why Fun Is Key to Happiness As We Age”, nextavenue.org, 15-07-2021. Available: https://www.nextavenue.org/why-fun-is-key-to-happiness-as-we-age/
[8] T. Tae Oh, “What Makes You Happy? Why Fun Matters to Your Happiness”, PsychologyToday.com, 23-09-2021. Available: https://www.psychologytoday.com/us/blog/the-pursuit-fun/202109/what-makes-you-happy-why-fun-matters-your-happiness
[9] M. Rucker, “Type II Fun: Embracing Hard Fun for Personal Growth”, PsychologyToday.com, 30-04-3024. Available: https://www.psychologytoday.com/us/blog/the-science-of-fun/202404/type-ii-fun-embracing-hard-fun-for-personal-growth
[10] “Simulation video game”, Wikipedia. Available: https://en.wikipedia.org/wiki/Simulation_video_game
[11] “Game Elements and Mechanics”, GameDesigning.org. Available: https://www.gamedesigning.org/learn/game-elements/
[12] “Sandbox game”, Wikipedia. Available: https://en.wikipedia.org/wiki/Sandbox_game
[13] “SPORE”, Steam, Electronic Arts. Available: https://store.steampowered.com/app/17390/SPORE/
[14] “Niche – a genetics survival game”, Steam, Stray Fawn Studio. Available: https://store.steampowered.com/app/440650/Niche__a_genetics_survival_game/
[15] “Species: Artificial Life, Real Evolution”, Steam, Spec Evo Studios. Available: https://store.steampowered.com/app/774541/Species_Artificial_Life_Real_Evolution/
[16] “The Universim”, Steam, Crytivo. Available: https://store.steampowered.com/app/352720/The_Universim/
[17] “Rain World”, Steam, Videocult. Available: https://store.steampowered.com/app/312520/Rain_World/
[18] “Endling – Extinction is Forever”, Steam, Herobeat Studios. Available: https://store.steampowered.com/app/898890/Endling__Extinction_is_Forever/
[19] “Subnautica”, Steam, Unknown Worlds Entertainment. Available: https://store.steampowered.com/app/264710/Subnautica/
[20] “No Man’s Sky”, Steam, Hello Games. Available: https://store.steampowered.com/app/275850/No_Mans_Sky/
[21] “The Isle”, Steam, Afterthought LLC. Available: https://store.steampowered.com/app/376210/The_Isle/
[22] “Eco”, Steam, Strange Loop Games. Available: https://store.steampowered.com/app/382310/Eco/
[23] “Themes and Concepts of Biology”, OpenStax.org. Available: https://openstax.org/books/concepts-biology/pages/1-1-themes-and-concepts-of-biology
