Quantcast
Channel: Answers for "Can I define initial variable for serialized array in the inspector?"
Browsing all 8 articles
Browse latest View live

Answer by qJake

No. Array values must be initialized manually. If you have Test[], the type is actually "Array of Tests", which is not the same as a "Test". Anytime you have an array, each cell has to be initialized...

View Article



Answer by Mike 3

Possible using the constructor:public class Example : MonoBehaviour { public Test test; public Test[] testArray; public Example() { Test a = new Test(); a.p = 5; Test b = new Test(); b.p = 100;...

View Article

Answer by standardcombo

This is how you do it. When Unity creates the 'myStrings' property for viewing in the inspector, it will call the ArrayInitializer() constructor, assigning the default values you pass as parameter:...

View Article

Answer by stuffses

Old question, but I had the problem myself and came across this while searching. @mike-3 has an okay solution, but it doesn't work when new items are added to the list. Eventually I figured out...

View Article

Answer by qJake

No. Array values must be initialized manually. If you have Test[], the type is actually "Array of Tests", which is not the same as a "Test". Anytime you have an array, each cell has to be initialized...

View Article


Answer by Mike 3

Possible using the constructor:public class Example : MonoBehaviour { public Test test; public Test[] testArray; public Example() { Test a = new Test(); a.p = 5; Test b = new Test(); b.p = 100;...

View Article

Answer by standardcombo

This is how you do it. When Unity creates the 'myStrings' property for viewing in the inspector, it will call the ArrayInitializer() constructor, assigning the default values you pass as parameter:...

View Article

Answer by stuffses

Old question, but I had the problem myself and came across this while searching. @mike-3 has an okay solution, but it doesn't work when new items are added to the list. Eventually I figured out...

View Article

Browsing all 8 articles
Browse latest View live




Latest Images