GeneratePrefabInstance

Definition

GeneratePrefabInstance(string prefabName, float XPos, float YPos, float ZPos, float XRot, float YRot, float ZRot, float XScale, float YScale, float ZScale)

Description

This function creates an instance of prefab prefabName and returns its name.

Parameters

prefabName
Specifies the name of the prefab from which you want to create an instance. You can see the names of prefabs through the Script Utility dialog in the script editor (Tools > Script Editor > Tools > Script Utility).

XPos, YPos, ZPos
These three values specify the position of the generated prefab instance.

XRot, YRot, ZRot
These three values specify the rotation of the generated prefab instance.

XScale, YScale, ZScale
These three values specify the scale of the generated prefab instance.

Return Value

Returns the name of the generated prefab instance.

Example

prefab_instance = ""

function OnTriggerEnter(otherActorName)
    prefab_instance = GeneratePrefabInstance("VandaEngine17-SamplePack1_house2", 1.0, 2.0, 3.0, 10.0, 20.0, 30.0, 0.3, 0.5, 0.7)
end

function OnTriggerStay(otherActorName)

end

function OnTriggerExit(otherActorName)
    DeletePrefabInstance(prefab_instance)
end
Let’s assume that this script is attached to a trigger called Trigger1. When the main game character or a dynamic object is entered into Trigger1, the GeneratePrefabInstance function is called and an instance of the prefab “VandaEngine17-SamplePack1_house2” is created at position (1.0, 2.0, 3.0) with rotation (10.0, 20.0, 30.0) and dimensions (0.3, 0.5, 0.7). Then the generated prefab instance name is stored in the prefab_instance variable.
Whenever the character or any other dynamic object exits Trigger1, the DeletePrefabInstance function deletes the generated prefab instance prefab_instance from memory.
adminGeneratePrefabInstance