IsPrefabInstanceMaterialEnabled

Definition

bool IsPrefabInstanceMaterialEnabled(string prefabInstanceName)

Description

This function determines whether the material of prefab instance prefabInstanceName is enabled or not.

Parameters

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

Return Value

If material of prefab instance prefabInstanceName is enabled, it returns true, otherwise it returns false.

Example 1

enabled = false
message = ""

function Init()
    enabled = IsPrefabInstanceMaterialEnabled("1_VandaEngine17-SamplePack1_wood_pile")

    if enabled then
          message = string.format("\nPrefab instance material is enabled")
    else
          message = string.format("\nPrefab instance material is disabled")
    end

    PrintConsole(message)
end

function Update()

end
First, we determines whether the material of prefab instance “1_VandaEngine17-SamplePack1_wood_pile” is enabled or not. Then we display its result in the console using the PrintConsole function.

Example 2

--Name of script is IsPrefabInstanceMaterialEnabled2.lua

enabled = false
message = ""

function Init()
    enabled = IsPrefabInstanceMaterialEnabled("this")

    if enabled then
          message = string.format("\nPrefab instance material is enabled")
    else
          message = string.format("\nPrefab instance material is disabled")
    end

    PrintConsole(message)
end

function Update()

end
If, in the Prefab Editor, you attach IsPrefabInstanceMaterialEnabled2.lua script to a Prefab, then “this” parameter in the IsPrefabInstanceMaterialEnabled 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 IsPrefabInstanceMaterialEnabled function refers to the name instance1_a.
In our example, the function IsPrefabInstanceMaterialEnabled determines whether the material of current prefab instance, which is prefab instance “instance1_a“, is enabled or not. then we display its result in the console using the PrintConsole function.
adminIsPrefabInstanceMaterialEnabled