Why Instantiating Transform object returns the object?

So I’m following a tutorial on endless scrolling.

It is done by creating new tile when the current is near the edge of the screen, so this gives the illusion that the floor is actually endless.

But here is my problem - in another frameworks I used to create new object (sprite) and put it on some position in front of current tile.

But here he actually copies a Transform and result is the same. I thought Transform is the position and rotation in space, and not actual Sprite?

Here is the code:

Transform newBuddy = Instantiate(myTransform, newPos, myTransform.rotation) as Transform;

myTransform is transform, newPos is the calculated position for a new sprite.

How does this even work?

Here is the full code:

using UnityEngine;
using System.Collections;

[RequireComponent (typeof(SpriteRenderer))]

public class Tiling : MonoBehaviour {

	public int offset = 2;

	public bool hasARightBuddy = false;
	public bool hasALeftBuddy = false;

	public bool reverseScale = false;

	private float spriteWidth = 0f;
	private Camera cam;
	private Transform myTransform;

	void Awake() {

		cam = Camera.main;
		myTransform = transform;
	}

	// Use this for initialization
	void Start () {
	
		SpriteRenderer sRenderer = GetComponent<SpriteRenderer> ();
		spriteWidth = sRenderer.sprite.bounds.size.x;
	}
	
	// Update is called once per frame
	void Update () {
	
		if (hasALeftBuddy == false || hasARightBuddy == false) {

			float camHorizontalExtend = cam.orthographicSize * Screen.width / Screen.height;
			float edgeVisibleRight = (myTransform.position.x + spriteWidth / 2) - camHorizontalExtend;
			float edgeVisibleLeft = (myTransform.position.x - spriteWidth/ 2) + camHorizontalExtend;

			if (cam.transform.position.x >= edgeVisibleRight - offset && hasARightBuddy == false) {

				MakeNewBuddy(1);
				hasARightBuddy = true;

			} else if (cam.transform.position.x <= edgeVisibleLeft + offset && hasALeftBuddy == false) {

				MakeNewBuddy(-1);
				hasALeftBuddy = true;
			}
		}
	}

	void MakeNewBuddy (int rightOrLeft) {

		Vector3 newPos = new Vector3 (myTransform.position.x + spriteWidth * rightOrLeft, myTransform.position.y, myTransform.position.z);
		Transform newBuddy = Instantiate (myTransform, newPos, myTransform.rotation) as Transform;

		if (reverseScale == true) {
			newBuddy.localScale = new Vector3(newBuddy.localScale.x * -1, newBuddy.localScale.y, newBuddy.localScale.z);
		}

		newBuddy.parent = myTransform.parent;

		if (rightOrLeft > 0) {
			newBuddy.GetComponent<Tiling>().hasALeftBuddy = true;
		} else {
			newBuddy.GetComponent<Tiling>().hasARightBuddy = true;
		}
	}

	                     

}

Check out the docs. Instantiate called on a component will clone the entire GameObject the component is attached to.

Instantiate creates a new gameobject. But the as Transform at the end of the line casts the result to just get the transform component, and this is assigned to the newBuddy variable, which is also just a Tranform.

GameObjects can have a lot of different components. If you only want to manipulate properties of their transform (i.e. their position, scale etc.), it’s more efficient to maintain a list of only the Transform components rather than the entire gameobject.