Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by awsapps · Aug 11, 2021 at 06:08 AM · compiler error

Force compile error on missing script

Hi, Is there a way to force a compile error if there's some Gameobject / Prefab with a missing script?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by awsapps · Aug 11, 2021 at 08:27 AM

Thanks rage_co! The post Callback after scripts finish compiling you mentioned is sufficient for what I want.

This should be a workflow for deleting a monobehaviour safely:

  1. You want to delete the monobehaviour A.

  2. Before deleting the script, add the method:

      [UnityEditor.Callbacks.DidReloadScripts]
         private static void OnScriptsReloaded()
         {
             System.Type monobehaviourType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
             Object[] objs = GameObject.FindObjectsOfTypeAll(monobehaviourType);
             foreach (Object obj in objs)
             {
                 Debug.LogWarning($" Watch out! The monobehaviour {monobehaviourType} is currently being used by {obj.name}", obj);
             }
         }
     
    
    
  3. Focusing on the editor again, the console will snitch all GameObjects (including prefabs) that are using such script. Double clicking each warning line will redirect to each GO.

Marking your reply as accepted. Thanks!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rage_co · Aug 11, 2021 at 08:56 AM 1
Share

glad you found a solution, and this is quite useful so i might use it sometime later in the future too, so a thanks in advance!!

avatar image
0

Answer by rage_co · Aug 11, 2021 at 06:15 AM

It's really simple to do this at runtime....for example let's say we want to give a compiler error if a certain component.... let's say CameraManager is missing...

 if(target.GetComponent<CameraManager>() == null)
 {
   Debug.LogError("Component missing!");
 }

Debug.LogError basically gives an error....hope this helps

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by awsapps · Aug 11, 2021 at 06:30 AM

Not in runtime?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rage_co · Aug 11, 2021 at 06:51 AM 0
Share

Im not too sure in that case...maybe Editor scripting? But since i haven't had any experience with it i can't really say

avatar image rage_co · Aug 11, 2021 at 06:54 AM 0
Share

I found this question and it might contain what you need "Callback after scripts finish compiling"...

avatar image rage_co · Aug 11, 2021 at 07:01 AM 0
Share

Also, just a piece of advice that you should use Debug.LogWarning instead of LogError since if you give out an error each time....you will not be able to do anything in the editor and actually fix the error...so a Warning should do just fine

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

166 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Bizarre compile errors in Unity while Visual Studio will build project successfully 0 Answers

Failed to compile resorces with the following parameters 0 Answers

Unexpected symbol Compiler error.,how to fix this "unexpected symbol" compiler error? 1 Answer

Gradle Build failed unity 2020.3.14. incompatible daemon, commandInvocationFailure 7 Answers

CS8025 Parsing Error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges