Transform

Learning Scripting: Transform

In the 2D Gameplay tutorial in the javascript file LevelAttributes.js:

    .
function Start () {
	createdBoundaries = new GameObject ("Created Boundaries");
	createdBoundaries.transform.parent = transform;
        ...
}
    .

What is happening with “createdBoundaries.transform.parent = transform;” ?

I assume the owner of the left expression is LevelAtrributes. Conversely this makes the GameObject createdBoundaries the child of LevelAttributes.

Could someone please explain what is transform on OOP terms and its type.

MageArt hacking Unity…:sunglasses:

A Transform object:

This is in response to pakfront.

Thanks for the reference but I am aware of this. What I am looking for is a more in depth of what is going on in the above declaration. Especially in shop talk in OOP.

MageArt hacking Unity…

Correct…well, the child of the GameObject that LevelAttributes is attached to, to be precise.

Writing “transform” is a shortcut for writing GetComponent(Transform).

–Eric

This is in response to Eric:

Is there documentation on shortcuts? What is the GameObject TYPE?

MageArt hacking Unity…:sunglasses:

Yes, it’s all in the doc links I posted.
Also, check this out:
http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Components.html

This is in response to pakfront:

To further my understanding of shortcuts, I took a portion from the scripting documentation as shown below:

The call GetComponent() returns a component attached to the GameObject that returns the contents of the variable in this case the variable transform.

So instead of using GetComponent(), I can use the “shortcuts” or the simple member variables… Interesting!?

Finally the transform variable is an instantiation of the class Transform of some type (class) which I do not yet know the type… I’ll let this one go for now.

My understanding: When writing a script lets say, where the script is embedded in a Game Object, then the transform variable, the instantiated variable, owned by the Game Object is the same as used in the example LevelAttributes.js file.

MageArt hacking Unity…:sunglasses:

Last important question:

Is there a way to output all the instantiated variables (lets say to the console) of a Game Object?

MageArt hacking Unity…

Hmm, you’re losing me here. Its type is Transform. Its class is Transform. Unless you mean something different?

You’d think so, and so would I, but from what I’ve read it’s actually the other way around. .transform is a property which calls GetComponent(). In practice, not a much different.

Debug.Log(gameObject.transform);
or the equivalent
Debug.Log(transform);

BTW, if you are coming from C++, you might find C# a bit easier to work with than JS/UnityScript. Worth a look anyway.

In response to pakfront:

The type is the contents of the variable transform of the class Transform. The reason why I ask is that I worry about type checking.

Simple types: integer, string…
Class types: Transform → transform → ???

pakfront: Are you an employee at UNITY? If so, could we have a new section besides scripting where this could be titled as “Unity debugging practices”. The reason why I am requesting this is because I cannot find much on debugging Unity.

Thanks for the other info…

MageArt hacking Unity…:sunglasses:

“transform” is a field on the GameObject and Component classes that is of the type Transform. Like this:

//C#
public class GameObject
{
	public Transform transform;
}

//UnityScript
class GameObject
{
	var transform : Transform;
}

The scripting board is fine; the vast majority of threads on the scripting board are already for debugging.

And honestly, there isn’t much to debugging Unity; it’s just general debugging skills you’d develop in any programming language and environment. And like all debugging, it’s imperative that you have some knowledge of the library/environment you are debugging for.

What might be worthwhile though is having some sticky/guide with explanations/fixes for some of the most common errors. If only to save some of us our sanity.

In response to FizixMan:

Thanks for the info… My background is C++ so I’ll be using C# mainly because of their similarities.

I agree but the unity documentation is lacking some what but the tutorials are helping in addition to the documentation. When I do not understand the coding and the documentation, I’ll post here at the forum to further help me… This is my sticky…

MageArt hacking Unity…