The previous article mainly recorded the creation of Uclass, now summarizes the creation of uobject, can be understood from a few different angles.
From the way, you can divide the classes according to the Uobject constructor:
// constructors. uobject (); Const uobject& SRC); Uobject (Enativeconstructor, uclassconstconst tchar* Inpackagename, Eobjectflags inflags); Const Const tchar* Inpackagename, Eobjectflags inflags);
2 is the copy constructor is not related to the initial creation, 3 basic has not seen (from the comment should be dynamic link is useful, and 4 effect similar), the most important is 1 and 42 kinds.
4 is the base class constructor called by Uclass this special subclass at construction time, where Inname is the class name.
1 is the default constructor, usually in Uobject::staticconstructobject (), that is, the dynamic creation of a class of objects when called, used to make an empty object, can say that the other uobject subclasses, the basic is created in this way.
For 1, there are several calling contexts:
The first is to come out directly in new tclass, such as :
New (Inouter, FName (*inname, Fname_add, TRUE), rf_public) Upackage;
The second is created dynamically with Uobject::staticconstructobject, which first staticallocateobject allocates memory and then initializes it by Internalconstructor on the object address returned by the former:
//Allocate the object.uobject* Result =Staticallocateobject (Inclass, Inouter, Inname, Inflags, Intemplate, Error, NULL, Subobjectroot, instancegraph); if(Result) {{Tguardvalue<UBOOL> Isaffectingcdo (Gisaffectingclassdefaultobject, (inflags&rf_classdefaultobject)! =0); //Call the base Uobject class constructor if the class was misaligned (i.e. a native class that's currently being recom Piled) if( ! Inclass->ismisaligned ()) { (*inclass->classconstructor) (Result); } Else { (*uobject::staticclass ()classconstructor) (Result); } }
Where Inclass->classconstructor is a property in Uclass, it points to the Internalconstructor function in the class it represents, and there is a function in each class that is mentioned in the previous article declare_ Defined in the Class macro:
Static void void* x) New((einternal*) x) Tclass; }
For example, when you want to create a class object, you usually get its uclass first, and then call Spawnactor to create it. In the game logic core class Gameinfo:
Unreal3 Object Management Module Analysis two