Chapter 7 – Spawning the followers

Manual spawning

There can be a multitude of ways you could spawn your new followers or squad members. One of them should be using some sort of spawn point. For the simplicity of the tutorial, we will spawn the follower manually around the player at set distance.

To this end we will delve into some predefined function of the GameInfo class. The function SpawnDefaultPawnFor is responsible for creating the default pawn you specify in your default properties in your custom game info class. As we are following the same tutorial, go to your IsometricGameInfo class.

Add the following code :

/**
 * Returns a pawn of the default pawn class
 *
 * @param	NewPlayer - Controller for whom this pawn is spawned
 * @param	StartSpot - PlayerStart at which to spawn pawn
 *
 * @return	pawn
 */
function Pawn SpawnDefaultPawnFor(Controller NewPlayer, NavigationPoint StartSpot)
{
	local Pawn ResultPawn;

	ResultPawn = super.SpawnDefaultPawnFor(NewPlayer, StartSpot);

	`Log("Spawn Info stuff");

	if(ResultPawn != none)
	{
		IsometricGamePlayerController(NewPlayer).PlayerSpawned(StartSpot);
	}

	return ResultPawn;
}

Calling a parent class function

Now what I did here was to call the GameInfo parent class function named SpawnDefaultPawnFor (we want to build on existing code). If we spawned the main pawn and it is valid, we call a new function in our player controller called PlayerSpawned. This will be our callback function when the main pawn is created on the level.

Return to our IsometricGamePlayerController. Add the following variable declaration on top of the file :

var class FollowerPawnClass;
var Pawn        Followers[3];

Add this in the defaultProperties :

...
FollowerPawnClass=class'FollowerPawn'
...

Class definition and real instances (FollowerPawnClass variable)

The FollowerPawnClass will be defined in the defaultProperties section of our current player controller file. This will hold the name of the class to instantiate when we create the pawns (like a blueprint). You could have multiple type of spawned character, I recommend you explore this at some point.

Followers

The Followers variable is an array that will contain our 3 followers instances that will appear and follow us on the map.

Now is the time to add the function that will spawn our minions, add this to the current player controller class :

function PlayerSpawned(NavigationPoint StartLocation)
{
`Log("Follower is alive");
Followers[0] = Spawn(FollowerPawnClass,,, StartLocation.Location - vect(100,100,0), StartLocation.Rotation);
Followers[1] = Spawn(FollowerPawnClass,,, StartLocation.Location - vect(200,100,0), StartLocation.Rotation);
Followers[2] = Spawn(FollowerPawnClass,,, StartLocation.Location - vect(100,200,0), StartLocation.Rotation);
}

Now this function spawn for each entry in the array a simple FollowerPawnClass, I set the base location manually in a triangle with the same rotation as our spawn point.

Compile and run the game

Compile and fire up the game, you should have now a couple of friends on screen, right now they are not rigged to receive commands yet.


chapter 7 – Assign commands to followers

Update me when site is updated
Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Slashdot
  • PDF
  • Twitter
  1. Mark Gossage
    March 12th, 2010 at 02:53 | #1

    Tried this and is failed to compile.
    The
    FollowerPawnClass=class’FollowerPawn’
    should be
    FollowerPawnClass=class’MyIsometricGame.FollowerPawn’
    It seems you need the full class name or it won’t compile.

  2. Hotdot
    March 15th, 2010 at 22:47 | #2

    yes it does it is an error on my part, although this was made with february version, they may have set it to be like that from march release.

  3. Bossa
    April 3rd, 2010 at 11:26 | #3

    The new variables in IsometricGamePlayerController:
    var class FollowerPawnClass;

    the tag disappeared…problem of HTML? LOL

    also there is a global variable and local variable both named as DistanceCheck, also inside IsometricGamePlayerController

  4. Roychr
    April 5th, 2010 at 23:35 | #4

    Bossa are you refering to the source code download ?

  5. Andreas Hesel
    April 8th, 2010 at 09:13 | #5

    @Roychr

    I think the problem Bossa is referring to is the missing class Type definition of:
    var class FollowerPawnClass;
    var Pawn Followers[3];

    the (smaller than and bigger than) signs gets eaten by the HTML compiler somewhere, so if you copy/paste the code directly from the example above, you never get the class difinition, and the FollowerPawnClass “blueprint” doesn’t mean anything to the unreal compiler – that line of code is NOT a compile error. The error will be in the PlayerSpawned function, where the Spawn function will complain with a:
    Type mismatch in Call to ‘Spawn’, parameter 1

    The solution is either to add the Type definition as intended (easy fix) or change the first parameter of the Spawn call to:
    Spawn(class’FollowerPawnClass’…

  6. sjayb2k
    October 10th, 2010 at 16:21 | #6

    @Andreas Hesel
    How would I add in the Type Definition? I am new to UDK and unsure at what this would look like.

  7. Roychr
    October 20th, 2010 at 21:18 | #7

    @sjayb2k

    Type definition is the class type that goes in front of a variable like :

    var int myvarname where int is the type definition here.

  1. February 23rd, 2010 at 17:12 | #1
  2. September 12th, 2011 at 19:31 | #2
You must be logged in to post a comment.