Tutorial: Solar Panel

From ARK Modding Wiki
Jump to navigation Jump to search


Solar Panel Preview


Introduction

Hello there!

The theme of the 4th modding tutorial competition was to create a mod for "Space Day", which celebrates science and technology. In keeping with that theme RedDwarf (myself) and Pleasure have teamed up to build a working solar panel for ARK, completely from scratch. Pleasure created an excellent youtube video tutorial in which he shows how the solar panel model was constructed. And this tutorial that you're reading now will walk you through how to setup the solar panel so that it can be used in-game.

Click Here to watch the modeling tutorial by Pleasure!


Youtube link



The Plan!

This solar panel will provide power during the day, if it's not build inside.

Additionally, the player can build batteries inside the solar panel's inventory, which allows the panel to charge the batteries during the day and discharge the batteries at night when no sunlight is available. Each battery extends the solar panel's power by 1 additional in-game hour. Players will need to build enough batteries to survive the night, if they want uninterrupted power.

The charging methodology is vary simple: When night sets, the solar panel will count the number of batteries currently in it's inventory, and begin a countdown showing how much battery time is left. Any battery added during the daytime is considered charged when night sets, but any batteries added at night will be ignored (since they have not been charged by sunlight). Additionally, if batteries are removed at night, the timer will go down -- and if it hits zero, the solar panel will be out of juice and shut down until the sun rises the following morning. =)

Let's get started!


Setting up the Solar Panel structure

Firstly, create a new directory under your "Mods" folder called "SpaceDay_SolarPanel" (or whatever you'd like your mod to be called), and create a new PrimalGameData file for it.

Inside this mod folder, I usually create an "Assets" folder for sounds and meshes, and an "Items" folder for blueprints and in-game items.

Like many modders, when creating a simple crafting structure, let's start by copying the Smithy ("StorageBox_AnvilBench") to our "Items" folder, and rename it "SolarPanel_BP".

Now, before we begin, let's discuss a little trick that we're going to do. If you look at the reference picture at the top of the tutorial, you'll see that the solar panel is connected to the battery storage box by an electrical cable and junction box.


9xAz76O(1).png


Wouldn't it be nice if that electrical cable changed color when the power was on, as a visual indicator? We can do that! The devkit has an easy built-in way to change materials on it's default static mesh when the structure is activated. For example, a refrigerators green lights might come on, etc.

So what we're going to do is assign the static mesh of our solar panel to be that cable (so that we can change it's color on activation), and we'll manually add the actual solar panel later as an additional static mesh component. Your "components" list will end up looking like this:


V1sGJJN(1).png


More on that later!

Next, let's take a look at how we should setup the "SolarPanel_BP" defaults.

Solar Panel: Defaults

As mentioned earlier, we're going to use an electrical cable mesh as the primary mesh for this solar panel, so that we can easily adjust it's materials when the solar panel is powered up, like so:


Ok6UN5y(1).png


  • Active/Inactive Materials: Powered and unpowered cable materials (yellow vs. gray).
  • Disable Activation Underwater: Probably a good idea for players to not put their battery boxes underwater!
  • Powered Water Source when Active: This means that the structure will generate Power and Water when activated. We're only going to add snap points for electrical cables, but in theory you could also get water out of this structure if it had a snap-point to add water pipes. That doesn't sound safe!
  • Container Activated/Deactivated Sound: For this, I borrowed the pre-existing activation sounds from Aberration's Charge Lantern. This adds a nice mechanical sound to the structure when it turns on.
  • Dont Actually Snap Just Placement: The generator blueprint has this checked, so I'm following along. I believe this means that the structure cannot use existing electrical cables as "support".
  • Blueprint Draw HUD: Later we will be adding code to generate a nice "Status" message for the user when they look at the structure, so we'll need this box checked so that the graph function will be called.
  • Damage Type Adjusters: This structure doesn't take any special damage from anything.
  • Structure Settings Class: "Broken By Metal" is the "Wood Tier", meaning that you can break it with metal tools, which makes sense for a solar panel. This is also in keeping with the durability of the generator.


LQ8UyN7(1).png


  • Consumes Primal Item: This should be setup to consume the PrimalItem that represents your SolarPanel_BP blueprint (we'll cover that in a moment).
  • Structure Snap Type Flags: This one is very important. This number serves as a bit-mask to tell the game which types of items can be snapped to it. For the full details, check out the Snap Points page.
  • Snap Points: The structure contains 4 snap-points, which are all identical except that their "Point Rot Offset" is rotated by 90 degrees each time. This allows you to snap cables in 4 directions. These cables have a "Point Loc Offset" which puts the cable snap point just under the battery box at the same height as a generator's snap point, for consistency's sake.

Next, we setup the placement details, health, name etc:


VHz9YTc(1).png


  • Placement Encroachment Check Offset / Box Extent / Trace Scale: These settings determine how much space your structure will need in order to be placed.
  • Placement Rotation Offset: This rotates the model 90 degrees so that it's facing us when we place it.
  • Requires Placement on Structure Floors: Do to the shape of the model, it would look very bad if placed on uneven ground, so this solar panel requires placement on a structure.
  • Placement Choose Rotation: Allow the player to rotate the structure.
  • Snap Requires Placement on Ground: The solar panel should always be on the ground.

The remaining settings are default for a generator. The "Destroyed Mesh" is left empty, because destroyed meshes take up a lot of disk space and inflate the mod's size, so that's left off for most of the mods that I create.


Solar Panel: Components

As mentioned previously, your SolarPanel_BP structure will contain the following components:


V1sGJJN(1).png
  • MyStaticMesh: "SM_CablesStraight" (The main mesh for the structure.)
  • JunctionBox: "SM_JuctionBox" (This is purely aesthetic, to show how power would get to the battery box.)
  • SolarPanel: "Solar_final" (This is the excellent solar panel model that Pleasant made for this tutorial.)
  • ActivatedEmitter: "SolarPanelEmitter" (This is a copy of the ActivatedEmitter from the Generator, modified with a free sound loop from [FreeSound.org], which gives it an electrical buzz sound when activated.)