- Home /
C# initializing array of structs error
Hello,
I feel like I'm hitting a wall here. I'm trying to initialize array of structs that contain data for where exactly objects in my level editor should go. Unfortunately it's not gonna happen because:
error CS1519: Unexpected symbol `}' in class, struct, or interface member declaration
The code is as follows and according to this SO answer: http://stackoverflow.com/a/309540/1046871 it should work (Unity uses C# 4 or so I was told).
public static Category[] categories = new Category[] {
new Category() {
name = "Level Objects",
objects = new CategoryObject[] {
new CategoryObject() {
name = "Cube",
iconName = "cube_ico",
prefabName = "cube_prefab"
},
new CategoryObject() {
name = "Cylinder",
iconName = "cylinder_ico",
prefabName = "cylinder_prefab"
}
}
}
}
Can someone help me? Obviously CategoryObject and Category are structs.
Answer by _met44 · Mar 30, 2015 at 01:46 PM
Do you have a semicolon at the end of it in your script ?
If so, comment everything out then uncomment each part after the other until the error shows up again. That should help you find what you missed !
You're a lifesaver, you know? How could I not notice missing semicolon? Though error reports should be more on point than "error CS1519: Unexpected symbol `}' in class, struct, or interface member declaration". But it's not your fault. It's $$anonymous$$$'s. Like everything that is going bad.
After a while you get used to what errors mean to the parser ;)
This one is either wrong amount of brackets or missing semicolon that breaks parsing, your brackets count was ok so... you got the idea ^^
Your answer