Observe no “The referenced script (Unknown) on this Behaviour is missing!” warnings
go over to Microsoft Visual Studio and make any edit to any script and save
Return to Unity Editor and watch short “Reloading Domain” window pop up
Observe 8 “The referenced script (Unknown) on this Behaviour is missing!” warnings
Repeat steps 4-5, now there are 12 of these warnings
Repeat steps 4-5 again, now there are 16 of these warnings
Repeat steps 4-5 again, now there are 20 of these warnings
Repeat steps 4-5 again, now there are 24 of these warnings
etc. etc. it keeps incrementing by 4.
Close the editor/project, and repeat steps 1-5: there are 8 warnings again just like when I first opened the editor.
Why does this happen? Google only really has answers for if you remove a script from a game object or things to that effect. I am not doing anything like this. What else can be causing this to happen? It doesn’t appear to have any affect on the game, but its concerning because I don’t know what is causing it. Also as the project matures and more game objects and scripts are added and updated, the number of this warning increases. So I am pretty sure something I am coding up or doing in the editor is causing it but it is very difficult to debug when the warning doesn’t point to anything in particular.
Do you have to enter play mode for this to happen, or is it also when you just recompile? Also, is it 4 more of the warnings for each time? Ie. if you clear the console between steps 8 and 9, do you have 4 or 20 warnings?
In general, that warning usually fires when Unity loads an object - like a prefab - that contains missing scripts. If this happens on reload, there’s something Unity thinks it should keep loaded that’s got missing data.
You could also see if you get more information if you try to set stack trace logging to full for warnings,
As that might just show what kind of operation is causing the object to load.
For possible solutions, It could be something strange where a ghost window is grabbing some invalid objects on awake. This was more of a problem before, but could still be an issue, so try to reset to the default layout, that sometimes fixes surprising things:
If it’s the case that you’re getting more new warnings for each time you recompile, that sounds strange, as domain reloads generally clear out everything. So that means that something is adding something that persists to the scene or the editor or whatever. It could be that if something is instantiating a prefab with missing scripts with the HideAndDontSave flags into the current scene, you’d get the issue you’re facing. Any possible culprits there?
Do you have to enter play mode for this to happen, or is it also when you just recompile?
It’s only in play mode, and it doesn’t happen when i hit play for the first time (just opened the project from unity hub). It only happens while IN play mode and I do a recompile due to updated script.
Also, is it 4 more of the warnings for each time? Ie. if you clear the console between steps 8 and 9, do you have 4 or 20 warnings?
I have the console set up to clear after everything (play, build, and recompile). So it clears and then I have 20 warnings after steps 8 and 9. It is incrementing the number of them, not just piling on more to the existing list of them.
Full stack trace of the warning (its the same for each warning):
It could be that if something is instantiating a prefab with missing scripts with the HideAndDontSave flags into the current scene, you’d get the issue you’re facing. Any possible culprits there?
Unfamiliar with this flag, to my knowledge I have not set that flag on anything. Are there some types of objects that have that set by default?
The ResoreBackups part there leads me to believe that it’s indeed some objects with missing scripts that are being restored after a scene reload. If you turn off reloading assembly and the scene on enter play mode (set Do not reload Domain or Scene under edit->project settings->editor->Enter Play Mode Settings), do you still get an increasing number of warnings for each enter play mode?
The only thing I can think of is that Cinemachine 2 used to spawn objects with HideInInspector set to true. So if you used to have Cinemachine installed, created a prefab with a CinemachineVirtualCamera on it, and then removed Cinemachine from the project but kept the prefab, that would mean that you’d be instantiating components with removed scripts from those sub objects.
That would not explain the ever increasing number of instances, though.
You should be able to find all instances by doing something like:
var hidden = FindObjectsOfType<GameObject>().Where(go => (go.hideFlags & HideFlags.HideInInspector) != 0).ToArray();
Debug.Log("There are " + hidden.Length + " hidden GameObjects");
foreach(var go in hidden) {
Debug.Log("GameObject " + go.name, go);
go.hideFlags = HideFlags.None;
}
Selection.activeObjects = hidden;
The only thing I can think of is that Cinemachine 2
I think its this. your little routine there returns a single GameObject cm. I am not going to be able to investigate further tonight, but at the least it does seem to be cinemachine
Okay so I switched to cinemachine 3.1.0, deleted the old cinemachine game object (that contained the hidden object), used the “find hidden game objects” tool and it returned nothing, and i am STILL getting +4 warnings after each recompile (during play time). So now i think it was not cinemachine after all…
Then I don’t know what it could be! I’d send a bug report, as this kind of thing where there’s a warning that you don’t know where is comming from and you can’t do anything about shouldn’t be there in the first place.
Very probably the hidden objects are in your prefabs. The script won’t find those.
You should have upgraded to CM 3.1.2, which contains a fix in the upgrader for a problem that prevented it from removing all the hidden objects in the prefabs.