PrefabInputEntity ( instance,input$ )

Parameters

instance - prefab placement

input$ - name of one of its typed entity/component inputs

Description

Returns the entity bound to a prefab input.

Prefab inputs connect a reusable object to things in the scene - a switch prefab wired to the door it opens, say. The result is the borrowed target entity, or 0 for an absent input or a target that has been freed.

Internal targets are remapped by CopyEntity; external targets remain borrowed. Binding alone does not change parenting.

For the full story, see the reusable resources guide, which covers resource formats, ownership, editing and the save workflow.


See also: PrefabInputComponent, PrefabInputsBound, CreatePrefabDocument.

Example

; PrefabInputEntity Example
; -------------------------

; A "tracker" prefab declares an entity input called target and attaches its
; marker cone to whatever the scene binds there - here, a moving ball.
Print "This example writes demo_tracker.prefab and demo_scene.world next to"
Print "itself, and deletes them when you exit. Press Y to continue."
WaitKey
If KeyDown(21)=0 Then End

q$=Chr(34)
prefab$="{'format':'blitz3d.prefab','version':1,'id':'demo.prefab.tracker','assets':[],'definition':{"
prefab=prefab+"'inputs':[{'id':'target','type':'entity','required':true}],"
prefab=prefab+"'entities':[{'id':'root','components':[]},"
prefab=prefab+"{'id':'marker','parent':'root','transform':{'position':[0,1.2,0]},'components':[{'type':'model','primitive':'cone'},{'type':'attachment','target':{'input':'target'}}]}]}}"
WriteTextAtomic "demo_tracker.prefab",Replace(prefab,"'",q)
scene$="{'format':'blitz3d.world','version':1,'assets':[{'id':'tracker','kind':'prefab','source':'demo_tracker.prefab','loading':'required'}],"
scene=scene+"'entities':[{'id':'ball','components':[{'type':'model','primitive':'sphere'}]},"
scene=scene+"{'id':'tracker','components':[{'type':'prefab','asset':'tracker','inputs':{'target':{'entity':'ball'}}}]}]}"
WriteTextAtomic "demo_scene.world",Replace(scene,"'",q)

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

world=LoadWorldAsync("demo_scene.world")
While WorldReady(world)=0
    If WorldLoadState(world)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(world)
    UpdateAsyncLoads 2
Wend
SetWorld world
ball=FindWorldEntity(world,"ball")
tracker=FindWorldEntity(world,"tracker")

camera=CreateCamera()
PositionEntity camera,0,1,-7
light=CreateLight()
RotateEntity light,35,-25,0

While Not KeyDown(1)

    ; Space frees the ball: the borrowed input becomes unbound
    If KeyHit(57) And ball<>0
        FreeEntity ball
        ball=0
    EndIf

    If ball Then PositionEntity ball,Sin(MilliSecs()*0.05)*2,0,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,"Arrow keys: move camera   Space: free the ball   Esc: exit"
    Text 0,20,"PrefabInputEntity(tracker,"+q+"target"+q+") is the ball: "+(PrefabInputEntity(tracker,"target")=ball And ball<>0)
    Text 0,40,"PrefabInputsBound(tracker) = "+PrefabInputsBound(tracker)
    Text 0,60,"PrefabInputComponent(tracker,"+q+"target"+q+") = '"+PrefabInputComponent(tracker,"target")+"'   (no component selector)"
    If ball=0 Then Text 0,80,"The attached cone was parented to the ball, so it went with it"

    Flip

Wend

FreeWorld world
DeleteFile "demo_tracker.prefab"
DeleteFile "demo_scene.world"

End

Index