envenger
(envenger)
April 21, 2014, 4:36am
1
From the First Person code, A projectile is spawned using
UWorld* const World = GetWorld();
if (World != NULL)
{
// spawn the projectile at the muzzle
World->SpawnActor<AMyProjectProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);
}
I am weak on pointers so I exactly can’t figure out how this works.
And what the World-> does here
MyObject->FunctionOfMyObject() calls “FunctionOfMyObject” function of an object that “MyObject” pointer points to.
envenger
(envenger)
April 21, 2014, 8:16am
3
Ok understand…
So what will
World->SpawnActor<AMyProjectProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);
do?
It spawns an actor of AMyProjectProjectile class but why is World-> given before it?
Because SpawnActor() function is a member of World.
Or more accurately: SpawnActor() is a member of UWorld class and World is a pointer to an instance of that class.
You should probably do a bit of reading about c++
zeOrb
(zeOrb)
April 21, 2014, 8:51am
5
Ok understand…
So what will
World->SpawnActor<AMyProjectProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);
do?
It spawns an actor of AMyProjectProjectile class but why is World-> given before it?
It is the same thing as World.SpawnActor<Type>(); except when you’re working with pointers you use “Object -> Member” instead of “Object**.**Member”
envenger
(envenger)
April 21, 2014, 12:59pm
6
Because SpawnActor() function is a member of World.
Or more accurately: SpawnActor() is a member of UWorld class and World is a pointer to an instance of that class.
You should probably do a bit of reading about c++
Ok thanks… I understood how pointers work in c++. I knew to deference a pointer with * but didn’t knew with ->
I understood now.
Thanks