• Functions for controlling factory components which are used to dynamically spawn game objects into the runtime.

Static methods

staticcreate(url:HashOrStringOrUrl, ?position:Vector3, ?rotation:Quaternion, ?properties:Table<String, GoProperty>, ?scale:EitherType<Float, Vector3>):Hash

  • Make a factory create a new game object.

The URL identifies which factory should create the game object. If the game object is created inside of the frame (e.g. from an update callback), the game object will be created instantly, but none of its component will be updated in the same frame.

Properties defined in scripts in the created game object can be overridden through the properties-parameter below.

Calling Factory.create on a factory that is marked as dynamic without having loaded resources using Factory.load will synchronously load and create resources which may affect application performance.

Parameters:

url

the factory that should create a game object.

position

the position of the new game object, the position of the game object calling Factory.create() is used by default, or if the value is nil

rotation

the rotation of the new game object, the rotation of the game object calling Factory.create() is used by default, or if the value is nil.

properties

the properties defined in a script attached to the new game object.

scale

the scale of the new game object (must be greater than 0), the scale of the game object containing the factory is used by default, or if the value is nil

Returns:

the global id of the spawned game object

@:native("get_status")staticgetStatus(?url:Null<HashOrStringOrUrl>):FactoryStatus

  • Get factory status.

This returns status of the factory.

Calling this function when the factory is not marked as dynamic loading always returns FactoryStatus.STATUS_LOADED.

Parameters:

url

the factory component to get status from

Returns:

status of the factory component

@:has_untypedstaticinlineload(?url:Null<HashOrStringOrUrl>, ?completeFunction:(url:Url, result:Bool) ‑> Void):Void

  • Load resources of a factory prototype.

Resources are referenced by the factory component until the existing (parent) collection is destroyed or Factory.unload is called.

Calling this function when the factory is not marked as dynamic loading does nothing.

Parameters:

url

the factory component to load

completeFunction

function to call when resources are loaded.

@:native("set_prototype")staticsetPrototype(url:HashOrStringOrUrl, ?prototype:String):Void

  • Changes the prototype for the factory. This allows the developer to load and spawn an arbitrary .collectionc/.goc file, further simplifying using dynamic content. The .collectionc/.goc files still need to be part of the resource archive.

We’ve added a “Dynamic Prototype” checkbox to the factories. The prototype can only be overridden when this is checked. If set, then the collection component count cannot be optimized, and the owning collection will use the default component counts from game.project.

Setting the prototype to null will revert back to the original prototype.

Parameters:

url

the collection factory component

prototype

the path to the new prototype, or null

staticunload(?url:Null<HashOrStringOrUrl>):Void

This decreases the reference count for each resource loaded with Factory.load. If reference is zero, the resource is destroyed.

Calling this function when the factory is not marked as dynamic loading does nothing.

Parameters:

url

the factory component to unload