using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class GoalPanel : MonoBehaviour
{
public Image thisImage;
public Sprite thisSprite;
public TextMeshProUGUI thisText;
public string thisString;
// Start is called before the first frame update
void Start()
{
Setup();
}
void Setup()
{
thisImage.sprite = thisSprite;
thisText.text = thisString;
}
}
I would appreciate any assistance you can provide. Thank You.
Yeah looking at the image again, you’re inspecting Goal Prefabs, which does have an image component. While you’re trying to drag Goal Image into the field, which likely doesn’t have the right component on it.
You might’ve put the component on the wrong game object then?
I’m not the only one to have the same issue with the exact same situation (viewers of the tutorial). There were no compile errors. The code was written exactly as the tutorial (and no errors in console).
Simple fact is, the 2022 version of Unity does not allow you to drag a prefab game object into an Image component from what I’ve determined. At least not in this case.
Image prefab, for some reason, can’t be dragged into this in the inspector in Unity 2022:
Everything works as expected for me. Here’s what I just tested:
install and open 2022.3.10f1:
make a new project
make a script with a public UnityEngine.UI.Image field
make a Canvas with an Image in it
drag the GameObject with that Image into the field - WORKS.
Goto my 2021 project:
made a prefab of a Canvas with Image, saved the prefab
closed 2021, dragged the saved prefab from the 2021 project to the 2022 project
dragged the prefab into my scene
dragged the GameObject Image into my script field - WORKS
Repeated ALL the above with an old 2018 project - WORKS.
Took the 2018 project, upgraded it in place to 2022:
fixed compiler errors related to Package crapware
newly-created Image instance: WORKS
old prefab from when it was a 2018 project dragged into slots - WORKS
We use this every day at 100+ person production scale. We’re migrating to 2022 now. My team is on 2021, but other teams are on 2022.
This stuff does work.
I’m still guessing you have compiler errors, or else perhaps you’re not being explicit with your type and you have something else called Image.
Make sure your log console selector buttons are enabled. See this graphic:
Extra unwanted packages in new projects (collab, testing, rider and other junk):
About the fastest way I have found to make a project and avoid all this noise is to create the project, then as soon as you see the files appear, FORCE-STOP (hard-kill) Unity (with the Activity Manager or Task Manager), then go hand-edit the Packages/manifest.json file as outlined in the above post, then reopen Unity.
Sometimes the package system gets borked from all this unnecessary churn and requires the package cache to be cleared:
Definitely wasn’t compile errors. It’s always the first thing I check. In your 2022 example, it doesn’t say that you made the game object or canvas into a prefab. In your 2021 example, it says you took the prefab over to your 2022 version. And you said it works with 2018, which I already knew it would with an older version. Did you try make the 2022 version game object into a prefab and dragging it from there? Or was the only workaround to make it in 2021 and take it over to 2022?
The prefab examples were Canvas with Image under it.
Of course after copying it I dragged it into scene because you cannot just drag a sub-child part of a prefab into a scene. That’s never been possible, even before the nestable prefabs.
However, as you requested above, in 2022 I made a bare prefab out of the Image without the Canvas (a VERY questionable workflow!) and I can drag that Image into a scene, then drag it into my field all day long.
I can also drag that bare Image prefab into the in-scene GameObject’s field.
You will NEVER be able to drag a Canvas into an Image slot, no matter how many Images are underneath the Canvas on other GameObjects. That’s never been a thing.
I know that. Maybe you misunderstood. I was trying to drag a BLUE (because it’s a prefab) Image GameObject into the Image spot. I never tried dragging the canvas. But, in 2022, it wouldn’t allow me to drag the blue Image to an Image spot in the inspector. After I switched to 2020, it allowed me to. Nothing else was changed besides switching versions.
Could it be that you had the Inspector window locked in your Editor?
In your first screenshot the Inspector has the message Root in Prefab Asset (Open for full editing support), which seems to indicate that you were inspecting the prefab asset selected in the Project window, instead of the prefab instance that can be selected in the Hierarchy window.
So when you tried to drag a reference from the unpacked instance in the prefab stage to the prefab asset, Unity doesn’t allow it, since scene-to-prefab references aren’t supported.
But then I’m not sure how you were able to select the Image using the Object Picker, and getting the Type mismatch issue.
Perhaps this isn’t supported for assigning references from the children of a prefab asset? Not sure if I’ve ever tried that.
Could also be the editor somehow got into a wonky state from the prefab being simultaneously modified by two sources (prefab stage with auto saving enabled and the locked inspector).