SDKBehaviorInstance interface
Addon SDK v1 retirement
The SDKBehaviorInstance
interface is used as the base class for runtime behavior instances in the SDK. When a behavior is added to an object type, each of its object instances has a behavior instance created and associated with it.
SDKBehaviorInstance
cannot be directly constructed; it should only be used as a base class.
Properties
- this._behInst
- Reference to the BehaviorInstance representing this behavior instance in the runtime. This allows access to Construct's built-in runtime features for behavior instances.
- this._inst
- Reference to the Instance representing the associated instance in the runtime. This is the object instance that the behavior can control.
- this._runtime
- Reference to the associated Runtime that controls execution of the project.
- this._behaviorType
- Reference to the BehaviorType representing the behavior type that this instance belongs to.
- this._sdkType
- Reference to your addon's SDK behavior type class, which derives from SDKBehaviorTypeBase.
Methods
- Release()
- Optional override for when a behavior instance is released.
- GetBehaviorInstance()
- Returns
this._behInst
publicly.
- GetObjectInstance()
- Returns
this._inst
publicly.
- GetWorldInfo()
- Returns
this._inst.GetWorldInfo()
, i.e. the WorldInfo for the associated object instance. Note this is only applicable when added to "world" type plugins, otherwise it returns null
.
- GetRuntime()
- Returns
this._runtime
publicly.
- GetObjectClass()
- Returns
this._objectClass
publicly.
- GetBehaviorType()
- Returns
this._behaviorType
publicly.
- GetSdkType()
- Returns
this._sdkType
publicly.
- GetBehavior()
- Returns your addon's SDK behavior class, which derives from SDKBehaviorBase.
- PostCreate()
- Optional override called after the associated object instance has finished being created. This is useful since the behavior instance constructor is called during instance creation, so the final state is not ready yet.
- Trigger(method)
- Fire a trigger condition. The condition must be declared as a trigger in aces.json. Pass a full reference to the condition method, e.g.
this.Trigger(C3.Behaviors.Bullet.Cnds.OnStep)
.
- _StartTicking()
- _StartTicking2()
- _StartPostTicking()
- IsTicking()
- IsTicking2()
- IsPostTicking()
- _StopTicking()
- _StopTicking2()
- _StopPostTicking()
- Utility methods to start or stop the runtime calling the
Tick()
, Tick2()
or PostTick()
methods of your instance every tick, and also to check whether ticking is active. It is recommended to stop ticking whenever the tick method is no longer needed to reduce the performance overhead of ticking. Redundant calls to start or stop ticking are ignored. The first call always takes effect (i.e. calls do not stack - if you make 3 calls to start ticking then 1 call to stop ticking, ticking is stopped).
- Tick()
- Optional override that is called every tick just before events are run after
_StartTicking()
has been called.
- Tick2()
- Optional override that is called every tick just after events are run after
_StartTicking2()
has been called.
- PostTick()
- Optional override that is called every tick just after all other behaviors have had their
Tick()
methods called. This allows behaviors to observe the state applied by other behavior's ticking. Note you should use Tick()
rather than PostTick()
where possible, since it is not possible to reliably observe the state applied by other behavior's post-ticking.
- GetDebuggerProperties()
- Override to return properties to display in the debugger. For more information see runtime scripts.
- SaveToJson()
- Optional override to return a JSON object that represents the state of the instance for savegames.
- LoadFromJson(o)
- Optional override accepting a JSON object returned by a prior call to
SaveToJson()
that represents the state of an instance to load, for savegames.
- CallAction(actMethod, ...args)
- Convenience method to run an action method with the given parameters. For example:
this.CallAction(C3.Behaviors.MyAddon.Acts.MyAction, "foo", "bar")
- CallExpression(expMethod, ...args)
- Convenience method to run an expression method with the given parameters. Returns the value returned by the expression. For example:
const value = this.CallExpression(C3.Behaviors.MyAddon.Exps.MyExpression)
- GetScriptInterfaceClass()
- Return a custom class to instantiate for the script interface in Construct's scripting feature. See the SDK downloads for sample usage of a custom script interface.
- GetScriptInterface()
- Return the actual script interface used for this behavior instance in Construct's scripting feature. This is an IBehaviorInstance or derivative.
- DispatchScriptEvent(name, cancelable, additionalProperties)
- Fire an event on the script interface for the behavior instance (as with
dispatchEvent()
on the script interface). name
is a string of the event name. cancelable
is a boolean indicating if the event can be stopped with preventDefault()
. The event object will have the default properties as described in Behavior instance event in the scripting reference. Additional properties can optionally be set by passing an object for additionalProperties
whose properties will be added to the event object. For example: DispatchScriptEvent("myevent", false, { extraProperty: 5 })
Addon SDK Manual
Construct.net
2018-05-15
2024-05-20
You are here:
Search this manual:
This manual entry was last updated on 20 May, 2024 at 15:13