How does Instantiate() clone an object

Hi,

I searched but couldn’t find any details on how exactly Instantiate() clones an object, specifically when that object has scripts attached to it, and those script have class variables.

So for example:

class test1 : MonoBehaviour {
    public int num;
    public List<int> multiNum;
    public MyClass myObj;
}

now, if I instantiate an object with test1 script attached to it, will it clone the value of num variable? What about multiNum variable? And last, what about myObj which is a class that I created. Will it clone it? If yes, then how does it clone it?

Thanks

It will make a copy of anything the serialization system can normally save so all basic types, all classes marker Serializable, lists and arrays. It will not copy anything else (like Dictionaries etc).

All object references to components within the tree defined as descendants of the object being cloned will be fixed up to point to the copied items.