Search Unity

AddScriptComponentUnchecked

Discussion in 'Editor & General Support' started by samjoly, Feb 22, 2016.

  1. samjoly

    samjoly

    Joined:
    Apr 23, 2013
    Posts:
    30
    Hi Team,
    I just upgraded to 5.3.2. and now I have an error with InternalEditorUtility.AddScriptComponentUnchecked ('InternalEditorUtility' does not contain a definition for 'AddScriptComponentUnchecked') - I'm using the Create Script Dialog (https://www.assetstore.unity3d.com/en/#!/content/2668).

    When searching for " InternalEditorUtility.AddScriptComponentUnchecked", so far I only found this:
    This lets you add a MonoScript to a game object directly without any type checks or requiring the .NET representation to be loaded already.

    Do you have any idea how it could be fixed?

    Thanks
    Sam
     
  2. bboysil

    bboysil

    Joined:
    Jun 1, 2013
    Posts:
    11
    I'm in the same boat as you are. Waiting for an answer... :(
     
  3. Stanchion

    Stanchion

    Joined:
    Sep 30, 2014
    Posts:
    269
    These breaking changes for no reason are getting to be too much.
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    The reason its in the class InternalEditorUtility is because its not intended for public use and may be changed at any time without any warning or publication of the fact.

    And by the way the package you are talking about is pretty out of date:
    Originally released: 19 January 2012
    Package has been submitted using Unity 3.4.2.
    So that would explain why its not working.
     
    Kurt-Dekker likes this.
  5. samjoly

    samjoly

    Joined:
    Apr 23, 2013
    Posts:
    30
    Temp solution: for now, I end up to simply comment those lines. It works, but disable the option to attache the script to a GameObject automatically.

    //if (CanAddComponent())
    // InternalEditorUtility.AddScriptComponentUnchecked(m_GameObjectToAddTo,
    // AssetDatabase.LoadAssetAtPath(TargetPath(), typeof(MonoScript)) as MonoScript);


    Old = Bad?:
    You are right it's very old package. Does it mean that it was a bad package? It seems that I'm not the only one that was using it, and it was working fine until the latest 5.3 update.


    I believe that what is bugging me the most is not so much the package by itself, but the fact any functions could stop working when upgrading Unity, without any alternative to fix or replace it. Should I take the time to create reusable script that could be randomly impossible to use (or even update) in the next Unity update?

    Thanks everyone for sharing your thought. I let you know if I find better solution to fix this package : )
     
    Last edited: Feb 29, 2016
  6. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    For the most public functions and fields unity will declare them as deprecated an will warn you before they will eventually remove them.
    If the new unity version does not work with your tool you have tow choices:
    1. Stay with the old version so you do not have to change anything.
    2. Fix your stuff to work with the new version.
    An that is not a unity problem, its a problem with software development in general that you have to deal with.
    I'm not saying the asset is bad, its you that did choose to use a asset that is not designed to work with the unity version you did choose. That it still works is more luck than anything else. It could have been brocken in 3.5 so that it was in no shape to use in 4.x or 5.x
     
  7. samjoly

    samjoly

    Joined:
    Apr 23, 2013
    Posts:
    30
    I have to admit, what you are saying is frustrating, but is true.
    Thanks fffMalzbier for sharing : )
     
  8. liuxiwen

    liuxiwen

    Joined:
    Sep 10, 2017
    Posts:
    1
    I use this --InternalEditorUtility.CreateScriptableObjectUnchecked(script);
     
  9. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    you mean you use that to replace this?
    Code (CSharp):
    1. private void Create ()
    2.     {
    3.         CreateScript ();
    4.  
    5.         if (CanAddComponent ())
    6.             InternalEditorUtility.AddScriptComponentUnchecked (m_GameObjectToAddTo,
    7.                 AssetDatabase.LoadAssetAtPath (TargetPath (), typeof (MonoScript)) as MonoScript);
    8.        
    9.         Close ();
    10.         GUIUtility.ExitGUI ();
    11.     }
     
  10. Zonker666

    Zonker666

    Joined:
    May 14, 2015
    Posts:
    1
    Change the lines

    1. Code (CSharp):
      1.   if (CanAddComponent ())
      2.             InternalEditorUtility.AddScriptComponentUnchecked (m_GameObjectToAddTo,
      3.                 AssetDatabase.LoadAssetAtPath (TargetPath (), typeof (MonoScript)) as MonoScript);
    to
    Code (CSharp):
    1.  
    2.  if(CanAddComponent())
    3. {
    4.    MonoScript ms = AssetDatabase.LoadAssetAtPath(TargetPath(), typeof(MonoScript)) as MonoScript);
    5.    m_GameObjectToAddTo.AddComponent<MonoScript>(ms);
    6. }
    7.  
    that should do it