- Home /
List won't take some types.
Hey guys, I'm in the middle of a stump I can't seem to figure out.
Okay, this line of code WORKS
cList.Add (new Camera ()); cList.Add (new CanvasRenderer ()); cList.Add (new Canvas ()); cList.Add (new CanvasGroup ());
However, CanvasScaler won't work
cList.Add (new CanvasScaler());
Which gives me these errors.
I have already tried doing public CanvasScaler scaler; and adding scaler to the List. Which doesn't throw any errors, at least until I try to debug log it. Then it says it doesn't exist...
What is messing it up is the new CanvasScaler() inside the list Everything else works but CanvasScaler.
All I'm trying to do is store all the Unity Components into a List so I can later use them.
Answer by doublemax · Sep 07, 2016 at 07:53 PM
The list is not the problem. The problem is that CanvasScaler has a protected constructor and therefore you can't create an instance of it.
Besides: I have serious doubts that what you're doing makes any sense. But then again, i'm only using Unity for a few weeks...
I guess that makes sense, as I don't exactly see it in the component menu, it must not be something I can access in general..
Oh I'd agree, normally what I'm doing wouldn't make sense, but it will when it's done. This isn't for a game or anything, just a tool I'm making.
But I will mark your answer as correct, because I wasn't even thinking about that to be honest. Thanks man.
Your answer
![](https://koobas.hobune.stream/wayback/20220612092347im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add dictionary keys with defined values to a list 1 Answer
Using Enums with JSON 0 Answers
what are Lists? 1 Answer
check if something is on a list by one argument 1 Answer
Javascript List, Sort a floating point number? [Solved] 2 Answers