Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
3
Question by habsi70 · Nov 02, 2014 at 02:15 PM · ui4.6

Beta 4.6 - Cannot get Image Component

I am currently working on an Android Project with the vuforia AR engine. I wanted to use the new UI engine to overlay a menu which can be toggled. In a seperate project I created the menu to get to know the new UI functions. The menu has some toggle Buttons which change the Icon when pressed. For example when I turn off the sound, the sprite is changed to a "sound off" Icon.

All other functions, like showing/hiding the buttons, muting/unmuting sound and even toggling the flashlight on/off are working as expected.

In the Test-Project everything worked out fine. But when I rebuilt the menu in my game, using the same scripts and Objects, I get the following Error: The type Image' must be convertible to UnityEngine.Component' in order to use it as parameter T' in the generic type or method UnityEngine.Component.GetComponent()'

Here is a C# code sample which works fine in a seperate project, but is throwing an error in my game:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class TestImageComponent : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
         Image img = GetComponent<Image>();
         Debug.Log(img.sprite);
     }
 }

In both projects I create a canvas, add an Image, add a UI Sprite to the image and add the script.

Both projects import UnityEngine.UI. My first guess was that I missed some Imports

I rebuilt the menu by hand. When this failed I exported a unitypackage from the working test Project. In both cases I get the same error.

I am suspecting this to be a bug, but maybe some of you had similar problems, or better, a solution?

Comment
Add comment · Show 2
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 habsi70 · Nov 02, 2014 at 02:34 PM 1
Share

Thank you, CanisLupus! Vuforia seems to have an Image class defined, so I followed your suggestion, added the following line to my script and adapted the type where necessary:

 using UiImage = UnityEngine.UI.Image;

 ...... Inside the class .....
 
 buttonImage = GetComponent<UiImage>();
 

Please convert your comment to an answer so I can mark it as correct.

avatar image Wolfram · Jan 06, 2015 at 05:42 PM 0
Share

Note there is an open thread in the Vuforia forum, to which I just replied. You might want to monitor it for any updates:

https://developer.vuforia.com/forum/issues-and-bugs/qualcomm-vuforia-conflict-unity-46

EDIT: They already replied: the issue is fixed in Vuforia 4.0 (currently Beta).

1 Reply

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

Answer by CanisLupus · Nov 02, 2014 at 02:22 PM

Is it possible that you have another class named Image somewhere in your game? If such a class is located in the default namespace, it might be conflicting with Unity's Image class, and the compiler only sees your class, which is not a Component.

Try adding the following after your usings and see if the problem remains:

 using Image = UnityEngine.UI.Image;

Update:

I'm glad this solved the problem ;)

For others reading this, please also read habsi70's comment below his question, as it completes my answer. Trying to redefine Image like I did can result in other compilation errors, so use a new name (ex.: UiImage).

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 lagallardo5426 · Oct 05, 2020 at 11:47 PM 0
Share

this is a great fix. it even fixed the problem of it not showing in the inspector, serialized, or the public attribute.

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

29 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

Related Questions

Where is Reference Resolution in new version? 1 Answer

unity 4.6 new UI Android soft buttons 1 Answer

4.6 Beta uGUI: Putting UI elements in a ScrollRect via code 1 Answer

4.6 UI - overriding order / depth 1 Answer

(4.6 UI) How to highlight a character/unit when moused over? 1 Answer


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