Background for Starfield
Member of the ScriptObject script
eventOnInit()

[DEV SERVER] Loading description...


Caveats

CK Wiki - Notes

  • Until OnInit has finished running, your script will not receive any events, and other scripts that try to call functions or access properties on your script will be paused until the event finishes. The only exceptions are when the functions are being called from another script inside its OnInit event, or inside a property set function being set by the master file.

    • Because of this, do not set stages in the OnInit event, or in any function called by OnInit, as it can result in a deadlock.
  • OnInit is called at the following times:

    • For Quests and Aliases: On game startup, and again whenever a repeatable quest starts, due to the quest being reset.
    • For other base objects like Topic Infos, Perks, etc that have scripts that run on the base object: At game start
    • For persistent refs: At game start
    • For non-persistent refs: When the ref comes into existence for the first time (not when 3d is loaded)
  • OnInit is called again when an object is reset. All your variables and properties will be reset before OnInit is called.

    • For Quests and Aliases this will happen when your quest starts, if it is repeatable. This means that a quest and alias will see OnInit twice before it starts the first time (game startup, and on reset). This should not cause any problems unless you are manipulating something outside the quest that doesn't reset in your OnInit.
    • For references this happens when the cell resets.

Examples

; This is within the "empty" state
EVENT onInit()                  ; This event will run once, when the script is initialized
    StartTimer(5)
    gotoState ("waiting")
endEVENT
    
 STATE waiting
    EVENT onTimer(int aiTimerID)            
        Debug.Trace("5 second timer expired!")
    endEVENT
endSTATE

Auto-Generated Example

Scriptname MyCoolScript extends ScriptObject

event OnInit()
    Debug.trace("Event received - OnInit")
endEvent

Related Pages

None


Additional References

View this event’s page on the Fallout 4 Creation Kit Wiki

Some data provided by the Fallout 4 Creation Kit Wiki. Licensed under the Creative Commons Attribution-Share Alike 4.0 license.