User Tools

Site Tools


annotations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
annotations [2021/12/09 10:44] maximeannotations [2021/12/10 11:33] maxime
Line 27: Line 27:
  }  }
 }) })
 +</code>
 +
 +=== Lazy-init ===
 +
 +By default, components are always initialized (call of ''init'' function) right after being created. For components flagged as //lazy-init// though, if the component is disabled on creation, the initialization is delayed until the component is enabled for the first time.
 +
 +<code lua>
 +local standardComp = nil
 +local lazyInitComp = nil
 +
 +level:createObject(function(_newObject)
 +    standardComp = _newObject:addComponent("STANDARD_COMPONENT")
 +    standardComp:setEnabled(false)
 +    
 +    lazyInitComp = _newObject:addComponent("LAZY_INIT_COMPONENT")
 +    lazyInitComp:setEnabled(false)
 +end)
 +-- at the end of createObject, only standardComp is initialized because it is disabled, but not lazy-init
 +
 +-- when enabling lazyInitComp, since it's enabled for the first time, it is initialized at the same time
 +lazyInitComp:setEnabled(true)
 </code> </code>
  
annotations.txt · Last modified: 2022/08/16 10:56 by maxime

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki