Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 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 /
avatar image
0
Question by TruffelsAndOranges · Jul 10, 2015 at 06:59 AM · bugshadow

GetComponent() returns the outline text effect instead of the shadow text effect!

Basically I'm using both an outline (Outline) and a shadow (Shadow) on my UI.Text. When I try to fade both the shadow and the outline I use:

 Shadow shadow = GetComponent<Shadow>();
 Outline outline = GetComponent<Outline>();

Those lines will make both the shadow variable and the outline variable bound to the SAME Outline component in the game object! How do I fetch the shadow component?

Comment
Add comment · 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 ClawHunt · Mar 03, 2020 at 10:00 AM 0
Share

2018.3.0f2 It is indeed the issue, If a component is having "Shadow" and "Outline" both. The GetComponent is returning "Outline" is case of "shadow".

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Mar 03, 2020 at 10:12 AM

Well, that is a common issue when inheritance is used. The Outline class is actually derived from the Shadow class. So an Outline actually is also a Shadow. Therefore GetComponent<Shadow>() will face two instances on the same object. As far as I remember Unity now searches through the components in the same order they appear in the inspector. So a "hacky" solution is to swap the order of the two components in the inspector. That should fix the issue, though not in a nice way.


The best and most robust solution is: Do not use GetComponent but assign the reference through the inspector. If that's not possible for some reason to make the code more robust you would need to use GetComponents<Shadow>() (note the plural), iterate through the components and filter out the right components by doing some type checks.

 Shadow shadow;
 Outline outline;
 foreach(var c in GetComponents<Shadow>())
 {
     Outline o = c as Outline;
     if (o == null) // component is not an Outline
         shadow = c;
     else // component is an Outline
         outline = o;
 }

That doesn't really look very nice but will work no matter what order the two components have.

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 shadowwwww · Mar 28, 2018 at 08:29 AM

is this U need?

 public GameObject Outline;

     Outline.GetComponent<Outline>().effectDistance = new Vector2(3, 3);
     Outline.GetComponent<Outline>().effectColor = Color.black;
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 ClawHunt · Mar 03, 2020 at 09:58 AM 0
Share

No Dear, Consider reading the question again, and you will see the "shadow" part.

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

24 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

Related Questions

Terrain Tree Shadows Bug(?) 0 Answers

Illumination through walls 0 Answers

Flickering Directional Lights after instantiate? 0 Answers

Unity disconnected/flying shadow (peter panning) 0 Answers

Disappearing shadow glitch? (When camera moves) 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