Search Unity

error CS0619: 'GUIText' is obsolete: 'GUIText has been removed. Use UI.Text instead.'

Discussion in 'Editor & General Support' started by RandomCharacters, Feb 12, 2020.

Thread Status:
Not open for further replies.
  1. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    I am using a asset on the unity store that was depreciated a couple of years ago. It worked under unity 2019.2 but now gives errors in the console. I get the following error in unity 2019.3
    error CS0619: 'GUIText' is obsolete: 'GUIText has been removed. Use UI.Text instead.'

    I changed 2 lines of code (see picture) but the other 2 lines stll gives errors.
    As it is not my asset, I do not fully understand it. Any help on the conversion would be cool. It's the equilivant of pixeloffset.

    Here is the code:
    Code (CSharp):
    1. public static void changeFont(GUIText gt,
    2.                                   Vector2 vec)
    3.     {
    4.         Font newFont = getFont(gt.font.name,vec);
    5.         if(newFont)
    6.         {
    7.             gt.font = newFont;
    8.             gt.material = newFont.material;  
    9.         }
    10.     }
    11.     public static void resizeGUIText(GUIText gt,
    12.                                      Vector2 vec)
    13.     {
    14.         if(gt!=null)
    15.         {
    16.             Vector2 v = gt.pixelOffset;
    17.             v.x *= vec.x;
    18.             v.y *= vec.y;      
    19.             gt.pixelOffset = v;
    20.         }
    21.     }
     
    Last edited: May 21, 2020
  2. TheDude4774

    TheDude4774

    Joined:
    Feb 17, 2020
    Posts:
    1
    I'm having the exact same problem. Mine is linked to a script that comes with the Standard Assets package from Unity that I am using for a course. I did the same fix, changing GUIText to UnityEngine.UI.Text, but it greatly altered the alignment of my camera and I'm worried it will cause problems down the road if I leave it that way. Did you find any other fix?
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The UI system added in Unity 4.6 which includes UI.Text works fundamentally different than the now removed GUIText. Normally you'd do your resizing in the inspector now instead of everything having to be hard coded in your scripts. Though it is still possible to do in scripts, the old system you had to do everything in scripts. Now usually you don't.

    Setting position and size of a UI.Text now is done via height/width and achor positions relative to its canvas, or just by adjusting the GameObject's scale, so there is no direct translation of the above code without a lot more context.

    https://docs.unity3d.com/2017.3/Documentation/ScriptReference/UI.Text.html
    https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/index.html

    If none of that makes any sense, take the time to follow some UI tutorials. As you'll need to understand concepts like canvas, anchors, etc, to make any progress, and none of that was in the old UI system.

    If you want to continue using code which relies on the old removed UI system, just stick to a version of Unity which supports it. (2018.4.x LTS is probably the best choice?) Otherwise scrap this code and create or otherwise acquire something to do the job using the current system.

    On the Standard Assets, there is no updated Standard Assets package updated for 2019.3. Some things will still work, but it was last updated for a version of Unity a couple years old. I'd suggest just removing anything which throws compile errors and not trying to fix them. If they all just needed simple fixes, Unity would just do it themselves.
     
    Last edited: Apr 16, 2020
  4. vanngao09

    vanngao09

    Joined:
    Apr 17, 2020
    Posts:
    1
    For the "GUIText", just change it to "GUI",
    Ex: [RequireComponent(typeof (GUI))] in ForcedReset.cs.
    In SimpleActivationMenu.cs, change the type of camSwitchButton to AlphaButtonClickMask. Ex: private AlphaButtonClickMask camSwitchButton;
    Use try to use the quickfix function in your visual studio. The code will run with a few warnings.
    /PS: I'm new to this. Hope it helps.
     
  5. Mr_Robot_07

    Mr_Robot_07

    Joined:
    May 2, 2020
    Posts:
    1
    Assets\Standard Assets\Utility\SimpleActivatorMenu.cs(12,16): error CS0246: The type or namespace name 'UI' could not be found (are you missing a using directive or an assembly reference?)


    Can anyone tell how to resolved this error.
     
  6. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,665
  7. kai2012

    kai2012

    Joined:
    Jun 29, 2020
    Posts:
    1
    Delete the cams in the code
     
  8. Wolverine-X-man

    Wolverine-X-man

    Joined:
    May 13, 2020
    Posts:
    6
    I will Comment whole error Script :mad::mad::mad::mad::D:D:D Screenshot (10).png
     
    lttxzhangcom and dominguez-n-3 like this.
  9. RonnyKibet

    RonnyKibet

    Joined:
    Jul 7, 2015
    Posts:
    3
    This is what worked for me.
    In SimpleActivatorMenu.cs the import
    Code (CSharp):
    1. using UnityEngine.UI
    , then change
    Code (CSharp):
    1. GUI
    to
    Code (CSharp):
    1. Text
    object for
    camSwitchButton. That's it.

    All the best.
     
  10. ahmedaniss

    ahmedaniss

    Joined:
    Sep 18, 2019
    Posts:
    98
    problem fixed here :
     
  11. ryanmcn2001

    ryanmcn2001

    Joined:
    Nov 3, 2020
    Posts:
    1
    thank you so much
     
  12. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    And what about DebugGui.GetComponent<GUIText>().HitTest?
    Where are the conversions for the dot functions?
     
    twice7713 likes this.
  13. ahmedaniss

    ahmedaniss

    Joined:
    Sep 18, 2019
    Posts:
    98
    solved here :
     
    rajababricz, Rafail77 and Kintyli like this.
  14. s-killz

    s-killz

    Joined:
    May 29, 2019
    Posts:
    1
    I can't believe they just changed something that renders so many assets worthless
     
    JWdell likes this.
  15. dokimkhanh

    dokimkhanh

    Joined:
    Aug 6, 2021
    Posts:
    3
    Hi, i'm try all. But not work for me. Help me
     
  16. slitthegoblin

    slitthegoblin

    Joined:
    Nov 2, 2020
    Posts:
    1
    Change GUIText to GUI
    Delete the two lines of code that write text with a squiggly line
    and it will run
     
  17. StephenGabrielHarper

    StephenGabrielHarper

    Joined:
    Dec 4, 2019
    Posts:
    31
    Im on 2023.16f1 using HFPS kit . i got this bug.
     
    stasofunity likes this.
  18. dhruv7102006

    dhruv7102006

    Joined:
    Jan 5, 2022
    Posts:
    1
    here is the solution:
    1)in first line, write Using UnityEngine.UI
    2)instead of GUItext write Text(t should be capital)
     
  19. RehanBhutta007

    RehanBhutta007

    Joined:
    Sep 3, 2020
    Posts:
    9
    F
    fixed thank u,
     
    Nick_Boolean likes this.
  20. Tehnodead

    Tehnodead

    Joined:
    Mar 27, 2022
    Posts:
    1
    Thank you very mutch
     
    Rafail77 and Nick_Boolean like this.
Thread Status:
Not open for further replies.