I am sitting in front of a complex project where I get the Monebehavior new warning.
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
Unfortunately the warning does not mention the script that does this.
i know what this means ,that there is a script trying to instantiate a Monebehavior up with “new”, but the error message does not give a hint where to start looking and the project runs fine otherwise. The project has gone through some years of experiments and I must have overlooked the warning all the years-- I know I made a decision at more than point to use Monobehaviors instead of class objects and rewrote the classes , might have been I have forgotten a script that still tries to create those-- but where to start looking? Makes no sense to wade through all scripts using the new keyword, that would take forever.
Does anyone know a trick how to find out where this warning is being triggered?
Thanks in advance:-)
Edit: found a solution:
Okay, I am commenting this myself since I have found a way to deal with this:
You can enable full strack trace logging for warnings in the console window in Unity (tiny icon on the right, three parallel lines). When this is enabled Unity gave me the necessary information to find the script that gave me the error.
//****OLD text
Thanks for the idea— but
Hmm-- disabling my scripts one after the other will very soon lead to errors stopping the runtime. Also components that do not use “Start” or “Update” cannot be disabled.
I was hoping for some way to make Unity give me more information about where the warning is being triggered.
I might try to simply disable groups of Objects to see if the error goes away, hoping the script resides on an object that is not interlinked with others too much to break execution, but that is also not really a reliable and methodically clean way to find the cause—
I read somewhere you can force Unity to treat warnings as errors-- I will give that a try, see if that gives more info.
*EDIT:
I created the file mcs.rsp at theroot of the asset directory and added the line “-warnaserror+” to it.
It worked and stopped my build with several errors that were warnings before, but unfortunately not the one I am hunting
tormentoarmagedoom · vor 6 minutes 0
Comence disabling scripts, 1 by 1
until you see the error disapear to
detect whicch script is.