question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Color Swap Highlighter does not restore color, if (shared) material is modified at runtime

See original GitHub issue

Happens if you have gameobjects / interactibles which dynamically change their color at runtime.

E.g. a random color is assigned to a cube in the Start() method using material.color = myColor). If afterwards a controller touches the cube, it will correctly adopt the selected highlightColor but will never go back to its initial state.

The reason is that on the first occasion that the material of a renderer is modified, it is cloned (if it is also used by other renderers) and from then on, this copy is being modified. As such, the StoreOriginalMaterials method already gets a reference to the cloned material and the ChangeToHighlightColor method will modify the same instance, thus overwriting the initial state.

The solution would be not to backup the references to materials but to make actual copies (new Material(oldMaterial)).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
thestonefoxcommented, Jan 20, 2017

There may be another solution. Someone did a PR a while back using MPB to do the colour swapping and apparently that way doesn’t break batching.

I never got chance to look at the PR but it may be a solution?

https://github.com/thestonefox/VRTK/pull/704

0reactions
mographcommented, Nov 6, 2017

I applied the fix from earlier in this thread but I’m still hitting the issue. Does the fact that I’m using drop zones change anything here? I also have multiple interactable objects nested within another.

Essentially I’ve built an experience where the user builds a model. There are a bunch of GameObject that the user picks up and snaps together (like lego blocks). When placing some of these objects, the highlight color gets stuck.

The issue is intermittent…

Read more comments on GitHub >

github_iconTop Results From Across the Web

problems with shared material and different colors
So if I want several different colored materials it seems I must predefine them in the editor and cannot color them dynamically during...
Read more >
Changing materials properties during runtime
First, check if your material has this property - material.HasProperty("_EmissiveColor"). If, so, there is a trick which is usually applied ...
Read more >
How do I change the color of the surface where the collided ...
The reason to change the surface is to change the color of the surface or texture because the object is not separate, but...
Read more >
Changing MATERIAL Colors in Unity [Instances & More]
In this Unity C# tutorial, I show you how to change the material albedo colour (To change all objects that share the same...
Read more >
Colors and fonts | IntelliJ IDEA Documentation
To change the colors, click the field with color code. The color picker popup opens allowing you to choose the color as you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found