Instance

Ashley's avatar
Medal
Construct Team Founder
Published 16 May, 2018
487 words
~2-3 mins

The Instance class represents an object instance in the runtime.

Methods

GetWorldInfo()

For "world" type plugins, get the instance's associated WorldInfo. This allows modification of the position, size, angle etc.

GetRuntime()

Get the Runtime for this instance.

GetSdkInstance()

Get the plugin-specific instance class for this instance, which derives from SDKInstanceBase. See also Addon interfaces for the public APIs exposed by some of the built-in addons in Construct.

GetObjectClass()

Get the ObjectClass representing the object type this instance belongs to.

GetPlugin()

Return the plugin class for this instance, which derives from SDKPluginBase.

BelongsToObjectClass(objectClass)

Returns true if this instance's object class is the given object class, or the given object class is a family and this instance's object class is a member of that family.

GetImagePoint(nameOrIndex)

Get an image point from the instance by either its index or a string of its name. Note image points are returned in a [0,1] range, such that 0.5 represents the middle.

IsInContainer()

Returns true if the instance is in a container.

GetSiblings()

Return a read-only array of sibling instances for this instance, i.e. its associated other instances in its container. This is only applicable if the instance is in a container.

GetUID()

Get the unique identifier (UID) for this instance. UIDs are unique integer numbers assigned to every instance, and never change during the lifetime of the instance.

GetIID()

Get the instance identifier (IID) for this instance. IIDs are the zero-based index of this instance in its object type's instance list. Note IIDs can change during the lifetime of the instance; if an instance with a lower IID is destroyed, all instances with higher IIDs are renumbered so the IIDs are contiguous from 0.

GetBehaviorInstances()

Return a read-only array of BehaviorInstance for this instance.

GetBehaviorInstanceFromCtor(ctor)

Look up a behavior instance by its behavior constructor. For example GetBehaviorInstanceFromCtor(C3.Behaviors.Platform) will return the first BehaviorInstance for the Platform behavior if the instance has one, else null.

GetBehaviorSdkInstanceFromCtor(ctor)

As with GetBehaviorInstanceFromCtor(ctor), but returns the behavior-specific behavior instance class (which derives from SDKBehaviorInstanceBase) instead.

GetInstanceVariableCount()

Return the number of instance variables for this instance.

SetInstanceVariableValue(index, value)

GetInstanceVariableValue(index)

Set or get an instance variable value by its index. Note the type of the instance variable will be preserved.

GetSavedDataMap()

GetUnsavedDataMap()

Return a Map to store additional data to associate with this instance. Use string keys only, and ensure keys are unique. The saved data map is written to savegame files so should be used for persistent state. The unsaved data map is not written to savegame files so should be used for transient storage or caching.