Using Structs in C++

Chris Didier
3 min readJun 26, 2022

We are going to be working with structs and how to get parts from a struct.

We are going to delete all of our UProperties we did from the last tutorial from the header and the variables in the C++ File.

Now let’s back over to our header file and add a UPRoperty and add a FVector. An FVector is a struct. We will assign it a default value called Constructor. For this we want to say there is an FVector(with parameters). In the editor you will see that the variables are now showing for our vector.

Now if we want to access these values in another UProperty. We must create a new variable we will call MyX that is a float.

Over in the cpp file we are going to set MyX = MyVector, but what parameters are we going to put in?

Well we need to know what an operator is.

  • Operator — Symbols that do something (Math…)
  • Dot Operator — gets something from within a struct or class.

So in this case we want to assign it to the .X position of the vector.

So save and compile we see back in the editor we our MyX. I then gave it a value of 8.0, but when I press play it will move to 1.0

Before
After

We are now going to set a Vector value of our own instead of getting one. We are going to swap our MyVector and MyX variables.

Back in the editor we will change MyX to 6.0 and when we press play the Y Value will change to 6.0.

This will allow us to use more compound code like structs going forward.

--

--