ShowPrefabInstance

Definition

ShowPrefabInstance(string prefabInstanceName)

Description

This function shows the prefab instance prefabInstanceName. To view the name of prefab instances, open the VScene and click on the desired Prefab Instance in the “Prefabs and GUIs” section and press the Edit button. You can also access the names of prefab instances from the Script Utility section of the script editor ( Tools > Script Editor > Tools > Script Utility). In the dialog that appears, you can view and copy the name of the prefab instance.

Parameters

prefabInstanceName
Specifies the name of the prefab instance. You can also use the name “this” for this parameter. In this case, “this” refers to the prefab instance that this script is attached to.

Example 1

timer = 0.0
shown = false

function Init()
    HidePrefabInstance("1_VandaEngine17-SamplePack1_eggbox")
end

function Update()
    timer = timer + GetElapsedTime()
    if timer >= 5.0 and not shown then
          ShowPrefabInstance("1_VandaEngine17-SamplePack1_eggbox")
          shown = true
    end
end
Assume that this script is attached to a game object such as main character. First, we hide the prefab instance “1_VandaEngine17-SamplePack1_eggbox”. After 5.0 seconds, ShowPrefabInstance function will show“1_VandaEngine17-SamplePack1_eggbox” prefab instance.

Example 2

--name of the script is ShowPrefabInstance2.lua

function Init()
    ShowPrefabInstance("this")
end

function Update()

end
If, in the Prefab Editor, you attach ShowPrefabInstance2.lua script to a Prefab, then “this” parameter in the ShowPrefabInstance function will point to instances of that Prefab in current VScene. For example, if you have an Instance named instance1_a from a Prefab named to which this script is attached, “this” in ShowPrefabInstance function refers to the name instance1_a.
In this example, assume that this script is attached to a prefab named prefab_and we have an instance of it named instance1_prefab_a and instance1_prefab_a is hidden at the beginning of the game. In this case, this script shows current prefab instance, which is instance1_prefab_a.
adminShowPrefabInstance