- Home /
2d mode through Editor Script
I am trying to set The Scene view to be in 2d mode with an editor script.
i can read the state on the sceneview with:
SceneView.lastActiveSceneView.in2DMode;
not problem, no errors! But if i try to Set it i get the following error! Any clues?
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Tools.get_viewToolActive ()
UnityEditor.Tools.get_viewTool ()
UnityEditor.SceneView.set_in2DMode (Boolean value)
Thanks in advance!
Answer by highlyinteractive · Jul 27, 2015 at 12:18 PM
Just came across this solution:
SceneView sv = SceneView.sceneViews[0] as SceneView;
sv.in2DMode = true;
Obviously it's possible to have multiple scene views, so you might want to put this in a loop.
I still get the same error... Have you tried the code? did it work?
Yes, I have it working & I can toggle between 3D & 2D modes. What error are you getting?
Same Error As i have Above! Cant find anything about it tho... Any ideas what could be the issue?
NullReferenceException: Object reference not set to an instance of an object UnityEditor.Tools.get_viewToolActive () UnityEditor.Tools.get_viewTool () UnityEditor.SceneView.set_in2D$$anonymous$$ode (Boolean value)
Not sure - it looks like your instance of sceneview is null. What does SceneView.sceneViews.Count return?
Actual number of scenes... and the SceneView.sceneViews [0]
returns (UnityEditor.SceneView)
I am working on Unity 4.6.5 so I tried the code in unity 5 and it works! So i guess its some sort of bug in Unity 4 maybe...