Skip to content

Commit

Permalink
Fix #143: don't call renderer.material at load time
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Sep 12, 2024
1 parent e59773a commit 7c4f3ab
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions RasterPropMonitor/Auxiliary modules/JSICallbackAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,9 @@ public void Load(ConfigNode node, InternalProp thisProp)
activeColorName = node.GetValue("activeColor");
}
string coloredObjectName = node.GetValue("coloredObject");
Renderer colorShiftRenderer = thisProp.FindModelComponent<Renderer>(coloredObjectName);
if (colorShiftRenderer != null)
controlledTransform = thisProp.FindModelComponent<Renderer>(coloredObjectName)?.transform;
if (controlledTransform != null)
{
affectedMaterial = colorShiftRenderer.isPartOfStaticBatch ? colorShiftRenderer.sharedMaterial : colorShiftRenderer.material;
affectedMaterial.SetColor(colorName, passiveColor);
mode = Mode.Color;
}
else
Expand Down Expand Up @@ -440,7 +438,7 @@ public void Load(ConfigNode node, InternalProp thisProp)
}
else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureShiftStart") && node.HasValue("textureShiftEnd"))
{
affectedMaterial = JUtil.FindPropTransform(thisProp, node.GetValue("controlledTransform").Trim()).GetComponent<Renderer>().material;
controlledTransform = JUtil.FindPropTransform(thisProp, node.GetValue("controlledTransform").Trim());
var textureLayers = node.GetValue("textureLayers").Split(',');
for (int i = 0; i < textureLayers.Length; ++i)
{
Expand All @@ -461,7 +459,7 @@ public void Load(ConfigNode node, InternalProp thisProp)
}
else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureScaleStart") && node.HasValue("textureScaleEnd"))
{
affectedMaterial = JUtil.FindPropTransform(thisProp, node.GetValue("controlledTransform").Trim()).GetComponent<Renderer>().material;
controlledTransform = JUtil.FindPropTransform(thisProp, node.GetValue("controlledTransform").Trim());
var textureLayers = node.GetValue("textureLayers").Split(',');
for (int i = 0; i < textureLayers.Length; ++i)
{
Expand Down Expand Up @@ -504,6 +502,14 @@ public void OnStart(InternalProp thisProp, string variableName)
GameEvents.OnCameraChange.Add(CameraChangeCallback);
}

if (mode == Mode.Color || mode == Mode.TextureShift || mode == Mode.TextureScale)
{
// since materials get instanced by calling renderer.material; we can't cache this at load time because it will be referring to the material on the prefab
var renderer = controlledTransform.GetComponent<Renderer>();
affectedMaterial = renderer.isPartOfStaticBatch ? renderer.sharedMaterial : renderer.material;
affectedMaterial.SetColor(colorName, passiveColor);
}

LoadAnims(thisProp);

TurnOff();
Expand Down

0 comments on commit 7c4f3ab

Please sign in to comment.