Skip to content
Alexander Strada edited this page Mar 21, 2021 · 9 revisions

Valheim Spawning

Valheim spawning consists of multiple joined disjointed systems.

Main amongst them are:

  • RandEventSystem - Raid management
  • SpawnSystem - General spawning. Handles spawning for raids too.
  • CreatureSpawner - Localized more fine-tuned spawning, such as ruins or firehole. These also includes goblin camps, dungeons and draugr villages.
  • SpawnArea - Destructible Spawners that you can encounter in dungeons, in biomes. (draugr pile, bone pile, greydwarfnest...)

SpawnSystem

  • Defined as part of the _ZoneCtrl prefab. These are instantiated when locations are loaded in, but are not directly tied to locations and can appear away from them.

  • Each _ZoneCtrl will have its own SpawnSysten, with its own SpawnData associated. Changing one, will only affect that one.

  • Each _ZoneCtrl will be placed at some point in the location, and will be despawned as players get out of range.

  • The _ZoneCtrl is initialized with an IsOwner check, meaning only one client will be in control of all spawning.

  • The _ZoneCtrl prefab is defined in only one place, the ZoneZystem. All instantiations of it will have the full list of all possible spawners.

  • SpawnSystem checks each spawner it has associated for each update, for whether or not it should start spawning mobs.

    • There is a good 44 spawners by default
    • They are by default positioned as a grid with distance 64 between each other.
  • Each Zone can be identified in the ZoneSystem, as a block of 2x2 (see ZoneSystem.GetZone(Vector3 point))

Instantiated at:

ZoneSystem -> Update -> CreateLocalZones -> PokeLocalZone -> SpawnZone

or

ZoneSystem -> Update -> CreateGhostZones -> SpawnZone

In the ghost spawn mode, the zoneCtrl instantiated will be destroyed almost immediately after initialization.

Update loop: SpawnSystem -> UpdateSpawning

Invoked every 4 seconds.

Checks for ownership as well as nearby players.

Calls UpdateSpawningList with this.m_spawners, which are the spawners designated at instantiation of prefab _ZoneCtrl.

If an event is active, it will do an additional call to UpdateSpawningList, with the spawners of the RandEventSystem.

UpdateSpawning -> UpdateSpawningList

Checks all input spawners for valid spawn conditions.

Conditions:

  1. Spawn enabled
  2. In the right biome
  3. Compare spawn frequency with last spawn of spawner. (I think this one actually carries across different SpawnSystems, due to the way they calculate the hashcode. Meaning index becomes very important) -> Starts looping
  4. Chance to spawn
  5. A required global key is is set.
  6. The environment is right.
  7. Can spawn at day, and time is day.
  8. Can spawn at night, and time is night.
  9. There are less entities of the prefab of the spawner spawned at location zero?? than there are m_maxSpawned. This one might actually just be a waste of cpu.
  10. Checks FindBaseSpawnPoint
  11. SpawnDistance <= 0 or if any SpawnData.m_prefab is not within SpawnData.m_distance of the point found by FindBaseSpawnPoint.

-> Loops through random group size * 2, stopping if enough have spawned.

  1. Generates a random point in a circle, then checks IsSpawnPointGood again

-> IsSpawnPointGood

-> Spawn

FindBaseSpawnPoint

Loops through an additional spawn condition check, up to 20 times, using a randomized position based off a random Player. Returns whether or not a position was found, and outs the Vector3 it was found at.

IsSpawnPointGood

  1. Is in right biome
  2. Is in right biome area
  3. Position is not blocked
  4. Inside altitude requirements, based on water level.
  5. Position tilt acceptable
  6. Spawn radius not too close to player.
  7. Is position checked inside EffectArea.Type.PlayerBase
  8. Is the spawn allowed in forest / outside forest, and is the location inside a forest.
  9. Is ocean depth min and max equal, or is position within ocean depth range.

CreatureSpawner

  • Loaded in as part of ZoneSystem, are part of the Location objects being loaded.
  • Each location is defined as part of a biome "_Zone", which has a set of potentiel locations inside it.
    • Blackforest is a "_Zone", inside blackforest could be locations:
      • Trollcave
      • Greydwarf_camp_1
  • Each location will most often have a set of CreateSpawner's defined, placed relative to the center of the location transform.
  • These spawners are simplified versions of the SpawnSystem, and will have their own update loop, for checking if a single enemy type should be spawned in, according to their own limits of respawn time and max.
  • They each only have a specific single enemy defined.

Locations:

  • StoneCircle
  • StartTemple
  • Eikthyrnir
  • GoblinKing
  • Greydwarf_camp1
  • Greydwarf_camp2
  • Greydwarf_camp3
  • Runestone_Greydwarfs
  • Grave1
  • SwampRuin1
  • SwampRuin2
  • FireHole
  • Runestone_Draugr
  • Castle
  • Fort1
  • xmastree
  • GDKing
  • Bonemass
  • Meteorite
  • Crypt2
  • Ruin1
  • Ruin2
  • Pillar1
  • Pillar2
  • StoneHouse1
  • StoneHouse1_heath
  • StoneHouse2_heath
  • StoneHouse5_heath
  • StoneHouse2
  • StoneHouse3
  • StoneHouse4
  • StoneHouse5
  • Ruin3
  • GoblinCamp1
  • GoblinCamp2
  • StoneTower1
  • StoneTower2
  • StoneTower3
  • StoneTower4
  • StoneHenge1
  • StoneHenge2
  • StoneHenge3
  • StoneHenge4
  • StoneHenge5
  • StoneHenge6
  • WoodHouse1
  • WoodHouse2
  • WoodHouse3
  • WoodHouse4
  • WoodHouse5
  • WoodHouse6
  • WoodHouse7
  • WoodHouse8
  • WoodHouse9
  • WoodHouse10
  • WoodHouse11
  • WoodHouse12
  • WoodHouse13
  • WoodFarm1
  • WoodVillage1
  • TrollCave
  • TrollCave02
  • SunkenCrypt1
  • SunkenCrypt2
  • SunkenCrypt3
  • SunkenCrypt4
  • Dolmen01
  • Dolmen02
  • Dolmen03
  • Crypt3
  • Crypt4
  • InfestedTree01
  • SwampHut1
  • SwampHut2
  • SwampHut3
  • SwampHut4
  • SwampHut5
  • SwampWell1
  • StoneTowerRuins04
  • StoneTowerRuins05
  • StoneTowerRuins03
  • StoneTowerRuins07
  • StoneTowerRuins08
  • StoneTowerRuins09
  • StoneTowerRuins10
  • Vendor_BlackForest
  • ShipSetting01
  • Dragonqueen
  • DrakeNest01
  • Waymarker01
  • Waymarker02
  • AbandonedLogCabin02
  • AbandonedLogCabin03
  • AbandonedLogCabin04
  • MountainGrave01
  • DrakeLorestone
  • MountainWell1
  • MountainCave01
  • ShipWreck01
  • ShipWreck02
  • ShipWreck03
  • ShipWreck04
  • Hugintest
  • Runestone_Meadows
  • Runestone_Boars
  • Runestone_Swamps
  • Runestone_Mountains
  • Runestone_BlackForest
  • Runestone_Plains
Clone this wiki locally