transform.parent vs transform.SetParent

I can make target transform to be child of another transform using 2 variants:

1) Go.transform.parent = transform;
2) Go.transform.SetParent(transform);

So i not sure what variant better (in performance perspective).

SetParent allows you keep the transforms local orientation rather than its global orientation (by setting the second parameter worldPositionStays to true). In terms of performance I would imagine this makes
SetParent slightly slower, but the difference would be negligible

See the docs for Transform.parent and for Transform.SetParent, particularly the line :

worldPositionStays - If true, the parent-relative position, scale and rotation is modified such that the object keeps the same world space position, rotation and scale as before.

transform.SetParent is relatively new (I believe sinse Unity UI came out) and exists because it also has an overload with a second boolean argument. And they also made a version which doesn’t have this boolean second argument (which defaults to having the second argument set to true). Setting the property and calling the method with one argument or with the second argument set to true all do exactly the same, but the method has a different behaviour when you call it like this.

Go.transform.SetParent(transform, false);

There really shouldn’t be any (noticeable) performance difference. The method probably has one extra method call because it calls setparent again with the second argument set to true but as I said, it shouldn’t be noticeable.

Transform.setparent: Help set the local position of the gameobject with the help of an argument i.e. worldPositionStays. If true, then the position it is carrying in its transform becomes its global position wrt world.
And if false, then its position is according to its parent behaving like a world. It means the parent position will be taken as the origin for the child object.

parent = gameobject keeps the worldposition of the child while SetParent allows you the choice between world position or changing the position to be relative to the parent. When the object is made a child of a parent in world space the object will stay in the same place it was when nested but the position, rotation, and scale values will still be modified to be relevant to the parent. You can see that in the demonstration here https://www.monkeykidgc.com/2020/12/tips-and-tricks-unity-set-parent.html

Just wanted to add an additional information here.
Unity’s Instantiate() also includes the parameters to assign new parent to the object you’re about to create.

Either one of these two API will create a new game object assign to the target parent transformation.

Instantiate( prefabTemplate, parent.transform );
Instantiate( prefabTemplate, Vector3.zero, Quaternion.Identity, parent.transform );

Both of these will save the additional cpu cost of applying parent transformation to your newly created game object. SetParent and parent assignment have a significant performance cost when applying transformations.


See below for more information:
Unite Berlin 2018 - Unity’s Evolving Best Practice
Unity Doc’s - Object.Instantiate