Spacecraft: Configuring the Universe
Event Graph
The Event Graph is a node-based system that allows users to define the behavior of objects and characters by creating a series of events and actions. In the Event Graph, you can create nodes that represent events such as player input, collision detection, or timer events. These events can trigger various actions or functions, such as spawning a spacecraft or running a simulation.
By default, there are two events that exist in the event graph; disabled.
- Begin Play: This event is executed when the level starts running and will run once. This is typically used to spawn all spacecraft and configure the simulation.
- Tick: This event is executed every Unreal frame (not simulation tick), which may be up to 60 times a second depending on the hardware capabilities. This event is typically used for running the simulation and updating the user interface.
A number of other events, such as input events, can be added to the event graph. This tutorial will not cover how these events can be configured but are standard Unreal Engine events. Information on the event graph can be found below.
Creating a Function
Although all of the blueprint code can be written on the event graph, it is best practice to group blueprint code into function blocks. Each function has a specific purpose, may have some input and output variables and can repeat multiple times if necessary. To construct a new function, navigate to the outliner and click the ➕ button on the functions tab. The first function will be the Configure Universe
function.
In the details panel, information about the inputs and outputs of the function are shown. These can be edited later and do not need to be defined immediately.
Setting up the Universe
For space domain simulations, the Universe System provides the context of the simulation epoch, celestial bodies and objects that exist within the simulation. The universe will be created in every simulation by default and always exist. By default, this step is not required and the Universe will initialize the starting epoch to be the current date-time and the central body to be the Earth. However, the Universe can be called in the Blueprint editor and those initial values can be adjusted to some custom ones. There are two ways to do this. For the standard set of initial values, use the Configure Universe
function. This should be under the Nominal
****************tab. To find a function, right-click on the level blueprint and search for a function name.
This function provides three inputs:
- Epoch: The current timestamp of the simulation in UTC time. To adjust the Epoch, a pin must be dragged out and the
Make DateTime
node must be connected to this input. - Zero Base: This defines the central location of the coordinate system. By default, this will be located on Earth. This means that the position
0, 0, 0
is situated in the centre of Earth. - Coordinate Frame: This defines the SPICE frame for the coordinate system. By default, a J2000 frame will result in the J2000 meridian being used for the epoch system. Alternatives will change the rotation of the planet and the coordinate system used.
Alternatively, these values can be directly edited on the Universe rather than calling a function. This is how additional configurations can be made to the Universe, such as setting up environment models or albedo data.
Exposing Input Parameters
Adding inputs to a blueprint function can be easy. Although inputs can be manually added by selecting the function and adjusting the inputs in the details panel, a quick way to add new inputs is by dragging the input from the node onto the purpose function start.
Multiple inputs can be done in this way, provided that the node touches some blank space without another parameter (to avoid a casting). From here, changes to the name of the inputs or type when required can be done using the details panel.
Note
The same process can be done for outputs. This function requires no outputs, but by selecting the Output Node from the blueprint search and dragging in the variables to output, the values can be exposed to the right of the function call.
Calling the Function
Once a function is created, it is important to add it to the Event Graph. In this case, the configure universe function needs to be added to the Begin Play
event. Drag or find the function call from the blueprint search and connect up the nodes from the event call. This will enable the event if it is the first function in the list.
Running the Level
Whenever enough changes have been made, to run the level make sure to compile the level assets. This button is located in the toolbar. Hit the save button as well to make sure the changes are not lost. When the play button is pressed, a new window (or the viewport) will start running the level. Without any simulation objects, the level should showcase the Earth in the centre of the world and nothing else.
To stop the level, either close the window or press the stop button in the toolbar. Blueprint coding can continue from there.