DeletePrefabInstance

Definition

DeletePrefabInstance(string prefabInstanceName)

Description

Removes the prefab instance prefabInstanceName from memory.

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

function Init()
    DeletePrefabInstance("1_VandaEngine17-SamplePack1_stab")
end

function Update()

end
In this script, we remove the prefab instance “1_VandaEngine17-SamplePack1_stab” from memory.

Example 2

--Name of script is DeletePrefabInstance2.lua

timer = 0.0

function Init()

end

function Update()
    timer = timer + GetElapsedTime()
    if timer > 3.0 then DeletePrefabInstance("this"end
end
If, in the Prefab Editor, you attach DeletePrefabInstance2.lua script to a Prefab, then “this” parameter in the DeletePrefabInstance 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 DeletePrefabInstance function refers to the name instance1_a.
In this script, we add the elapsed time to the timer variable. If the timer value is greater than 3 seconds, we delete the current prefab instance, which in our example has the name instance1_a, from the memory.
adminDeletePrefabInstance