- Home /
Why do my Assets work in Editor and nowhere else?
Hey guys, my problem is quite simple: I have several GameObjects (Cars) that - depending on distance to camera and a "mood"-variable - change their mesh (like LOD) or material. Neither mesh nor material are actually "in the scene": The Spawnpoint GO - placing the cars in the scene - has a List of GameObjects (Cars), which then again have their two meshes and three materials. While playing the cars dynamically change their shared mesh / material. This works fine in Editor and did already worked on devices (!) (e.g. WinRT, Windows Phone 8, Windows 8), but stopped working. When changing the LOD the mesh isn't rendered, when changing the material it becomes pink. This happens on all three platforms outside of the editor. As it is working IN the editor, it shouldn't be a "code-problem." What might be the reason for the differing behaviour? Cheers, Daniel
Does it generate any error messages? Also, what do you mean "works in the editor?" Do you mean it works in Play $$anonymous$$ode in the editor? Or do these scripts run in edit mode?
Have you changed anything with the software, like updating Unity?
Also, have you changed devices?
Are you sure that all the assets that are needed are in the right places in the builds you're testing?
EDIT: Calling Resources.UnloadUnusedAssets() before entering a level actually solves the problem. Still, the question remains.
Pink means that a shader hasn't been loaded, or the shader isn't compatible with the device.
Graham, the shader should be compatible. It's the standard $$anonymous$$obile/Diffuse and it has already been working and right now appears to be working from time to time with no changes in the shaders.
DESTRU$$anonymous$$TORR, I don't have any error messages (even on the devices) and everything works fine in Play $$anonymous$$ode in editor. I have been using 3 Platforms and Devices, but these are the same devices, that have already been working.
The only major change was that I have tried Unity Pro License but cancelled my testphase to rule this out. Problem remains with both licenses of Unity. I can't really say if the problem started with the Pro-License as it only happens on the devices and I only test on them from time to time. Additionally I ran an update of Daikon Forge UI - but playing with a disabled UI doesn't change the situation.
What do you mean by "are in the right places?" I didn't move them, they get included in the built (from what I can tell from the Editor.log after building) and they work in the editor.
One more thing I noticed: I happens that in one level I've got access to all materials and meshes(!) and in others don't (within the very same built and ga$$anonymous$$g session)
EDIT: Actually it is random if a level has got these problems or not. During one session in the same built levels either work or don't. It appears to be completely random.
Answer by FlashMuller · Jul 10, 2014 at 06:36 AM
Ok,
so I found a solution to that problem, although I can't explain why the old system stopped working. As a reminder: Resources we're assigned to variables in the editor and then randomly disapppeared. When using Resources.Load during the Start() Routine everything works fine, so there appears to be a big difference between assigning and loading.
Still I don't know why this did work once in the first place. Anyway, Resources.Load() appears to be the right way to get Resources in the scene.
Cheers
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Getting properties on 'missing' things in Editor Scripts? 4 Answers
How to set a shared material in inspector? 0 Answers
Unity editor and inspector header 0 Answers