Why my material color gets reset on the next scene?

183 Views Asked by At

I have a strange issue for the past week or so. So I'm working on a 3D mobile application and I've been testing the app on and off on my android phone.

On scene 01, I have a slider for the color and it changes a certain material's color. After I'm happy with the color that I've chosen, I go then and hit the button which loads scene 02. On scene 02 the new color of the material is maintained. This happens on the Unity Editor on PC and it works great. This also used to happen when I tested the application on my phone (android) and everything worked fine.

Now to get to the issue, starting since last week, I started optimising the game for the mobile platform since it had like 20-30 fps or so and some spikes. Since then, if i am on the Editor on PC, when i change the material's color in scene 01 , it's also persisting in scene 02. BUT when I do the same on the mobile phone , for some reason when scene 02 is loaded, I still have the color of the material that the application was built with.

For example: I set the material's color to RED on Unity PC, then I build the application, and when I test the application on my phone, even if I change the color from RED to BLUE, on scene 02 it's still RED.

Now I don't know why this happens, I'm thinking maybe I've messed up some Player Settings ??? Or is there even a setting that has this kind of impact?

I started replacing the Shader (Lit) with Shader (Simple Lit) for most of the objects that are stationary, but I kept the Shader (Lit) on the object that I want to change the material's color. Maybe it has something to do with this?

Does it have anything to do with the Graphics API or something? Is there anything caches wrongfully that I have to manually clean? I still don't understand why on the PC Editor it works fine between the scenes, but on mobile it gets reset.

What resources do you need me to provide?

I have three sliders, for red, green and blue, and I'm assigning the values back to the color of the material.

Summary of the code:

 public Material material;
 
 public void MethodCalledInUI()
 {
     Color color = material.color;
     color.r = redSlider.value;
     color.g = greenSlider.value;
     color.b = blueSlider.value;
 
     material.color = color;
  }

I also tried to use PlayerPrefs to set up the material and it still does not work. (before I didn't use any PlayerPrefs for the material and it worked just fine on both platforms).

1

There are 1 best solutions below

3
On

First of all, I suggest that you consider explaining the steps you took to optimize the game. Also, consider adding screenshots for when you are on the PC vs on the Phone. For your problem, if I were you, I would try to make a build and play it on the PC, to see if it is a problem with the phone or with the build. If it is a problem with the phone, it could be because your lighting is harder to see on a smaller screen. If it's a problem with the build, I would attempt to undo what you did for the optimizing and see if it works again. Go through your optimization process step by step and see which step causes the problem. Once you figure out which step it is, you can probably solve it. If you can't, consider editing or adding a new question by asking "why does this cause this?" which will have a much higher chance of being answered to your desires.