Spawning an actor

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.

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++

It is the same thing as World.SpawnActor<Type>(); except when you’re working with pointers you use “Object -> Member” instead of “Object**.**Member”

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 :slight_smile: