SpawnSphere

consoledoc.h

This class is used for creating any type of game object, assigning it a class, datablock, and other properties when it is spawned.

More...

Spawn

string

Object class to create (eg. Player, AIPlayer, Debris etc)

string

Predefined datablock assigned to the object when created.

string

String containing semicolon (;) delimited properties to set when the object is created.

string

Command to execute immediately after spawning an object. New object id is stored in $SpawnObject. Max 255 characters.

bool

Flag to spawn object as soon as SpawnSphere is created, true to enable or false to disable.

bool

Flag to set the spawned object's transform to the SpawnSphere's transform.

Dimensions

float

Deprecated.

Weight

float

Deprecated.

float

Deprecated.

float

Deprecated.

Callbacks

void
onAdd(uint objectId)

Called when the SpawnSphere is being created.

Public Static Attributes

bool

Disables rendering of all instances of this type.

bool

Disables selection of all instances of this type.

Public Functions

bool
spawnObject(string additionalProps)

Dynamically create a new game object with a specified class, datablock, and optional properties.

Detailed Description

This class is used for creating any type of game object, assigning it a class, datablock, and other properties when it is spawned.

Torque 3D uses a simple spawn system, which can be easily modified to spawn any kind of object (of any class). Each new level already contains at least one SpawnSphere, which is represented by a green octahedron in stock Torque 3D. The spawnClass field determines the object type, such as Player, AIPlayer, etc. The spawnDataBlock field applies the pre-defined datablock to each spawned object instance. The really powerful feature of this class is provided by the spawnScript field which allows you to define a simple script (multiple lines) that will be executed once the object has been spawned.

// Define an SpawnSphere that essentially performs the following each time an object is spawned
//$SpawnObject = new Player()
//{
//   dataBlock = "DefaultPlayerData";
//   name = "Bob";
//   lifeTotal = 3;
//};
//echo("Spawned a Player: " @ $SpawnObject);

new SpawnSphere(DefaultSpawnSphere)
{
   spawnClass = "Player";
   spawnDatablock = "DefaultPlayerData";
   spawnScript = "echo(\"Spawned a Player: \" @ $SpawnObject);"; // embedded quotes must be escaped with \ 
   spawnProperties = "name = \"Bob\";lifeTotal = 3;"; // embedded quotes must be escaped with \ 
   autoSpawn = "1";
   dataBlock = "SpawnSphereMarker";
   position = "-0.77266 -19.882 17.8153";
   rotation = "1 0 0 0";
   scale = "1 1 1";
   canSave = "1";
   canSaveDynamicFields = "1";
};

// Because autoSpawn is set to true in the above example, the following lines
// of code will execute AFTER the Player object has been spawned.
echo("Object Spawned");
echo("Hello World");

Spawn

string spawnClass 

Object class to create (eg. Player, AIPlayer, Debris etc)

string spawnDatablock 

Predefined datablock assigned to the object when created.

string spawnProperties 

String containing semicolon (;) delimited properties to set when the object is created.

string spawnScript 

Command to execute immediately after spawning an object. New object id is stored in $SpawnObject. Max 255 characters.

bool autoSpawn 

Flag to spawn object as soon as SpawnSphere is created, true to enable or false to disable.

bool spawnTransform 

Flag to set the spawned object's transform to the SpawnSphere's transform.

Dimensions

float radius 

Deprecated.

Weight

float sphereWeight 

Deprecated.

float indoorWeight 

Deprecated.

float outdoorWeight 

Deprecated.

Callbacks

onAdd(uint objectId)

Called when the SpawnSphere is being created.

Parameters:

objectId

The unique SimObjectId generated when SpawnSphere is created (%this in script)

Public Static Attributes

bool isRenderable 

Disables rendering of all instances of this type.

bool isSelectable 

Disables selection of all instances of this type.

Public Functions

spawnObject(string additionalProps)

Dynamically create a new game object with a specified class, datablock, and optional properties.

This is called on the actual SpawnSphere, not to be confused with the Sim::spawnObject() global function

Parameters:

additionalProps

Optional set of semiconlon delimited parameters applied to the spawn object during creation.

// Use the SpawnSphere::spawnObject function to create a game object
// No additional properties assigned
%player = DefaultSpawnSphere.spawnObject();