How it works...

We create the Spawn UFUNCTION and a variable called ActorToSpawn. The ActorToSpawnUPROPERTY is of the TSubclassOf< > type, a template type that allows us to restrict a pointer to either a base class or subclasses thereof. This also means that within the editor, we will get a pre-filtered list of classes to pick from, preventing us from accidentally assigning an invalid value:

Inside the Spawn function's implementation, we get access to our world. From here, we check it for validity.

SpawnActor wants an FTransform* to specify the location to spawn the new actor to, so we create a new stack variable to contain a copy of the current component's transform.

If TheWorld is valid, we request it to spawn an instance of the specified ActorToSpawn subclass, passing in the address of the FTransform we just created, which now contains the desired location for the new actor.