First Simple Machine
In this chapter we’ll create a simple machine which simply counts the items and types of items that pass through it, outputting them again on the other side.
Create the machine
Creating a simple machine is fairly straightforward. First of all, you’ll need to create another buildable with descriptor and recipe, but this time use this (TODO make this mesh) as the mesh and this (TODO make this icon) as icon so that it looks a bit more like a machine.
Now we simply want to add the factory-connectors
(conveyor input and outputs).
For that add two new components of type
FGFactoryConnectionComponent to the actor
and place them in the lower center of the input/output connection points of the mesh,
don’t forget to rotate them.
Set the output’s direction to output and the type to Item. The inputs type also needs to get set to Item but the direction needs to be input.
We also want to make our machine depend on electricity.
For that we need to add a FGPowerConnectionComponent
at the position of the power connection point of the mesh.
M Max Num Connections to something like 1 (to allow only one cable to get connected).
The init logic happens in the
BeginPlay event and initializes the
base state of the factory (also based on the save information).
There is not that much we need to do here.
The only thing we need to do is to set the PowerInfo of the power connector to your added
FGPowerInfoComponent and we need to set the target consumption of the power-info to something like 1.0.
FactoryGrabOutput function of the
FGBuildable gets executed by the output
connector when a new item gets requested. To add logic to it, we simply need to override it.
Because we want to store the count of items transferred
and the count of different item-types,
we will need to add a new global integer variable,
let’s call it "itemAmount"
and a array of
FGItem-Classes, call it "itemTypes".
Now, in the grab logic, first we check if the machine has power.
We do this by using the "HasPower"-node of the
If it returns false, we return nothing and the boolean is false.
But if it’s true, we use the grab function of the input connector to request a new item.
If the boolean is true, we increase the "itemAmount" integer by one and add the item unique to the "itemTypes". Now we simply log "itemAmount" and the size of the "itemTypes"-array. After that we return the item we got from the grab and true.
If the boolean is false, we just return nothing (the boolean needs to be false).
This basically checks if we have power, if we do, it trys to get a item from the input, if that is not the case, we do nothing. But if we get a item, we count it and then return it to the output.
That’s it, try out your newly created machine!