Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by onelivesleft · Dec 04, 2016 at 08:24 AM · editorscript.custom editor

Editor Script doesn't work on restart

I made a simple editor script to perform some operation on an object tree (i.e. set a value on a parent object and all its children). It works fine during use: I can make the window show, dock it, and use it. However, when I restart Unity after docking it I get:

Removed unparented EditorWindow while reading window layout: window #11, type=UnityEditor.FallbackEditorWindow, instanceID=13494 UnityEditor.WindowLayout:LoadWindowLayout(String, Boolean)

followed by:

ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List`1[UnityEditor.EditorWindow].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633) UnityEditor.DockArea.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:328)

As I said the script works fine in the first instance; there are no compiler errors or warnings. Any idea?

Script:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 public class StampTool : EditorWindow {
     public GameObject MaterialParent;
     public Material material;
     public GameObject ShadowsParent;
     [MenuItem("Window/Stamp Tool")]
     
     public static void ShowWindow() {
         EditorWindow.GetWindow(typeof(StampTool), false, "Stamp Tool");
     }
 
     void OnGUI() {
         GUILayout.Label("Stamp Material", EditorStyles.boldLabel);
         MaterialParent = (GameObject) EditorGUILayout.ObjectField("Parent", MaterialParent, typeof(GameObject), true) as GameObject;
         material = (Material) EditorGUILayout.ObjectField("Material", material, typeof(Material), true) as Material;
         bool enabled = GUI.enabled;
         GUI.enabled &= MaterialParent!= null && material != null;
         if(GUILayout.Button("Stamp")) {
             foreach(Renderer r in MaterialParent.GetComponentsInChildren<Renderer>()) {
                 r.material = material;
             }
         }
         GUI.enabled = enabled;
         EditorGUILayout.Separator();
 
         
         GUILayout.Label("Stamp Receive Shadows", EditorStyles.boldLabel);
         ShadowsParent = (GameObject)EditorGUILayout.ObjectField("Parent", ShadowsParent, typeof(GameObject), true) as GameObject;
         enabled = GUI.enabled;
         GUI.enabled &= ShadowsParent != null;
         GUILayout.BeginHorizontal();
         if(GUILayout.Button("Stamp On")) {
             foreach(Renderer r in ShadowsParent.GetComponentsInChildren<Renderer>()) {
                 r.receiveShadows = true;
             }
         }
         if(GUILayout.Button("Stamp Off")) {
             foreach(Renderer r in ShadowsParent.GetComponentsInChildren<Renderer>()) {
                 r.receiveShadows = false;
             }
         }
         GUILayout.EndHorizontal();
         GUI.enabled = enabled;
     }
 }
Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Glurth · Dec 04, 2016 at 05:42 PM 0
Share

Can you confirm this has nothing to do with the contents of OnGUI(), by remarking-out all that code temporarily, and testing it again? If you put this editorwindow in a new, otherwise empty, project, do you get the same error?

avatar image onelivesleft Glurth · Dec 04, 2016 at 05:47 PM 0
Share

Same error after commenting out OnGui. I then made a new project and added that version (no OnGui) to it, and same error again :/

avatar image Glurth onelivesleft · Dec 04, 2016 at 05:53 PM 0
Share

odd. Your ShowWinndow code looks almost identical to the documentation example. I'll test it on my system when I get back home: perhaps it's a system-specific problem.

Show more comments
avatar image Bunny83 · Dec 04, 2016 at 06:15 PM 0
Share

Try to reset your Layout of the Unity editor (the drop down at the very top right of the editor). And default layout should do.

I'm not sure if the changed window title could cause a wrong recreation of the window. Try adding:

 void OnEnable()
 {
     titleContent = new GUIContent("Stamp Tool");
 }
avatar image onelivesleft Bunny83 · Dec 04, 2016 at 06:20 PM 0
Share

Tried both your suggestions, neither worked

avatar image Bunny83 onelivesleft · Dec 04, 2016 at 09:44 PM 0
Share

I've copied your editor script as it is into my test project. I've tried several arrangements, different docking positions / states but not matter what i do the window loads back in just fine after a restart. Are you sure that there are no compiling errors whatsoever? Any compiling error in another script could prevent the loading of your editor window class at startup.

What you could try is:

  • closing your custom editor window.

  • close Unity

  • delete the metadata file of your editor window script

  • restart Unity

If the problem persists there must be something else wrong. In that case it would be great to know:

  • your exact OS version

  • your exact Unity version

  • where and how that editor window is docked (maybe a screenshot)

avatar image ZealotAlie · Feb 16, 2017 at 03:05 PM 0
Share

Hi, I just meet the same problem. So have you resolved this error?

avatar image onelivesleft ZealotAlie · Feb 16, 2017 at 04:22 PM 0
Share

No, I pretty much just gave up on it. it only has a problem when I dock it, so now I just open the tools window when I need to use it then close it after :/

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Undo.Record: Recording variables within array elements 0 Answers

How can I create a custom AssetPreview for a prefab 1 Answer

layout serializable objects in unity 1 Answer

Drag from custom editor ObjectField 0 Answers

How Mark Prefab Dirty? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges