How to get an error/warning about missing scripts on gameObjects?
Is there any NORMAL (= without making other scripts) way to get an error or warning when you rename or delete a function in a script that is attached to a button On Click in the Unity Editor? Currently unity keeps working like nothing happened, until I actually click the button. We can't be expected as devs to always keep in mind to go to 1000 buttons in the Editor and change their functions when we simply rename a function in code. Because of this I try to avoid like the plague using the Unity Editor do drag and drop things, I literally cannot trust it.
Answer by pcdrive · Jun 11, 2018 at 11:19 AM
Hi @self_made,
I didnt used unity lately, but maybe you can make use of this.
You can make a check in the script which you use the items in. With the
if (YourGameObject.GetComponent<YourScript>()==null) Debug.Log("missing script.")
or if you want a warning
if (YourGameObject.GetComponent<YourScript>()==null) Debug.LogWarning("missing script.")
Hi @pcdrive, thanks for the answer, but is there any way to have Unity do this? $$anonymous$$y code will look like shoe if I add for each gameObject code to check if the gameObject is there or not, idk, this seems like common sense for me, that the IDE tells you that something is missing, I noticed it does this for prefabs, but not if I...for example rename a function in code that is assigned as On Click in the Editor for a button.
Answer by NEVER-SETTLE · Jun 21, 2018 at 03:00 PM
The 'best' way so far I've come across is:
Assert.IsNotNull(yourGameObjectOrWhatever);
This will essentially throw an error at compile time if you are in this scene with the gameObject that contains this code.
Please vote on this topic here, maybe someone at Unity will start to give a shoe about it...
https://feedback.unity3d.com/suggestions/required-field-attribute