Hi, I am getting this annoying error, “UnassignedReferenceException: The variable m_Content of ScrollRect has not been assigned.” every time I open a prefab that has a ScrollRect in it:
even though my ScrollRect clearly has the Content properly defined and referenced in the ScrollRect Content inspector field.
Everything works fine at run time with no errors.
This is in Unity 2022.3.39f1. The only thing I did was uncheck horizontal scrollbar in the ScrollRect inspector and delete the horizontal scrollbar child.
Funny thing: when I click on the error in the console it highlights the vertical scrollbar in the prefab hierarchy.
Any ideas how I can get rid of this? Restarting Unity doesn’t help…
Hello,
Can you upload any screenshots or the code it references. It sounds like although you delete the bar in your inspector it isnt being deleted in the prefab parent, meaning when the game runs it recreates the scroll bar and isnt instanced at run time. To check against this follow these steps:
- Identify which object has the script that mentions m_Content
- Run the game and find the object at runtime
- If it is a prefab, step into the prefab so it is in isolation mode
- Remove the scroll bar from this
- Find references to the scroll bar in the script, can you add (if null) statements
- if the above is a yes, do so, then run the game
If you carry on having issues, feel free to get back in contact, I respond to as many posts as I can, and I can reassure you, my information is sound.
Hey, thanks! I have a couple of layers of prefabs to get to the popup windows that contain the issue. I’ll check carefully.
But the thing is, its not like the horizontal scrollbar shows up or anything at run time.
Also, I have no m_Content variable. That is in the Unity ScrollRect class and Unity’s editor is throwing the error. It references the Content field of the ScrollRect. but the issue cannot be as the ScrollRect Content field in the inspector references a valid transform.
The only code I have that touches this at all references the Content transform to dynamically add the child objects that will appear within the ScrollRect viewport.
As I wrote, it’s all fine at runtime and everything works. To reiterate, it is an editor error that only occurs when I edit a prefab that contains a ScrollView element. The problem seems to have started fairly recently.
It may well be an issue with the version of Unity, as far as im aware (Assuming Unity use the international standard) m_Content is a material variable, m signalling material, you could in theory replicate it replacing the variable that is missing. If it is not game breaking then it is okay, the scroll views only come into use when/if the content “breaks” the box as how text wraps, the scroll view is there for something that extends outside the range of the UI. That is assuming Unity use the standard naming convention.
b for bool
m for material etc.
I shall download the unity version you have and try to replicate this issue, to verify what could be going wrong. Just to see if its a constant issue, if it is then it needs to be flagged (game breaking or not)
Hey thanks for your help. I believe you were correct that the prefab at a higher level didn’t have a value in the ScrollView inspector wasn’t set - the Content value. Even though it looked like it was reference properly in each step up the hierarchy.
This prefab was inside another prefab in the scene, everything looked fine as far as Content field reference. So I unpacked the parent prefab and then the child prefab, and low and behold the ScrollView had an empty Content field reference (even though when it was a prefab the reference was there) - weird.
Having prefabs in prefabs can be a bit of a mess because overrides can get applied, and then if you edit the prefab and assign the same value as an override, the editor still thinks it is an override. The whole thing can go wonky I guess.
Thanks for your help again!
1 Like
I dislike strongly prefabs in prefabs, it is poor management. Unpack where you can and create new prefabs, there are lines of code you can write that automate this solution, but depending on your level, depends on whether it is recommended. I shall discuss the matter of overriding Unity scripts and their protection level with Unity when I have chance, I have had to write my own code automating mass, acceleration etc for a small test project and their “Unity Units” do not help. I am glad to see you got this issue fixed, always if you need it, message me I respond rather quickly
1 Like