Construct 3 icon

Construct 3

Documentation

Object class script interface

Ashley's avatar
Medal
Construct Team Founder
Published 28 May, 2019
281 words
~1-2 mins

The IObjectClass script interface represents an object class in the project, e.g. a Sprite object type. An ObjectClass can have multiple instances created, which are represented by the IWorldInstance script interface if it appears in a layout, otherwise the IInstance interface.

Object class APIs

name

A read-only string of the object class's name.

setInstanceClass(Class)

Set a custom class to be used to represent instances of this object type. The class must derive from the default class. This can only be called in runOnStartup, before any instances have been created. For more information see the guide on subclassing instances.

getAllInstances()

Return an array of all instances of this object class.

getFirstInstance()

Return the first instance in the array returned by getAllInstances(), or null if no instances exist.

*instances()

Iterates over all the object class's instances.

getPickedInstances()

Return an array of instances that have been picked by the event's conditions. This is only useful with scripts in event sheets.

getFirstPickedInstance()

Return the first instance that has been picked by the event's conditions, or null if none. This is only useful with scripts in event sheets.

*pickedInstances()

Iterates over the instances that have been picked by the event's conditions. This is only useful with scripts in event sheets.

createInstance(layerNameOrIndex, x, y)

Create a new instance of the object type at a position. The layer to create on is specified either by a case-insensitive string of the layer name or its zero-based index. The position is given in layout co-ordinates. Returns an instance class representing the created instance.