- Home /
What could be causing this problem reading from a Rect into a Vector2?
First time I've seen this error message:
FieldAccessException: Error verifying someScript:someFunction ():
Type at stack is not accessible at 0x00ea
Line that causes it:
v_MenuWindowSize = Vector2(screenPresets.Menu.Window.width, screenPresets.Menu.Window.height);
screenPresets.Menu.Window is a Rect. screenPresets.Menu is a class container that has all of my variables for GUI layout for the screen.
Answer by NewfieJoe · May 22, 2011 at 05:23 AM
I have two variables referenced this way. .Presets worked fine before adding the MenuSettings class but because Preset can't use .Menu for a variable declaration in this context it had to be moved into a separate script in Standard Assets\Scripts to be sure it was compiled first ( ScreenPresetList is in Plugins\ ).
public class ScreenPresetList {
private class MenuSettings {
public var Window: Rect;
public var Buttons = new Rect[5];
public var Music: Rect;
public var FX: Rect;
public var Skill: Rect;
public var Label: String;
}
private class Preset {
public var Label: String;
public var ScreenWidth: int;
public var ScreenHeight: int;
public var CameraOffset: float;
public var MenuWindow: Rect;
public var TinySkin: boolean;
public var Menu: MenuSettings;
public var ID: int;
public var Skin: GUISkin;
}
public var ScreenPresetLabel: String;
public var ScreenWidth: int;
public var ScreenHeight: int;
public var CameraOffset: float;
public var Skin: GUISkin;
public var Current: int;
public var Menu: MenuSettings;
public var Android = new Preset[12];
public var iOS = new Preset[4];
public var Browser = new Preset[3];
public var Count: int = 12;
public enum PlatformType { Android=0,
iPhone=1,
iPad=1,
PC=2,
Macintosh=3,
Netbook=4,
Web=5}
public var Platform: PlatformType;
private var fileName: String = "Game_Presets";
}
Answer by Luke Briggs · May 21, 2011 at 11:16 PM
It looks to me like you might be having an issue with permissions on the variable. If it's in C# then it may need to start with public (e.g. public Rect Window=new Rect(...); ). You might also need to put static in there if it's stored in another file to the one your trying to access it from:
C#: public static Rect Window=...
Js: static var Window:Rect=..
If not try storing a reference to the Rect before using it:
var theWindow:Rect=screenPresets.Menu.Window;
v_MenuWindowSize=Vector2(theWindow.width,theWindow.height);
Hope that helps! :)
Yeah...a quick access test is to break it out: int fff = blah.height; int ggg = blah.width;
and see which one throws the error.
Answer by Bunny83 · May 22, 2011 at 10:12 AM
How about making your MenuSettings
class public? A private class is only accessible from within the class so every variable of that type will throw an error if accessed outside the outer class.
The problem was the compile order. Since one private class was accessing the other private class I had to make $$anonymous$$enuSettings into a separate public class outside the outer class and place it in standard assets so it would compile before the outer class did. (The outer class was in assets/plugins) I thought they would be compiled in the order they appear and it actually seemed so, but at runtime it would throw up that error in the console. Just making it a public class inside the outer class would make the entry show up twice in the inspector IIRC.
Your answer
Follow this Question
Related Questions
NullReferenceException help 1 Answer
ExecutionEngineException: SIGILL 0 Answers
Populating a Vector2 array in Javascript 1 Answer
Why doesn't Unity like my rectangles? 1 Answer
Vector2 AI help 0 Answers