A little uncertainty about declaring FRotators

Hi,

How come we must write:
“FRotator NewRotation = FRotator(0.0f, -75.0f, 0.0f);” when we declare a new variable instead of simply:

“FRotator NewRotation = (0.0f, -75.0f, 0.0f)”;

If we declare an int we would also just write “int number = 5;” and not “int number = int(5);” or something.

In this step a new FRotator is constructed by the statement on the right, that FRotator value is copied to our NewRotation variable.

Here Visual Studio would not know what these values are, and would give an error.

You can write int number = int(5); It isnt written that way because this is a basic type. And it doesn’t need to be declared like that. I don’t know exactly why, but I guess its convenient to write it straight away.

If not clear, I’ll try to explain again.

I think it has something to do with the different types. As in (0.0f, -75.0f, 0.0f) could also be interpreted as a Vector, which is why in C#(which is what im experienced in) we write rotations as rotation = Quanternion.Euler((0.0f, -75.0f, 0.0f) and vectors as vector = Vector3(0.0f, -75.0f, 0.0f). That way the type is known. But that’s just my opinion working with c#.

That’s what I think it is. It doesn’t know what these values are and how to interpret them.

Thanks guys!

I think this helps.

The fact that I COULD write int(5) as well, makes it very clear to me. On some types you just have to instead of it being optional.

There are numerous ways of initialising a variable in C++

std::string str = "hello";
std::string str2("hello");
std::string str3{ "hello" }; //or str3 = { } | The equals sign doesn't make a difference
std::string str4 = std::string("hello")  //or using { }

The reason why

FRotator Rot = (1.f, 1.f, 1.f);

doesn’t work is because (x,x,x) isn’t a type, you would just be tring to assign the right most value to Rot and there’s no assignment overload for FRotator that takes a single float. Though using { } should work as that would be a [list initialisation] (http://en.cppreference.com/w/cpp/language/list_initialization)

1 Like

I think:

FRotator NewRotatoion(0.f,60.f,0.f) it’s best way

Almost!

FRotator Rotation = FRotation(0.f,-60.f,0.r);

Broken down;-

Frotator is the Type
Rotation is the Variable name
FRotation(0.f,-60.f,0.r) constructs a new value to put in that Variable

Privacy & Terms