Chapter 2: Create ComponentSystem

Chapter 2: Create ComponentSystem

Hello everyone. This is Linda again.
in this section, let’s learn how to create a Component System
in the Unity DOTS Visual Scripting Tool environment. Open the Visual Script panel, you’ll see
there are different methods for creating Graph. Graph is Visualization of Component System,
nodes equal to code blocks. Code is automatically generated.
Let’s create a folder for all the graphs called System.
Right click and create a Graph file called Player Control.
The C# code is to be automatically created by the Visual Scripting Tool in the runtime
folder. Drag the Player Ship from the Hierarchy panel
and drop it into graph, VS Tool will automatically create a query
variable for us. Its parameters are components which help us
find this Entity in Entity Lists. Each of the query parameters is a Component
that might contain data or just an empty tag. We only need to keep necessary parameters
for querying the Entity or for Graph usage. Translation, Rotation are not unique components.
In order to return a series of specific query entities,
we often add Tag Component to Entity. We can also create a Entity Query directly
on the Blackboard and drag it into the Graph. Let’s click on the Query slot and drag it
over to create Event Node. We use On Update Node Stack to hold all the
update functions each frame. Select the blank area of the Update node,
press the space bar here. In the pop-up search panel, enter Translate
and add this node into the Update node. Then click the button on the right to change
the float3 input mode to Axis so that we can enter the values for each coordinate
separately. Click on the checkbox next to the gray text
Add because we want to add the input coordinates
as an increment to the current translation. Right click on the canvas, select Get Input
Node. Switch Input mode to Horizontal.
Copy this node, and switch Input mode to Vertical. We will get the X and Z direction keyboard
input data. You may notice the error message at the bottom
of the window. We can clear them in the Console panel at
anytime. Connect the two Nodes you just created to
the X and Z inputs. Click the Play button and test our scene.
Ah, the Player Ship is flying too fast. Since the game (fps) should be greater than
500, the keyboard input will change the value of
the object’s coordinates a lot in a short time.
Let’s create a float variable named Speed on Blackboard.
Drag it onto the Graph and create a node called delta Time.
We need a multiply node, We found that there are two nodes representing
multiplication. They are from different namespace.
They have the same functionality most of the time,
but the Mul node can clearly constrain the data types of our input and output.
So we use the Mul node this time. Multiply delta Time by Speed,
then multiply the result by Keyboard Input. We’ll get the fixed translation data.
Assign the results to X and Z respectively. We can use control C and control V to copy
nodes. You need to Save All and Build each time before
running. This allows the Visual Scripting Tool to convert
Graph Nodes to C Sharp Code in the Run Time folder.
Click on the Code Viewer panel and you will see the automatically generated code.
Here is the Speed variable we created. We set Speed value here.
Here is the code line that changes the Translation value.
Let’s set the speed to 8, slightly faster before running.
Click on the play button again. Nice! The player ship is moving around.
But we found that the ship often moves outside of the view.
Here we need a Node named Clamp, which is used to constrain the X and Z coordinates
we created. To make it easier for us to check if the ship
is in the border area, let’s set the parameters to be smaller than
the background size. We insert these two nodes into the logic.
Because the clamp coordinates are created with absolute coordinates,
you can no longer use the add translation method.
We changed the translate mode to translate to mode.
Drag and drop the Translation variable from the On-Update Node,
which represents the translation of each found Entity.
We use the add node to add the original translation to keyboard input.
Generate a new translation, and finally pass it to the translate node.
Let’s copy these nodes and work on the Z-direction calculations.
Don’t forget to switch the coordinate value here as the Z coordinate.
Save All, Build All, and Play. The player ship does move within the designated
boundary area. Isn’t that cool?
Ok, Its all for today. See you next video!

Comments (4)

  1. Thanks for the videos so far. Really Helpful.

  2. Thanks for the videos so far. Really Helpful.

  3. Thank Kote for the Russian Subtitle!!

  4. Your video was a great help for me, you are very beautiful.

Comment here