material_modify_control

From Valve Developer Community
Jump to navigation Jump to search

material_modify_control is a logical entity available in all Source Source games. It is used to modify arbitrary material properties in response to I/O events. For the entity to work, its target material must have the MaterialModify or MaterialModifyAnimated proxy installed.

C++ Class hierarchy
CMaterialModifyControl
↳CBaseEntity
C++ MaterialModifyControl.cpp

Does similar things to the env_texturetoggle entity, which can set the frame index for a given target entity. Unlike env_texturetoggle, however, this entity targets via parent hierarchy (not targetname).

Icon-Important.pngImportant: Only becomes active after triggering SetMaterialVar for the first time. The parent must be set before calling the input in order for this to work properly.

The target of this entity is its parent (a missing parent targets the worldbrush instead). In the case of there being multiple material_modify_control entities targetting an entity/worldbrush, only the lowest-ID (first created in Hammer) applies. Every frame, each targetted instance of your material tries to retrieve a fresh copy of the parameter value that's currently stored in its childed material_modify_control entity.

Icon-Important.pngImportant: Material properties are stored per-material, not entity. If global material changes are not desired, then multiple material_modify_control entities need to be employed: one per entity/worldbrush containing the material.
Icon-Bug.pngBug: Having multiple material_modify_control. on different entities, but changing the same material, seems to still affect it globally   (tested in: Day of Defeat: Source)
Icon-Bug.pngBug:The "lowest-ID" stipulation is not filtered by materialName/materialVar. This makes it impossible to manipulate more than one material property on the same material simultaneously. This also severely limits the ability to manipulate material properties on the worldbrush (only one material can be controlled on it at a time) (tested in: Source SDK Base 2013 - Multiplayer)
PlacementTip.pngWorkaround: If you're fine with having only one target material per model/worldbrush, you can overload a single property with multiple values by sending them packed together as a Vector string (see Material_proxies#Variables).
PlacementTip.pngWorkaround: If you need to target more than one material per entity/worldbrush and are fine with globally applying each material property, then simply kill each controller in-place after the value is set (one at a time, in lowest-ID order). Note: you must wait 1-2 ticks after calling SetMaterialVar before Kill or else the property will not consistently apply.

Keyvalues

Name (targetname) <string>
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also: Generic Keyvalues, Inputs and Outputs available to all entities
Material to modify (materialName) <material>
Path to the VMT file you want to modify, relative to materials/ folder. Omit .vmt suffix.
Icon-Bug.pngBug:Does not work if the VMT is just in materials/. Should be in a subfolder, like materials/effects/ for example.  [todo tested in ?]
Icon-Important.pngImportant: When a material has a $envmap with env_cubemap as the value, this entity will appear to not work for that material. This is because VBSP will patch the original material and give it a different name that corresponds to the position of the closest cubemap to the brush face that has that material. This happens for every occurrence of the material. In order to make it work, you can replace the env_cubemap in your material with the path to the generated image of the closest cubemap. For example: env_cubemap "maps/yourmap/c124_28_-60". This means, however, that you will have to do it for every occurrence of the material you want to change, especially when you want them to use different cubemap images. This will make it so that VBSP will not try to patch the material and thus leave the original name. Another way is to just to directly specify the patched material name that is generated by VBSP, which you can find after unpacking the map file.
Material variable to modify (materialVar) <string>
Name of the shader parameter you want to modify. Include the $ symbol like how they are written in the VMT.
Warning.pngWarning: In Left 4 Dead 2 when using VScript don't modify m_szMaterialName and m_szMaterialVar using NetProps.SetPropString. It won't work properly because of the way it's stored[Confirm]. Using AddOutputs or Set* inputs of this entity is required. The same applies to using NetProps.GetPropString which won't give you expected results.

Inputs

SetMaterialVar <stringRedirectInput/string>
Sets the chosen material parameter to the specified value.
Warning.pngWarning: At least in Source 2013, it doesn't convert given values to strings, so it can't accept inputs from entities which output anything else than string, math_counter or math_colorblend for example.
Todo: Confirm in other games/engines and find workaround.
SetMaterialVarToCurrentTime
This sets the material variable to the current time on the server.
StartAnimSequence <stringRedirectInput/string>
Force an animated material with the MaterialModifyAnimated proxy to play a set of animation frames.
Format is: <Frame Start> <Frame End> <Frame Rate> <Loop>
<Loop> should be 1 or 0.
Tip.pngTip: Setting "Frame End" to -1 uses the last frame of the texture.
Icon-Bug.pngBug:The second last frame will play after the last frame when not looped.  (tested in: Counter-Strike: Source)
Icon-Bug.pngBug:Using -1 will cause a random texture in the map to display as the last frame before it resets to the first frame.  (tested in: Counter-Strike: Source)
Warning.pngWarning: This input will crash the game if the material has a MaterialModify proxy.
StartFloatLerp <stringRedirectInput/string>
Force a material with the MaterialModifyAnimated proxy to linearly interpolate a material var between two floating point values.
Format is: <Start Value> <End Value> <Transition Time> <Loop>
<Loop> should be 1 or 0.
Note.pngNote: On an animated texture both the MaterialModify and MaterialModifyAnimated proxies need to be present for this input to work.
Note.pngNote: This sets a single value so this can't for example set one translation axis in $basetexturetransform. (Is there a workaround?)
Icon-Bug.pngBug:StartFloatLerp will never loop.  (tested in: Counter-Strike: Source)