I am going insane, i am making a sandbox game, in that game you can also change the color of the object you want to spawn, by changing the prefab color, but however i dont want the objects that are already spawned change its color, and if i change the color of the prefab, it also changes the color of the object that was spawned, how do i do this? i researched a lot and found nothing related to my problem. So Please Give me a Solution, and i promise i will credit you when the final build releases
At first I was confused why is it not obvious that you’d only change the color of the instance, but then I realized that you may be changing the color of the shared material, which is not instantiated with the prefab. (But I am still unsure whether you are changing the color of the prefab before instantiation or not).
Accessing renderer.material property actually creates a copy of the material, so if you are using that, it should not be a problem.
The best solution is to use MaterialPropertyBlock. Have a single color changing script on your prefab that has or can obtain references to all renderers you want recolored. On its start or color property set, iterate over renderers and change their MaterialPropertyBlock to include the Color property override. That way you don’t have to duplicate materials, which has several advantages, both performance and editor experience (you can for example still change the other properties of the original material in the editor while the game is running).