Howdy!
I have been delving in the low level workings of the Engine for educational purposes. Specifically I am interested in the process of UWorld:SpawnActor
. I can follow the C++ code till here
// actually make the actor object
AActor* const Actor = NewObject<AActor>(LevelToSpawnIn, Class, NewActorName, ActorFlags, Template, false/*bCopyTransientsFromClassDefaults*/, nullptr/*InInstanceGraph*/, ExternalPackage);
The function NewObject
basically returns a static_cast of UObject
like so
return static_cast<T*>(StaticConstructObject_Internal(Params));
UObject
is an object, if I understand right, which has been initialised by placement new operator, which, in turn, calls the constructor of UObjectBase
like so
new ((void *)Obj) UObjectBase(const_cast<UClass*>(InClass), InFlags|RF_NeedInitialization, InternalSetFlags, InOuter, InName, OldIndex, OldSerialNumber);
Seems alright and makes sense to me till here.
I am wondering where is the placement new written for the actual AActor
that we are spawning without which there won’t be any constructor call of AActor
class and consequently no vtable, rendering virtual functions of the AActor
class useless, to name a issue I can fathom.
Thanks for reading,
The-Cowboy