Prop.setAlbedo 8
Swaps the albedo texture of the prop's designated material: made for "generic" props like the waving flag, whose prefab carries a PropAlbedoSwap component saying which material to retexture. Works on props spawned with er2.createProp (call it in the onSpawned callback) and on props placed in the mission editor with a script (the texture is re-applied automatically when a streamed prop comes back into view).Pass nil to restore the material's original albedo.Local only: in multiplayer every client must call it on its own prop. The usual pattern is a script started with er2.runEveryone, where each client spawns and textures its own local copy with identical values.
Return value
| Return Type | Description |
|---|---|
| bool | True if the texture was applied (or stored for a streamed prop's next instance). False if the texture handle is invalid or the prop's prefab has no PropAlbedoSwap component. |
Parameters
| Parameter | Type | Description |
|---|---|---|
| 1 | Texture | A handle from er2.loadTexture or er2.getFactionFlag. Nil restores the original albedo. |
Examples
Texture a generic flag prop (texture API)
-- Textures are handles: load one once and pass it around. The same
-- prop works with a faction flag or any image from the mission folder.
local flagTex = er2.getFactionFlag("UnitedStates_allies")
-- local flagTex = er2.loadTexture("flags/my_banner.png")
er2.createProp("FlagWaving_1", vec3(100.0, 25.0, 200.0), vec3(0, 90, 0), false,
function(prop)
prop:setAlbedo(flagTex)
end)
-- In a prop script placed in the mission editor the prop is "myself",
-- and the texture is re-applied automatically when it streams back in:
-- myself:setAlbedo(er2.getFactionFlag("Germany_axis"))Custom banner from the mission folder (texture API)
-- Script assigned to the flag prop in the mission editor: "myself" is
-- this prop. Ship the image with the mission (subfolders are fine).
local bannerTex = er2.loadTexture("flags/clan_banner.png")
if bannerTex == nil then
er2.print("banner image missing!")
return
end
-- the texture sticks: it is re-applied automatically every time the
-- streamed prop comes back into view
myself:setAlbedo(bannerTex)