Camera Get Transform necessity?

I “solved” the challenge by hooking up the Transform: Get Rotation directly to the Camera: Get Main node, and then hooking it up to the Instantiate node. I tested it and I can’t tell the difference. Why do we add the Camera: Get Transform in between?

There might be some under-the-hood processing that gets the transform from the camera. That said, it would be good not to rely on that and to go through the (albeit more involved) process of getting the transform via the Get Transform node.

That doesn’t really answer my question, in fact, it makes me more curious about why we are adding it. As you say, there “might be” some unseen processing going on but what is that processing? Does it make it more efficient? Or is it something that, for all intents and purposes, is the same outcome? This being my only foray into coding, I understand that there are already some established “best practices” and “we just do this because” but being a clean slate I find it important to try and remove as much unnecessary filler as possible, and trying to understand the importance of each node I add.

I understand that my answer is not the most satisfying. The reason I gave that answer is because that’s the best answer I can give. The source code underlying how visual scripting nodes are processed and the nodes themselves (unless you make your own, which is beyond the scope of this course) is not viewable by us.

Which means all I can do is guess.

The short answer is ‘because that’s how it was done’.

Not all code looks the same. One person may get the rotation directly from the camera, someone else may get the transform of the camera first and then get the rotation from that. In both cases we got the rotation from the transform of the camera.

The nodes pretty much map directly to code. In one case it would be

Quaternion GetRotation()
{
    return Camera.main.transform.rotation;
}

and in the other case it would be

Quaternion GetRotation()
{
    Transform transform = Camera.main.transform;
    return transform.rotation;
}

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms