Search Unity

How to make scene view pop up text.

Discussion in 'Editor & General Support' started by Shaba1, Aug 4, 2018.

  1. Shaba1

    Shaba1

    Joined:
    Jan 21, 2010
    Posts:
    63
    I am writing a script that has several public variables that the use must enter a value for BEFORE pressing play to go from the scene view to the game view. Normally when I write a script if I have an error in it Unity puts a message in the scene view that says something like" You cannot run this game until you fix all the compilation errors in the scripts" That is not the actual word for word text but something like that.

    My question is can I make my own custom text like that that will pop up over the scene view if the user fails to enter in a value for one of those public variable. I know i could just debug.Log("my error message") but that will show in the editor console and in the unity editor status bar. Which I think is not obvious enough. I know sometimes I forget to look at the status bar or the console. That is why I wanted something big and bold like that text that unity puts up when you have a compilation error. The will not apply to a running game only to people that want to use MY script in their game.
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
  3. Shaba1

    Shaba1

    Joined:
    Jan 21, 2010
    Posts:
    63
    Madgvox: Perfect that was exactly what I was looking for
     
  4. Shaba1

    Shaba1

    Joined:
    Jan 21, 2010
    Posts:
    63
    Madgvox: I read that page. But there are two problems:

    #1 the example that they use shows this image as an example.

    That looks like a tab that would normally be where the console window is or the asset folder is displayed.
    I wanted to pop up a notification in the scene view tab of the normal Unity 3d editor window. The same way you get the pop up text in the scene view window when you have scripting compilation errors.

    #2 The code example uses GUIContent() and GUILayout.Button(). I thought that all the GUI classes were deprecated?
     
    Last edited: Aug 6, 2018
  5. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    The undocumented class
    SceneView
    is what you want. It contains a static array of all of the sceneviews currently open. Call ShowNotification on the objects in that array.

    Only for runtime. The editor still runs off of the IMGUI system.
     
  6. Shaba1

    Shaba1

    Joined:
    Jan 21, 2010
    Posts:
    63
    Thanks. So Scenview.ShowNotification takes a string as an value? You say it returns and array Since this script will only work with one scene I should address array(0). If that is the way you access and array in C#. I come from a python and basic background. Is there a RemoveNotification method in that class?
     
  7. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    SceneView is an EditorWindow. It's the exact same method that I previously linked. The array is a separate static property on the SceneView class called
    SceneView.sceneViews
    .

    I think you're confusing terms a bit. SceneView is the class for the literal window in the editor titled 'Scene'. You can have multiple 'Scene' windows open at once. It's these windows that are populating the
    SceneView.sceneViews
    array. This is not the same thing as the concept of a scene file that you open in Unity.

    You would use it along these lines:

    Code (CSharp):
    1. foreach( SceneView scene in SceneView.sceneViews ) {
    2.   scene.ShowNotification( new GUIContent( /*your message*/ ) );
    3. }
     
    amesa_unity likes this.
  8. Shaba1

    Shaba1

    Joined:
    Jan 21, 2010
    Posts:
    63
    Madgvox: Thank you so much for responding to what must seem like stupid newbie questions.
     
  9. Shaba1

    Shaba1

    Joined:
    Jan 21, 2010
    Posts:
    63
    I have not tired the new functions that you mentioned yet. Real life has been keeping me busy. But I will in the next week. I just wanted to warn you to be prepared for follow up questions.

    Thanks again.