'Unity changing from game object to ui Image

In unity I am fetching a UI image through GameObject.Find() However when I try to change the value of another image component to the result of the game object find I get the error:


Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.UI.Image' \[Assembly-CSharp\]csharp(CS0029)

Code:


Image image;

image = GameObject.Find("the other image");

Is there a way to fetch a UI Image game object through just it's name without it being set to a generic game object?



Solution 1:[1]

You are attempting to assign the value of a image to a gameObject, you simply need to get the image

Image image;

var imageGameObject = GameObject.Find("the other image");

if(imageGameObject == null)
{
    //couldn't find the gameobject 
}

image = imageGameObject.GetComponenet<Image>();

to get the actual image component

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1