Why is it that everytime I try to follow a tutorial or the unity documentation..

Why is it that everytime I try to follow a tutorial or the unity documentation it doesn’t compile?
its like no one attempts to update their tutorials.

I am currently copying this
but it says that GetWindow and window.Show doesn’t exist.

this is my current code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Runtime.CompilerServices;

public class FoldoutUsage : MonoBehaviour {

    bool showPosition = true;
    string status = "Select a GameObject";

    [MenuItem("Examples/Foldout Usage")]
    static void Init() {

        FoldoutUsage window = (FoldoutUsage)GetWindow(typeof(FoldoutUsage));
        window.Show();
    }
}

I am on unity 5.5.1f1 personal and this shouldn’t be happening.

Try EditorWindow.GetWindow();
change MonoBehaviour to EditorWindow <------ that’s the big one
and you shouldn’t need Show() but if you do its there

Oh and also the window wont recieve Start() but it does however receive OnEnable and Update

also make sure your foldouts are inside an OnGUI() method

You’ve entered the code wrong.

In the example you’re supposed to inherit from EditorWindow. Neither of those methods come from MonoBehaviour.

2 Likes

I know it’s frustrating, I feel your pain, but the Unity API continues to evolve and expand, and stuff gets deprecated and obsoleted over time. There is no way for all tutorials and code snippets to ever be updated all at once, since they are scattered about the interwebs everywhere.

1 Like

@Rick-Gamez @Ryiah
thankyou
however it seems that it throws a error that it can’t convert method group to non-delegate type ‘FoldoutUsage’

@Kurt-Dekker
ya i know its is frustrating you think the unity developers could hire a team of people just to update the documentation
idk though

public class FoldoutUsage : EditorWindow{
    [MenuItem("Examples/Foldout Usage")]
    public static void Init(){
        EditorWindow.GetWindow<FoldoutUsage>();
    }
}

    void OnEnable(){
        //Called when the window starts.
    }

    void OnGUI(){
        //Your GUILayout  or EditorGUILayout code goes here.
    }

Well to be fair to Unity, in this case you used MonoBehavior instead of EditorWindow, which is the root of probably most of your current issues.

Edit: I just went and copy/pasted Unity’s FoldoutUsage example and it works precisely as indicated: makes a menu item under “Examples” and pops open a custom transform position inspector window.

Don’t get frustrated too easily in Unity because you’re coming into a MASSIVE system of amazing complexity and function. You can do almost EVERYTHING you could ever want to do in Unity… you just have to take the time to understand it, and that takes time.

1 Like

They do have staff for this very thing.

There’s a lot of documentation though… and sometimes it gets missed, or they just haven’t gotten to it yet.

I won’t lie, as a dev, I’d rather them release me new features and wait on documentation corrections, rather than wait on documentation corrections before I get my new feature release.

3 Likes

Yea I’ve been using unity for years and every time I work with it I learn something new. Patience is the key here.

1 Like

That’s part of the attraction: there is ALWAYS some new nuance to learn. Good stuff… easily the best engine out there for all-around good times game-makin’ fun.