- Home /
Material becoming pink while using DontDestroyOnLoad
Hello, I use a DontDestroyOnLoad GameSettingsObject to pass a material of a PlayerObject from menu into the level (player can choose a skin of that object). When a button is pressed in menu, it passes it's material to that GameSettingsObject, and when a level is loaded I use the LevelStarterObject to attach the material into the PlayerObject. It always turns out to be pink however. I don't get any errors/warnings and when I try to access other GameSettingsObjects' components, they work fine.
Even though in my inspector my material is still attached to GameSettingObject, when I try to print it using Debug.Log, it says "null".
When I load a level, the LevelStarterObject and the PlayerObject are already instantiated, but no matter when I try to attach the material, the result it the same. All objects that I use have their prefabs, just like all my materials, which usually work perfectly fine.
I was looking for answer for a lot but couldn't find any :/