Blitz3D+ Command Reference

CreateWorldAsset ( asset[,parent] )

Parameters

asset - a ready model asset handle returned by FindWorldAsset

parent (optional) - parent entity for the new entity; with no parent it is created in the selected world (default)

Description

Creates an ordinary entity from a ready model asset.

This is the spawner for models declared in a .world manifest: preload a pickup, prop, or enemy model once through LoadWorldAsync, then stamp out as many copies as the game needs - each call copies the shared prepared model, so spawning is cheap compared with loading from disk. The result is a completely ordinary entity: position it, texture it, animate it, collide it, and FreeEntity it like anything from LoadMesh.

Without a parent the entity is created in the currently selected world; a parent puts it in that entity's world instead, wherever that is. Either way the new entity is independent of the manifest world it came from and lives on after that world is freed.

The asset must be a model - other kinds have their own accessors (WorldAssetTexture, WorldAssetSound, WorldAssetShader) - and it must be ready, or the call is a runtime error. Check WorldAssetReady first for streaming or manual assets.

For the full story, see the Async World Loading guide and the Building .world Asset Collections guide.

Requires Extended mode.

See also: FindWorldAsset, WorldAssetReady, WorldAssetKind, SetWorld, FreeEntity.

Example

; CreateWorldAsset Example
; ------------------------
; Requires Extended mode.

Graphics3D 640,480,0,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()

camera=CreateCamera()
PositionEntity camera,0,1,-5
light=CreateLight()
RotateEntity light,45,45,0

; Load the asset manifest world in the background
manifest=LoadWorldAsync("../../../samples/worlds/asset-preload.world")
While Not WorldReady(manifest)
    If WorldLoadState(manifest)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(manifest)
    Cls
    Text 0,0,"Loading the asset manifest..."
    Flip
Wend

; The manifest's model asset is ready along with its world
model_asset=FindWorldAsset(manifest,"display-model")

; CreateWorldAsset instantiates an ordinary entity from the model asset
pickup=CreateWorldAsset(model_asset)
PositionEntity pickup,0,1,0
count=1

While Not KeyDown(1)

    ; Space spawns another pickup from the same asset
    If KeyHit(57)
        item=CreateWorldAsset(model_asset)
        PositionEntity item,Rnd(-4,4),Rnd(0,2),Rnd(0,4)
        TurnEntity item,Rnd(360),Rnd(360),0
        count=count+1
    EndIf

    TurnEntity pickup,0,1,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Space: spawn another pickup   Arrow keys: move camera   Esc: exit"
    Text 0,20,"CreateWorldAsset instances made from one model asset: "+count

    Flip

Wend

FreeWorld manifest
End

Index