• 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 /
avatar image
Question by U1Arts · Jan 26 at 03:18 PM · beginnerbasicsconditionalsimplifyexpression

Help with simplyfying this line of code!

Hello, I'm relatively new to unity and the tutorial I'm following uses the line below to declare a variable

public TMP_Text tmpro => tmpro_ui != null ? tmpro_ui : tmpro_world;

The problem is I'm getting an error in unity saying: error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'TMPro.TextMeshProUGUI' and 'TMPro.TextMeshPro'

I assume that this is about the version of c# used in unity 2020. Is there a way to write the same line of code in different way? For example:

 if (tmpro_ui != null)
     public TMP_Text tmpro = tmpro_ui; 
 else 
     public TMP_Text tmpro = tmpro_world;
  

Sorry If this is dumb. If you can help me with transforming that line of code ti will be very very helpful. Thank you.

Comment

People who like this

0 Show 1
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 The-Peaceful · Jan 26 at 06:50 PM 0
Share

Sounds like unity has no clue how to convert the ui version to the 3D version. I am guessing 'tmpro_ui' is TextMeshProUGUI and 'tmpro_world' is TextMeshPro and not TMP_Text, do you need them to be those specific classes or can you not just declare both of them as TMP_Text? Or you just cast them into a TMP_Text (that should work since they both derive from that class). That would look like this

public TMP_Text tmpro = tmpro_ui != null ? (TMP_Text)tmpro_ui : (TMP_Text)tmpro_world;

I have not tried that code out though :P

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by TermoPollo · Jan 26 at 08:06 PM

I believe the problem is not the version of Unity you are using but rather the assignment. TextMeshPro has both TextMeshProUGUI and TextMeshPro class, the error is telling you that you are trying to implicitly assign one class to a different one. TextMeshProUGUI is used when working with canvas elements. TextMeshPro is used for meshes in 3D world space I don't know exactly what you want to do, but if you just want to set the text you can do as follows:


 public TMP_Text tmpro;
 if (tmpro_ui != null)
     tmpro.SetText(tmpro_ui.text); 
 else 
     tmpro.SetText(tmpro_world.text);

Comment
Captain_Pineapple

People who like this

1 Show 0 · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

171 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Begginers question, Simplifing a script, opening two doors with 2 overlapping triggers. 1 Answer

Did my software download incorrectly? 2 Answers

A begginers Basic Questions *community help wanted* 3 Answers

Having trouble with wheel colliders. (IMMA NEWB) 0 Answers

Beginning Game Development for Unity 2 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