Space Engineers

Space Engineers

71 ratings
Rules of Nature! Advanced lightning guide
By Merii
Guide to how lightning works in Space Engineers, as of 1.200.032. Likely valid for the foreseeable future.
3
5
   
Award
Favorite
Favorited
Unfavorite
Introduction
So we all hate having lightning blow up our stuff, right? Pertam electrical storms driving you nuts? Me too. I decided to do some research into the actual mechanics of lighting.

Here's what I've got. All data is taken directly from game files and code, so this may contradict what you think should happen.

This guide is about working with the game rules for lightning. If you don't want lightning to strike or do damage, there are mods for that!
When does lightning strike?
Let's start from when the storm blows in. First, it chooses where to strike. It generates 3 random numbers, for "next lighting", "next lightning character" and "next lightning grid" based on the max and min intervals as defined in the weather configuration in Content\Data\WeatherEffects.sbc. Those numbers are stored as seconds in the data file and are turned into frame counts in the code, and every frame it decrements the number by 1. When it hits zero, lightning strikes.

Rule 1: The timers for the ground, characters, and grids are separate, but there is always going to be a minimum and maximum time between strikes of all 3.
Where does lightning strike?
A single lightning strike always has a pair of true/false values defined: hit grids and hit characters. Currently, it appears that these are never both true, but they could be. Even if both were true, it will always choose a grid first if one is available.

First, the game figures out the bounding sphere of the weather - that is, an orb based on the position of the weather effect in the world with a radius of the size of the weather effect. It finds all grids that are contained within that orb, and chooses based on a few rules. The rules are: Is not immune (due to being an invulnerable admin), *is not a respawn ship*, is not a projection, and a couple other things related to grids in the process of being destroyed.

Rule 2: Your respawn ship (survival pod) will never be struck by lightning if it's still considered a Respawn Ship.

You can tell if your pod is still a respawn ship by the red text saying it will be removed if you spawn a new one when you try to build on it, and it has a GPS marker that follows it around.

For characters, it simply checks to see if the user is an untargetable admin or not and if so doesn't hit them. Only "online" characters are considered, so you can never die to lightning if you're disconnected.

Rule 3: Offline characters are never struck by lightning.

Both grids and characters are selected via random chance, all grids and characters within the storm's sphere are considered equally.

Game rule: This is not specific to weather, but characters inside a grid (for example, in a cockpit or cryo tube) are not considered to be "characters", they're just part of the grid. You can see this if you set a sensor to detect characters but not grids and fly a ship up to it with your cockpit in the sensor range. The sensor only sees your character once you get out of the cockpit. This can be used to further escape storms though - take a seat in a passenger seat or cockpit til it blows over!

If there are no grids or characters within the storm, it still causes lightning, but it will never do damage and is just randomly placed within the storm.
How can strikes be mitigated?
What about decoys? That's the next part! The storm found your delightfully conductive grid and wants to zap the hell out of it and destroy your hard work, but first it checks to see if there's anything that's considered a decoy nearby. How thoughtful!

Standing under a tree in a lightning storm sounds stupid, but in Space Engineers, it's actually the correct thing to do. Decoys are great, but if there's a tree within 400 meters of where the lightning is going to strike, it will always hit the tree first. Yes, it will do enough damage to the tree to one-shot it, but if you're caught out in a thunderstorm in Space Engineers without a base nearby, the safest thing to do is get to a forest.

Rule 4: Trees are the best lightning rods.

What if you don't have any trees nearby? You need a decoy. There are a couple of major checks that are done for decoys that are not called out anywhere and these are what are going to trip most people up.

Static grids (a grid embedded within the ground or made into a station) have priority over dynamic grids in all cases. This means that a decoy on a static base always has priority over a decoy on a ship or rover. This is great, because generally you want a dedicated static lightning rod to be hit instead of your ship or rover's decoy.

However, there's a catch. Decoys on subgrids are considered after all main grids. The lightning tries to find the main grid (Usually the one that was built first, so in the case of a grid built from the projector, the largest grid) and find a decoy on that, for all static grids in the area. Failing that, it tries to find a decoy on the main grid for all dynamic grids in the area.

After it has searched all main grids, it searches all blocks in all grids that it previously checked, including subgrids, in the same order (so static first, then dynamic) for a decoy or antenna on that grid. This means that even if there's a dynamic grid with a decoy, it would prefer a static grid with an antenna.

The second big check for a decoy is that it must not be "underground". The rules to this are strange. First of all, if the decoy is under the planet's Minimum Radius, it's considered underground. If it's not under the minimum radius, then it can't be below the local surface. This means don't dig out a big pit and put your decoys in that.

Finally, the rule that most people are familiar with: The target point must be within the Safety Radius of the decoy. This is not actually the safety radius in Content\Data\WeatherEffects.sbc - it is defined on the item definition but the defaults are used since it's not defined in the cubeblocks SBC. For Large Grid decoys, the radius is 50m, for small grid the radius is 10m. This can't be changed due to a hardcoded check of 50m in the code, though - the decoy must be within the safety radius or 50m of the struck block, whichever is smaller, no matter what.

Rule 5: Decoys on static main grids are preferred over decoys on dynamic main grids, but decoys or antennas on static subgrids are preferred over decoys or antennas on dynamic subgrids.

Rule 6: Decoys cannot be underground.

Safety Radius: Large Grid 50m, Small Grid 10m.

The big question: why does my base keep getting hit underground? Well, if you remember the rules for what grids were checked, I didn't mention anything about an "underground" check for the grid, just for decoys. That's right: if you're within the Radius of the storm, your underground base might just get hit if it's not within the safety radius of a decoy that is above ground. There's a couple more checks for that later though, but as I'm sure you've seen if you've experienced this, they can fail.

Onto antennas! Antennas cannot be underground to be considered, and must be turned on. Only proper antennas are considered - beacons are not Radio Antennas for this purpose. The dish is also considered an antenna. Grid size is not checked for antennas, which means that lightning absolutely can and will target Small Grid antennas.

Much like decoys, antennas have a safety radius but it's much smaller than a decoy: Large grid is only 10m and small grid is only 2m.

Rule 7: Decoys will be hit before antennas, and beacons are not antennas for lightning rod purposes.

Safety Radius: Large Grid 10m, Small Grid 2m.

The final check before zapping your precious grid or player that just got elite tools and then ground down the medbay is a raycast. It tries to figure out a point about 50 meters "up" (relative to planet gravity) from where it chose to hit, then does a raycast to that point. If it hits anything on the way, it chooses the point that the ray hit to strike rather than the point it was going to strike originally.

I don't know why a raycast could fail to hit stuff on the way, but I'm guessing "adaptive simulation quality" may have something to do with it - for example, does underground striking happen more at high load? Maybe it spawns the ray inside the ground and then it doesn't hit the back face of the world. Who knows!

Rule 8: A final raycast check is attempted to try to make sure that the lightning hits ground or a block before hitting its target, but it's only 50m long so it may fail to correctly check if your base is too deep or your CPU is struggling.
Mitigation strategies
Armed with the knowledge above, go forth, build (static grid) lightning rods, and conquer Pertam's electrical storms! Smile smugly as lightning falls all around you and never touches your grids!

Warning: Lightning has splash damage. Make sure any deformable blocks such as armor or interior wall blocks are not adjacent to the decoy in any direction if it is unprotected by a non-deformable block. If it is protected, make sure that deformable blocks are not adjacent to the protective block.

If you're just starting out, get your Basic Assembler up ASAP and build a decoy sticking out of the ground or attached to your base - that's enough. Repair it when lightning strikes it.

This is the best lightning rod I've come up with. Just fill the welder with steel plate or connect it to your base conveyor system and relax! Check it after the storm and refill if needed. A solar panel can be used to recharge the battery if needed, but a welder takes almost no power so it should last a good long time, and even if it goes out, decoys don't need power at all.



Lightning used to strike blocks above decoys but currently does not[support.keenswh.com]. This is a bug and may be fixed in the future, after which the following should apply. For now though, lightning snipes decoys no matter where they are in your ship or base.

If it does get fixed, you want a block on top of your decoy as shown below:

A wheel is much cheaper and seems to take less damage (3 steel plate worth of damage instead of 4-6) but a 1x1 is not ideal because of the possibility of two hits in very close succession (grid and character strike timers being close), so a 3x3 is the best.



If steel plate is not an issue, a Blast Door variant should be used.



Any non-deformable block with a bunch of steel plate is fine as the top block - even a battery can be used as a top block!
12 Comments
Merii  [author] 24 Feb @ 9:38am 
The game decides to hit a grid, then decides on a random block on that grid, then does a search for decoys within 50m of that block after it has chosen the point to strike.
Mmarss 24 Feb @ 2:37am 
One point here isn't quite clear to me: if a grid is larger than a decoy's safety radius, do we need multiple lightning rods?

Does the game decide to strike a grid, then look for decoys within 50m of the grid, and finding one, hit the decoy? Or does the game decide to strike a grid, then pick a point on the grid to strike, and only then look for decoys within 50m of that point?
evilshroud 25 Oct, 2022 @ 10:01am 
I just got my first lightning strike. Haven't played the game in quite a while, but after this came out. I must have been lucky never to encounter it before. Unfortunately, it therefore took out my tall solar array. I am so very sad, but now I have a project for tomorrow after work.
griffithwes 30 May, 2022 @ 9:04pm 
And they run when the sun comes up. With their lives on the line. A L I V E.
⫸Lyric Drake 591⫷ 24 Oct, 2021 @ 3:41pm 
neat.
EnjoyCoke 22 Oct, 2021 @ 8:35am 
So... actual "decoy"-block is what we're gonna want to use over antennas? This is pretty cool. Thanks for the guide :D
thelolrus 30 Apr, 2021 @ 6:38pm 
...I misread the title as Rules of Natural Advanced lighting guide and was very excited to see a cool lighting guide...

I need some glasses :praisesun:
General Space 27 Apr, 2021 @ 6:03am 
Thanks!
Merii  [author] 26 Apr, 2021 @ 3:59pm 
@General Space: The two props are called LightningRodRadiusLarge and LightningRodRadiusSmall - both can be set on the same block, which doesn't make sense, but it checks the Large one for LG and the Small one for SG, as expected. They both hang off of MyObjectBuilder_DecoyDefinition if that helps you any!
General Space 26 Apr, 2021 @ 1:43pm 
Let's say, theoretically, one had a lightning rod mod and wanted to add a different safety radius to that specific block's sbc entry. In your research, did you discover the syntax for a block-specific safety radius?