#↕️┃editor-extensions

1 messages · Page 8 of 1

lilac wave
#

all uniform now

tawdry kraken
#

What do you mean by this?

lilac wave
#

is there a way to avoid having to write EditorGUILayout.Space() everytime I want to add a space, can't it be shortened somehow

lilac wave
tawdry kraken
#

Yes, of course. It's automatically aligned. One of the better features in the system.

#

I'm not sure what else you'd want or why

lilac wave
#

I just wanted all labels to have a fixed size like above

#

which works now

#

just have to override it for each label 🤷‍♂️

tawdry kraken
#

This sounds weird.

lilac wave
#

why

#

if I set labelWidth they aren't all equally sized

tawdry kraken
#

and at that point, none of them have the GUILayout.Width() ?

lilac wave
#

yeah

#

wait lemme try it again

#
EditorGUIUtility.labelWidth = 80;
#

this line

#

results

tawdry kraken
lilac wave
#

might be messy

#

the way I understand it though

#

just because you reserve 80 pixels doesn't mean it won't be bigger

tawdry kraken
#

This following line inside OnGUI is a bit overkill.
Place it inside void OnEnable instead. Then it runs only once, instead of several times per frame.

_managerScript = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
lilac wave
#

ah

lilac wave
#

I wasn't aware onenable was available

#

yeah I had that tab open but didn't scroll down far enough

#

but yeah seems like I have to override all my labels manually

tawdry kraken
#

The mess between GUI and EditorGUI classes will easily make anyone's head spin.

#

It's an incredibly vague mismatch

lilac wave
#

well

#

I changed it to label fields and all

#

but now the width of my labels is the same, except I can't really change it

#

unless I missed something

#

actually the labelWidth thing doesn't seem to have any effect... 🤔

tawdry kraken
#

Well this is perplexing.
I have solved this in two projects before, but my initial tests right now cannot make it actually do anything.

lilac wave
#

did I miss anything

#

also in general how is the code structure

#

Curious, it does actually affect the width, but I can't seemingly get it smaller than what is shown above

#

but definitely bigger

#

ig for now I'll just stick to manually overriding them

#

probably gonna make a helper functio

hollow trail
#

I have created a property drawer to expose some variables of an object when its added in the inspector. This works when its a regular property, but if i add the object to an array it does nothing. Do i have to do something special for it to apply to lists?

tawdry kraken
lilac wave
#

i do have it in OnGUI

#

@tawdry kraken

#

but it does not work

#

I'll just use a workaround for now

#

🤷‍♂️

tawdry kraken
# lilac wave but it does not work

Doesn't work? What about what you said earlier?

it does actually affect the width, but I can't seemingly get it smaller than what is shown above

lilac wave
#

because it doesn't get smaller

lilac wave
#

the label I mean

tawdry kraken
#

Np

lilac wave
#

true

#

Fair point

#

this is what I wanted to achieve though

#

anyway thank you

#

tremendous help overall today

tawdry kraken
#

This is how you can make an array of GUILayoutOptions.
It's one of the more difficult to comprehend.

GUILayoutOption[] options =
{
    GUILayout.Width(10), 
    GUILayout.Height(10)
};

I don't use it at all, but from these issues I suspect you may find it useful.

tawdry kraken
lilac wave
#

Ahhh

#

That seems pretty good

#

I solved it like this for now

#

since for now I only have labels like this

#

and if I wanna change the width I don't want to edit 100 labels

tawdry kraken
# lilac wave

That's a good solution.
Alternatively:

private GUILayoutOption[] _width = { GUILayout.Width(10) };
//..
EditorGUILayout.LabelField(str, _width);
#

mostly useful if you're going to mix and mash layout options

#

@lilac wave Last thing, your Window needs better code to Open/Close correctly.
And perhaps a hotkey for easy access.
^ is CTRL

is Shift

& is Alt
_ is no modifier

private static bool _isOpen;

[MenuItem(" Tools / My Window _F12")]  // <-- no modifier F12 
private static void Window()
{
    _window = GetWindow<MyWindow>("My Window");

    if (_isOpen) _window.Close();
    else
    {
        _window.Show();
        _isOpen = true;
    }
}
private static void OnEnable()
{
    _isOpen = true;
}
private static void OnDisable()
{
    _isOpen = false;
}
visual stag
#

The Shortcut attribute is much improved and I wouldn't add shortcuts directly to menu items any more

tawdry kraken
visual stag
#

I'm not sure what you mean by the tooltip thing, but yeah that does suck. Personally it's a small price to pay for rebinding, conflict resolution, and a sensible attribute constructor. I'd love if they added it to menu items though

tawdry kraken
#

For large projects or collaborations, it seems a priceless tool.
For beginners, a bit impractical for the scope.

#

Thanks for making me aware. @visual stag

#

And for anyone reading, the docs are a bit unclear:

[Shortcut("Name in Shortcuts", KeyCode.F11, ShortcutModifiers.Control | ShortcutModifiers.Shift)]
private static void Example() //...

// Additional overloads
// Context: Only when this EditorWindow type is open. 
[Shortcut("Name in Shortcuts", context: typeof(EditorWindowTest), KeyCode.F11, ShortcutModifiers.Control | ShortcutModifiers.Shift, displayName = "Optional name in shortcuts")]
tawdry kraken
#

Ah, it is possible to add a shortcut to any existing MenuItem, including ones created by users. (Shortcut window)

visual stag
tawdry kraken
#

At least there's that :)

#

That probably means it's possible to use ShortcutManager.instance.etc to rebind all existing binds 🤔

#

Thus fixing that

visual stag
#

I imagine there's some specific combo of paths or something that would tie the menu item to the shortcut attribute. Maybe I'll look into it when I'm home

tawdry kraken
hardy needle
#

I hope this is the right place to ask this, but I am trying to find a way to edit the 2d animation package to fix a known bug, but every change I make reverts. I've been searching how to edit Unity packages, and the best thing I have seen says I have to remove the copy the package and edit the copy, but that would break everything else even if it did fix my issue 😄 anyone have a direction for me?

#

I'll keep asking around too. 🙂

tawdry kraken
hardy needle
#

seems like if they knew about it a hotfix could sew thing up quickly, but what do I know.

tawdry kraken
#

Only other thing I can consider, is perhaps giving your package a higher version number.
(I really don't want to bloat the chat any more than necessary.)

peak bloom
#

@north sphinx here

#

Either @gloomy chasm @waxen sandal can definitely answer your doubts here... I'm just an NPC regarding SOs as I'm not too fond about it

#

sorry being sus here 🤘

waxen sandal
#

If you have a domain reload then all instances get recreated (since well, the domain is unloaded so there's nothing left)

#

Not sure what you mean without domain reloads @north sphinx

north sphinx
#

I disable domain reload

waxen sandal
#

Are you seeing an actual issue or is this hypothetical

north sphinx
#

hypothetical

#

as of now I just unsub on every registered event

#

but it's kind of

#

doubles amount of code

waxen sandal
#

In that case you are responsible for cleaning up references and subscriptions

north sphinx
#

So SO C# objects are persistent between Play modes?

waxen sandal
#

I think there's no guarantee that they are destroyed but they might be in some cases

tawdry kraken
tawdry kraken
tawdry kraken
#

Ah, they are assets, so I don't believe they are destroyed.
But C# instance, I can't say 🤔

lilac wave
#

window gets closed instantly when I try to openit

dreamy grotto
#

hey i have a prefab and i change materials of gameobjects that gameobject has, lets say i have a level and i have 3 items in level. when i press button item colors changes. but i dont want this to be overriden. when i save the prefab and exit prefab mode i dont want this to be overriden

#

in this level prefab item colors changed if i save and exit prefab mode

#

basiclly i dont want this changes to be saved to prefab

#

is there a way to achieve this?

#

maybe a method from prefabutility

tawdry kraken
lilac wave
#

Yeah I might have forgotten something lol

tawdry kraken
lilac wave
#

I'll see how it is with the restart

#

it did not change

#

like it works once to open it, and when I close it then it won't open again

#

it works if I don't do add the onEnable/Disable

#

and handle the isOpen stat in the open function

tawdry kraken
# lilac wave and handle the isOpen stat in the open function

Pardon the late reply. Good that you made it work.
I'm not sure why you're experiencing errors with code which works for me, unless I'm messing up, or you're on a different version of Unity. I'm on 2021.3.
If you can bother, I would like to read the code which works for you.
Otherwise, good luck and have a nice day.

lilac wave
#

I can always bother

#

but tbh my unity has been wonky recently anyway

#

whenever I drag a script to a component it gets added twice, some gizmos are not displaying properly

tawdry kraken
#

What do you mean by 'added twice'?

lilac wave
#

2021.3

lilac wave
#

instead of just once

vital zephyr
#

I'm having trouble making a custom editor for a component. Here is my code (located in /Assets/Editor/)

using Levels.Game.Scripts.Environment;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(TimeOfDay)), CanEditMultipleObjects]
public class TimeOfDayEditor : Editor
{
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        GUILayout.Label("HELLOW!");
    }
}

But still the Inspector shows the normal editor (when it should show only the Hello label)

#

What am I doing wrong?

#

Nevermind i see that after compiling i must de-select / select the component before it will show up with the updates

abstract solar
#

Question: I want to have a button on a component that opens up a pop-up window for you to enter a value in, and then when you hit accept it closes the popup window and uses that value. How do I make a pop up window like that?

earnest talon
#

This is one of the few classes that allow you to make popup windows

#

Though a trade-off is you can't drag the popup around

abstract solar
snow pebble
#

if i have a base abstract class with a custom inspector - how do i get it to show with a derived class which doesn't have a custom inspector?

#

because it seems i have to make an editor script for every derived class to show the base class inspector which is ridiculous

#

all my base class does is show a label field

visual stag
snow pebble
#

i set that to true but it didn't show the custom inspector

#

[CustomEditor(typeof(ObjComponent),true)]

you mean this right?

#

when it is set to true all that changed was it showed a notice about multi object editing:

#

but doesnt show the base class inspector only the Condition class which is derived

visual stag
#

If you see the multi object editing thing without having multiple objects selected you should reselect it to fix the editor

snow pebble
#

ahh

#

so it is !

#

thank you 🙂

earnest talon
#

once you've changed the value, if the accept button is clicked then you do SerializedObject.ApplyModifiedProperties()

abstract solar
#

oi

earnest talon
#

Yeah?

abstract solar
#

What if I just passed a string back to a callback method? somehow?

earnest talon
#

Are you just trying to set a string value?

#

Is this for a game object - or is it for a ScriptableObject?

abstract solar
# earnest talon Is this for a game object - or is it for a ScriptableObject?

Could be either, but the most important is scriptable object. Basically, I have 2 scriptableobjects (that gameobject components depend on) that can connect to eachother by an ID. I want to make a popup on a custom inspector for the scriptableobject I've made that allows you to select another one from a list (Ive already written the list) and it will "connect" both by adding the ID references to eachother

earnest talon
#

Generic Menu is arguably more suitable to that task as that's all you need for the popup behaviour you're looking for.

#

You have to manually add each element though

abstract solar
#

I'll have to look at that

earnest talon
#

I have a method for it

#

I'm just trying to figure out the specifics

#

so, if you were to have say a list of objects - A, B, C, D, E and F

#

if you wanted to link A to C, you clicked on the option then A will be linked to C

#

and then C would link to A in return

abstract solar
earnest talon
#

I sent you a method for automatically laying out a dropdown in DMs because it's experimental and the documentation is a bit finnicky with it.

#

I'll try to help you as best as i can

dreamy grotto
#

Is there a way to only revert fbx overrides?

#

this reverts everything

glad cliff
#

Is it possible, and if it is, how to implement somewhat of a custom component system? I wanna make some state machine creator with xNode framework and I wonder how to achieve funcionality implemented in AnimatorController, where to every state you can assign StateMachineBehaviour class, just like a MonoBehaviour to any GameObject. I already peeked a bit into AnimatorController source code, but it is a massive chunk of not commented code that I dont understand at all. All I got from it is that StateMachineBehaviour class derives from ScriptableObject and is somehow "converted" into what it is, but that is all that I uderstand unfortunatelly.

snow pebble
#

how do you get a dictionary in a custom editor so you can iterate its keys/values? i tried serialized property but i cant figure out from there how to get the data back to the type i want

gloomy chasm
snow pebble
#

well i also tried reflection but thats giving me problems too

gloomy chasm
#

What are you wanting to do?

snow pebble
#

oh it suddenly decided to work

#

i just wanted to text output the dictionary

#

reflection did the job

#

seems reflection is a lot simpler than unity's serialised property nonsense

#
var result = typeof(TestObj).GetField("_test", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(target) as Dictionary<int, float>;
foreach (var kvp in result)
    Draw(kvp.Key, kvp.Value);            

was how i got it to work

placid rune
#

how could i make it to where, let me explain in simple (ish) terms:

i have a WeaponSystem script.
i want to have custom values i can edit based on what Round Type i choose
for example, if i chose "shell" it would only show up shotgun settings.
how would i go across doing this?

snow pebble
#

im confused how do i change a field from serialized properties? I have in my scriptable object:

[SerializeField, HideInInspector]
    Color _pathColor;

And then in my editor class i have:

var c = serializedObject.FindProperty("_pathColor");
c.colorValue = EditorGUILayout.ColorField(c.colorValue);```

but this doesn't seem to work how do i make sure it applies to back to the field `_pathColor` in my scriptable object?
#

very confusing api unity have made for this

tawdry kraken
tawdry kraken
peak bloom
snow pebble
#

thanks ! docs dont make this easy to find ! 😄

tawdry kraken
snow pebble
#

yeah though a lot of their code examples dont cover much or explain much

#

i had to dig deep into the forums to figure out how to click in the editor window without losing focus in inspector on my scriptable object

tawdry kraken
#

On some of that, I would agree, but the more I learn, the more the docs make sense.

tawdry kraken
snow pebble
#

i meant for selecting things in the scene window

#

if i clicked to select a node it would defocus the scriptable object in the inspector lol

#

was a pain

tawdry kraken
#

exactly, you can either Lock the inspector, or have a Properties window

#

What solution did you come up with?

snow pebble
#

apprently adding this:
HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive));

before you use the event fixed it

tawdry kraken
#

Interesting.

snow pebble
#

now i can add nodes and it wont lose focus

tawdry kraken
#

That's handy.

snow pebble
#

yeah!

snow pebble
#

is there a way to call an editor function from another editor script for example a player references a scriptable object, now i want the scriptable object's path to be drawn in the editor when i select player which is a method in the scriptable object's custom editor

tawdry kraken
#

or do you mean File Path to the asset?

snow pebble
#

Player has a reference to scriptable object Path @tawdry kraken when you select SO Path it shows the path in the scene view, but i need it to also show when i select the Player which has a reference to that Path

tawdry kraken
snow pebble
#

to show the path in editor?

tawdry kraken
#

How does it show the path in the scene view?

snow pebble
#

i have a method in PathEditor : Editor which draws on SceneGUI:

                for (int i = 0; i < points.Count; i++)
                {
                    var point = points[i];

                    if (_modifyIndex == i)
                    {
                        Handles.color = new(1, 1, 1, .3f);
                        Handles.DrawSolidDisc(point, Vector3.up, .55f);
                    }

                    Handles.color = _colorProperty.colorValue;
                    Handles.DrawSolidDisc(point, Vector3.up, .5f);


                    var pos2D = HandleUtility.WorldToGUIPoint(point);
                    var rect = new Rect(pos2D.x - 60, pos2D.y - 10, 120, 20);

                    Handles.BeginGUI();
                    Handles.DrawSolidRectangleWithOutline(rect, new Color(0, 0, 0, 1), _colorProperty.colorValue);
                    GUI.Label(rect, _target.PathName + " -> " + i);
                    Handles.EndGUI();
                }
#

looks like this

#

this is when the SO is selected

#

but i need the path to also show now when i clicked the object that has been assigned this path

tawdry kraken
#

I would imagine something like
That code segment should be a public method.
Make a custom editor for the Player (or use a different approach)
so that when the player is selected, it executes that public method.

snow pebble
#

is it possible for PlayerEditor : Editor to access PathEditor class from the player's reference of the Path class?

#

i get the impression it isn't possible

#

because Path doesn't have a reference to PathEditor

tawdry kraken
#

If you can move the logic to the static, I believe it should be possible that way, but I have not actually done this before (with custom editors).

#

Do you have a firm concept of how static works? @snow pebble

reef hornet
#

Hi there (dunno if this is right here to ask)
does anyone know how to use a custom property drawer inside a custom editor script?

wise forge
#

Custom property attribute doesn't work (help)

errant shale
#
  • If it's valid to ask about custom tools here, are there any manuals out there on how do i add interactive gui elements to my objects? In a nutshell, i make an alternative resize tool, being able to expand and contract my "object". I'm a complete beginner to this and i struggle to find anything related to this, probably because of my poor terminology
earnest talon
#

This is a problem I encountered with my own custom AI regions system in university.

#

What you would do is have: ```c

// In selection hierarchy if you want to have it display when the object attached to a path is linked
[DrawGizmos(GizmoType.Selected | GizmoType.InSelectionHierarchy)]
public static void DrawAssignedPath(yourObjectType t, GizmoType gizmoType)
{
// ... Path Drawing Code here for Gizmos ...
}```

#

This attribute is able to work in editor scripts.

#

this is the attribute in action with my AI path system (ignore the UI, it was placeholder by another student in our team project)

errant shale
#
  • I managed to make a resize tool with 4 ScaleSlider handles around it. It invokes a method of the edited object directly, passing the drag value in there. So it's first 1, then 2 and so on. This makes my object expand by 1, 2, 3 etc. grids, and this causes my object to scale way faster than the cursor tells it to. How can i work it around?
snow pebble
#

@earnest talon@tawdry krakenah i had a suspicion i would have to use statics - okay i will go for that then, thanks!

snow pebble
#

How do i use enums with serialized properties? I tried this:

_typeProperty.enumValueFlag = EditorGUILayout.EnumPopup("Type: ", _typeProperty.enumValueFlag); 

but it seems to not like it im not sure how to do it correctly

meager reef
#

So how do you get editor variable fields to display in the Inspector, as opposed to an existing custom window?

peak bloom
#

how can I display OnInteractivePreviewGUI in a VisualeElement (uitk) container?

visual stag
peak bloom
#

oh I forgot IMGUIcontainer exists blushie

barren moat
#

When creating a new asset, Unity will automatically rename it to prevent duplication. AssetDatabase.CreateAsset will silently overwrite an existing asset if you give it a path that already exists. Is there a function I can call that will give me a path that doesn't conflict (by adding the correct number to the end)?

#

for example:

barren moat
#

But that's for scene names?

#

oh, list of existing names...

#

Okay, so I can load all assest in a folder and check

tepid bramble
#

Is it possible to make a scriptable object numeric, dynamic ID system?
e.g I create a new object, which auto generates a readonly id which equates 64, because there have been 63 other objects of that kind.
Is there any way to cache a variable into the unity editor?
Then, on validate for my scriptables, I could just assign the id based on the cached count.

frozen perch
#

I'm having a teeny issue. I'm trying to get a struct to have a custom editor, but all I'm getting is a "No GUI Implemented" message. It works for other elements that I have made, so I'm scratching my head as to why this does not work

#

In this example, Level is of the Stat_int type

frozen perch
#

I have found my answer 😄

gloomy chasm
tepid bramble
#

@gloomy chasmThank you!!

hybrid yoke
#

Anyone know how I could insert the custom editor buttons along side each element?

fierce cave
#

Hi there!

I'm having trouble with my editor preview system. Whenever i set a color on the same sprite on two custom tile the colors merge I have provided in the video what is happening, here is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Tilemaps;


[CustomEditor(typeof(LevelTile))]
public class LevelTileEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
    }

    public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
    {
        Tile Target = (Tile)target;
        if (Target.sprite != null)
        {
            Texture2D newIcon = new Texture2D(width, height);
            Texture2D spritePreview = AssetPreview.GetAssetPreview(Target.sprite);
            Color[] pixels = spritePreview.GetPixels();
            for (int i = 0; i < pixels.Length; i++)
            {
                pixels[i] = pixels[i] * Target.color; // Tint
            }
            spritePreview.SetPixels(pixels);
            spritePreview.Apply();
            EditorUtility.CopySerialized(spritePreview, newIcon);
            EditorUtility.SetDirty(Target);
            return newIcon;
        }
        return base.RenderStaticPreview(assetPath, subAssets, width, height);
    }
}

Thanks!

fierce cave
#

pls

fierce cave
#

anyone

next robin
fierce cave
#

Thanks!

#

But yeah, kinda like that

next robin
#

To resolve it, I made a copy of the current assetpreview texture which I saved in a new Texture2D, this way there is no way the texture is applied globally to all previews.

fierce cave
#

Now all i need to do is finish replicating all the tile editor formatting stuff 😅

peak bloom
#

How can I zoom in/out OnInteractivePreviewGui? ... pretty sure we can do this by default when previewing in inspector but when put in a IMGuiContainer just the model being shown

var t = new IMGUIContainer(() => edtr.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(prevWindow.contentRect.width, prevWindow.contentRect.height), bgColor));

I can manipulate the Rect for zooming in/out but still looking for a built in solution if any

peak bloom
#

aight, seems like OnPreviewSettings is what I'm looking for

full badge
#

How do I save a sprite generated in the editor to asset folder?

barren moat
full badge
#

Yeah

#

I figured it out though

barren moat
#

Nice.

#

In the past I have output it as a PNG

#

Using System.IO to actually save it to the file I want

#

There might be a better way.

gloomy chasm
#

(In case that isn't the way you figure out)

earnest talon
gloomy chasm
#

Indeed!

earnest talon
#

One thing I'm looking to find is if I can forcefully set the background of the editor window element itself.

gloomy chasm
#

What do you mean?

earnest talon
#

To directly change the GUIStyle that an editor window is created with

#

instead of having it in the default, usual grey

#

changing it to be, say, transparent

#

or cache the screen

#

one of the two would work.

gloomy chasm
#

No, there is no way to make a editor window transparent.

#

I have tried a lot 😛

earnest talon
#

well then I'm thinking

#

Cache the screen

#

and use that as an overlay for a draggable windows HUD, of sorts.

#

I know we can make draggable windows but the limitations of events isn't good.

gloomy chasm
#

Can you explain what you are wanting to do?

earnest talon
#

Create a popup window with a semi-transparent overlay so I can create a grid which I can use to provide developers with the means of creating draggable, borderless windows in an overlay.

#

I've seen caching the screen done before, for a contained editor window

#

and if that's possible then you can for sure do it for popups

#

only reason to do this route is because, even with draggable windows without such a technique the means to handle mouse dragging stops if the mouse cursor falls out of the editor window itself

#

meaning you can't actually take into account editor window offsets based on cursor position

gloomy chasm
#

Oh, wait so you just want it for your own window, not every/any window?

earnest talon
#

yeah

gloomy chasm
#

OOOH

earnest talon
#

What I want is

gloomy chasm
#

That makes it way easier!

earnest talon
#

Unity Editor stays the same

#

we don't touch that

#

that would be a bad idea

#

very bad spaghetti code idea

gloomy chasm
#

There is an article on it

earnest talon
#

thanks, that helps a lot.

#

My reason for this

#

is I'm building an Editor Framework

#

I've got a 1.0.0 done and I'm doing documentation for it actively

gloomy chasm
#

I thought you were wanting it to be for any editor window. And that would require a bunch of reflection and stuff. And even then it would be iffy.

earnest talon
#

It's nothing fancy, I'm building it so others students at my university can get an easier introduction to Editor Windows.

gloomy chasm
earnest talon
#

but it's basically a lot of simplified nomenclature and stuff that abstracts Unity's IMGUI-style editor window creation (for context on why I deleted the image, just got a message to delete it from someone else - not moderators/unity staff)

gloomy chasm
#

Ooh, very cool!

earnest talon
#

(also I'm fine with my uni being known for various reasons, this would be in the final publication anyway)

gloomy chasm
#

If you can I would look in to UIToolkit, probably be easier to learn for some people!

earnest talon
#

I considered it

#

only issue is

gloomy chasm
#

Also, IMGUI is going the way of the doe doe (at some point)

earnest talon
#

some of the versions of Unity our uni uses

#

isn't compatible with UI Toolkit

gloomy chasm
#

Ahh

earnest talon
#

I'd immediately say

#

deprecating IMGUI for editor windows is a bad idea

#

It's definitely the most accessible way for programmers (or ones that I've shown it to, now they understand it)

#

some of the stuff I added into Cappuccino are personal taste, others are more broader-reaching

gloomy chasm
#

I mean, IMGUI isn't going to be deprecated. It is used in far too many assets and projects. But all of the default editor is being rewritten to use UIToolkit.

earnest talon
#

ah fair

#

that's good

#

here's one of the things I've added with Cappuccino

#

A property wrapper

#

allows me to create (kinda) serialized properties, directly pull the value as a cast-necessary object

#

and find underlying properties directly w/o FindPropertyRelative

#

there's also extensions, hence the partial

#

Array Handling, CProperty.Draw (simpler than EditorGUILayout.PropertyField in a lot of ways but just uses that & EditorGUI.PropertyField)

gloomy chasm
#

I see... well whatever works for you!

earnest talon
#

yeah it's definitely not the best in some regards

#

other regards ofc being more personal opinion

#

thanks a lot for the screen capture article though

#

that's going to be extremely helpful for creating the first extension for this framework

earnest talon
#

by far the most creative error I've ever seen in unity.

gloomy chasm
#

LOL

earnest talon
#

I did get it working before, mostly

#

just decided I wanted to capture the whole screen

#

Turns out 128GB might not be enough for over 8 million pixels worth of colors.

simple cove
#

anyone tried UIElements? looking for feedback on if u liked it and why
looking to set up editor stuff soon and I'm already quite familiar with the vanilla way.. wondering if it's worthwhile going with UIElements instead for w/e reasons

waxen sandal
#

If you just want to hack something together go with imgui

#

Need to maintain it longer? Go with uie

earnest talon
#

I'll just say

#

UIElements is practically what happens when Unity butchers web-dev languages.

#

As much as I can understand why they went for it and why it's a more native layout language

#

It just won't surpass IMGUI in terms of legibility a lot of the time.

simple cove
earnest talon
#

With UI Elements, you're dealing with (Essentially) forked CSS & XML

waxen sandal
earnest talon
#

Well, complex editors can be easier to maintain

#

with just a good file structure

#

an some basic housekeeping

#

I use a practice of "Editor" and "Panels" layout, where Editor Windows and each subsequent attached panel are separate

simple cove
#

the project is some quite complex (hoping to simplify over time via design iterations) visual scripting

earnest talon
#

the Editor just being a container

#

You using GraphView Lyrcaxis?

simple cove
#

no, I'm a vanilla guy

earnest talon
#

ah

#

guessing you're not much for experimental stuff

simple cove
#

everything is pretty much copy-pasteable to Unity 2017 😛

earnest talon
#

still experimental for god knows how long

#

I'd be surprised if there's any devs working on Unity 2017 nowadays

simple cove
#

yeah I sticked with Unity 2017.4 until unity 2021.3 was here 😄 REALLY not much for experimental stuff 😄

earnest talon
#

The way to put unity and experimental stuff into context

#

the entire engine's experimental.

simple cove
#

oh well the stability and performance makes up for it in every way

earnest talon
#

They've left GraphView on experiemental for years

#

and I don't know if they just forgot a few years back to remove the experimental tag

#

or they just forgot to finish it

simple cove
earnest talon
#

go IMGUI

simple cove
#

no I'm with 2021.3 now

earnest talon
#

well then there's no concern really

#

you can do either/or

waxen sandal
earnest talon
#

I'd argue IMGUI purely for legibility (provided you don't write code without comments and follow some sense with structure)

#

and for backwards-compatibility.

#

UIE is basically butchered web-dev crammed into the engine

#

UIT barely works on earlier verisons of unity because it was designed for later ones

simple cove
#

what is UIT?

earnest talon
#

UI Toolkit

#

Without a doubt though, IMGUI is probably one of the best GUI creation toolkits I've ever seen for a game engine

#

purely for how straightforward it is.

simple cove
#

I totally agree

earnest talon
#

if you're a programmer and you have a grasp for what Rects and Vectors are

#

as well as a basic understanding of "sprites" (kinda), you're able to pull off LOTS of crazy stuff with IMGUI that just

#

you can't really with others

#

IMGUI is just that flexible and powerful.

simple cove
#

ikr lol.. UnityEditor.dll in general is so OP

#

and UnityEngine.dll is just simple.. which can be good as well

earnest talon
#

the fact I can do all this in IMGUI

#

and still understand every line of code

#

it's way better.

#

I'd say for sure UI Elements is a good inclusion into the engine

#

It'll enable web-developers to start getting involved with toolkit creation

#

but there's nothing that compares to the careful management you can obtain with IMGUI

simple cove
#

btw are GUI calls also considered IMGUI?

earnest talon
#

yeah

#

Immediate-mode GUI

#

all that's just done via Handles (in the scene view)

#

I just like to include extra wrappers like this personally

#

pretty much how that handles GUI works.

simple cove
#

cool!

earnest talon
#

I would have an aneurysm trying to exploit the way editor windows are created

#

if I were ever forced to use UIE for it

simple cove
#

I'd imagine the only difference in UIE would be the design of the layout stuff.. Like literally expecting to use it in editorWindows like so

override void OnGUI() => UIE.EmbedLayout("..somepath", context: this);
gloomy chasm
simple cove
#

either, but I'm mostly interested in the maintaining part

gloomy chasm
earnest talon
gloomy chasm
earnest talon
#

considering the amount of people who experimented with, well, experimental tech

#

It'd make at least some sense to keep it in

gloomy chasm
earnest talon
#

when it comes to UI Elements though, I don't think it's easier to maintain for everyone

#

USS and UXML are forever web-dev language forks

gloomy chasm
#

Also, they have stated repeatedly that IMGUI (and UGUI) is going to be replaced with UIToolkit. It is quite literally the reason they made it. They are working on rewriting every editor window currently. The inspector, and sceneview have already switched over. I know they are working on the Hierarchy, and I think they said they are rewriting all of the custom editors as well.

earnest talon
#

for some reason it just force CTD's Unity Engine every time you try use the package.

#

(Unity 2020.2/Unity 2020.3 is the versions this is happening in)

earnest talon
#

Crash to Desktop

#

Unity 2020.2/2020.3 just doesn't like UIToolkit

#

maybe it's some patches more than others but some of us have had our projects corrupt because of it

#

(which is probably in part due to the PC security too)

gloomy chasm
#

Ehh, that is odd. 2020.3 works fine for me. I have developed an asset on that version that makes heavy use of UITK.

earnest talon
#

reading more about Unity's documentation for UI

#

it seems they take a more nuanced approach on who should use UI Toolkit (or rather who it's most suitable for)

#

and I'm guessing it's all based on preference given their considerations in the manuals

gloomy chasm
#

Which version are you looking at? Also, their runtime and editor UI recommendations are different.

#

For the editor, they recommend UITK now

earnest talon
#

2020.3, 2021.2, 2021.3, 2022.1, 2022.2, 2023.1

#

and yeah I can see why they recommend it

#

and I've been reading carefully about it

#

For the use cases and structuring I follow

#

IMGUI is better

#

that and I don't like doing web-dev-like code because it's just annoying with tags.

simple cove
#

anyone knows if and how would I be able to suppress this warning in specific cases? (e.g.: when [SomeAttribute] is applied to something)

tawdry kraken
#

Is it enough to manually write the workaround each time?

simple cove
#

no, lol.. I want a solution that just works

#

prepared to add an analyzer if no solutions are found.. would just like to avoid that for some extra performance in compilation

tawdry kraken
#

Do you know how to suppress warnings in general?

simple cove
#

yeah in either a per-case context or a global context.. I just want to get rid of the false-positives tho -- specifically to events I apply the attribute on

tawdry kraken
#

Hm. Why does this error appear?
Why is there an event which is not being used?

#

I'm not trying to be coy. I am looking for the phrase for something I think might work.

#

Meanwhile, I wonder what could identify if it would not be used

#

But it's a compiler-level thing, so I'm not sure if that would make sense even if it was possible

simple cove
#

I'm using the attribute to scan usages via reflection, and inject on them -- so the events are used, but as far as the compiler can tell, they aren't

tawdry kraken
#

Would it cost you to write it so that it is being used?

#

My search yielded no results.
A pragma warning disable is the normal way to deal with this issue.
I'm not aware of any other ways. There could be a VS Extension for it.

simple cove
#

you mean instead of using reflection for invoking it? or create a dummy class that just accesses it?

tawdry kraken
#

There is actually a function in Unity's documentation named DoNothing() {}

simple cove
#

well I would consider invoking it to another dummy class, but it's an event, only invokable by the class that hosts it

tawdry kraken
#

child class then?

simple cove
#

and I REALLY don't wanna add a random unused function to all the classes that use that attribute

#

still not possible. events are only invokable by the class that hosts them

#

I could potentially just discard the event keyword as last resort lol.. but curious on how one'd go for it normally

tawdry kraken
#

Does the event have to be used in that manner?
What if you just print the name of it, so that the variable itself is in use?

tawdry kraken
simple cove
#

these wouldn't work either -- the warning won't go away unless there's an .Invoke() call of some sort

tawdry kraken
#

Well, last idea I have is you could write a VS Snippet to encapsulate existing code in a pragma warning disable

#

would be fast and translate to any other project

simple cove
#

I'll give it a day and decide tomorrow whether I wanna just go for an analyzer or completely rewrite the architecture lol

#

thanks! was good crossing out all potential solutions and getting feedback

tawdry kraken
hybrid yoke
#

Anyone know how to input editor buttons within a class drop down?

#

like if you make a custom class that's serialized so it's viewable in the editor, and then want to make a custom button within that default drop down menu, how would you do that?

hybrid yoke
gloomy chasm
hybrid yoke
#

You sure? Cause one of the tutorials I'm looking at calls it a custom property drawer, and im used to putting the buttons in custom editors

gloomy chasm
#

It is a custom property drawer. When you do EditorGUILayout.PropertyField(myProperty) that is basically just calling the custom property drawer's OnGUI method.

hybrid yoke
#

Interesting, I'll definitely play around with it and thank you for the tip

barren moat
#

Should I be concerned about this?

Child GameObject 'Wall_Narrow_Block(Clone)' was not registered into undo system and became dangling during an undo operation.
Use Undo.RecordCreatedObject to correctly add a child GameObject which can be handled by the undo system

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler ()
#

I have registered every object with the undo operation, but I think repeated creation + destroy of objects during the same undo step is causing issues.

simple cove
#
  1. it's annoying to see a warning
  2. you might wanna actually undo at some point
#

I'd say go for a single undo addition per mouse release, instead of when merging blocks / on SceneGUI or smth

barren moat
# simple cove yeah you should fix it imo

There is only one per mouse release, the problem is that as the mouse is moving it's creating and destroying many objects (at least that's my assumption as to what is happening).

Perhaps I can keep track of the first round of deletions and the last round of additions. I'd need to somehow get the release event to submit them, which I'm not sure I can get from a drag handle.

simple cove
#

no you should just not delete them until the mouse is released -- imo

#

-- mark them for deletion, then mass perform OnMouseReleased with a single undo

#

can 'hide' the 'marked-for-deletion-objects' if this sort of thing is THAT important. I'm usually marking them with red and fading their alpha while keeping them in some list

#

or, well.. if it's a grid thing in which you know no more than 1 objects will be on that specific grid cell at the same time, then deleting real time and forgetting is an option

barren moat
#

But if I can somehow get an event for when the handle stops moving I could do something like that

#

But it's kind of just called once per frame so I'm not sure how I'd find it when it ends

#

I'll have a think about it. There must be some way to do it.

gloomy chasm
barren moat
gloomy chasm
#

Kind of a long shot but I will go ahead and ask here.
I have a method that creates VisualElements for each item in a list and 'binds' their value to the expanded state of a the serialized property. However the expanded state is not keeping for all of them.

foreach (SerializedProperty fxItemVariableProperty in fxItemsProperty)
{
  var headerFoldout = new ScatterFXHeaderFoldout();
  headerFoldout.value = fxItemVariableProperty.isExpanded;
  headerFoldout.RegisterValueChangedCallback(evt => {
    Debug.Log($"Set {fxItemVariableProperty.propertyPath}, to: {evt.newValue}, from: {fxItemVariableProperty.isExpanded}");
    fxItemVariableProperty.isExpanded = evt.newValue;
  });

  // Other stuff here...

  _fxItemsContainer.Add(headerFoldout);
}

Here is the inspector that it creates. Note that the two expanded items are set to "preset", and they are numbers 3 and 4. Only when things are set to "preset" are the expanded state saved for some reason.
Additionally, you can see the debug.log message that is sent when you select a the Scriptableobject that the editor is for. You can see that neither 3 or 4 show up. It spams the value changing 10 times for each other item (weird UITK thing?) and it oddly sets the to true a couple of times. Any ideas?

barren moat
#

It seems that the change check returns false during the drag

#

Basically my problem is this: I'm dragging a wall around using handles, and generating blocks to fill out its length. They get created and destroyed during the drag. I want to be able to undo this operation afterwards, but I get a warning about dangling references if I both add and remove the same prefab instance during the same drag operation.

visual stag
barren moat
#

lol tried to make a video

#

Obtained 35 stack frames
0x00007ff7d4125381 (Unity) DestroyOrphanedObjectHierarchy
0x00007ff7d4124618 (Unity) DestroyOrphanedChildrenAndComponents
0x00007ff7d4122b19 (Unity) StructureUndoBase::ApplyInternal
0x00007ff7d41345c0 (Unity) ObjectUndo::ApplyUndo
0x00007ff7d4134f7c (Unity) UndoManager::ApplyUndo
0x00007ff7d4140f02 (Unity) UndoManager::Undo

#

Yep, this does seem bad.

#

Does Undo.RecordObject include its child objects and components?

gloomy chasm
barren moat
#

Cool. Okay... So I feel kinda stuck with this, but I know there must be a way.

visual stag
gloomy chasm
visual stag
#

so you could click the button, which sets header toggle, which sets value, which sets header toggle twice... it's a lot

#

if you set you set value, which calls _headerToggle.value, which then calls value again the first time I think, and then you have it running twice

#

value should definitely be using _headerToggle.SetValueWithoutNotify, and so should SetValueWithoutNotify

gloomy chasm
visual stag
#

I can't really think of why it would do that, but I can only imagine that your logic is setting the toggle or value somewhere else, or perhaps some logic is the inverse of what you think it is, like a toggle appears expanded but returns false

gloomy chasm
visual stag
#

I haven't seen any pooling logic, but if there is any that sounds like a point of concern for sure

indigo pilot
#
        public static void GenerateAgentTypeNamesEnum(string path, string enumTypeName, string namespaceString)
        {
            int settingsCount = NavMesh.GetSettingsCount();

            if (settingsCount <= 0) return;

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"namespace {namespaceString}");
            stringBuilder.AppendLine("{");
            stringBuilder.AppendLine($"\tpublic enum {enumTypeName}");
            stringBuilder.AppendLine("\t{");

            for (int i = 0; i < settingsCount; i++)
            {
                string agentTypeName = NavMesh.GetSettingsNameFromID(i).StripSpaces();

                int agentTypeID = NavMesh.GetSettingsByIndex(i).agentTypeID;

                stringBuilder.Append($"\t\t{agentTypeName} = {agentTypeID}");

                if (i < settingsCount - 1)
                {
                    stringBuilder.Append(",");
                }

                stringBuilder.AppendLine();
            }

            stringBuilder.AppendLine("\t}");
            stringBuilder.AppendLine("}");

            File.WriteAllText(path, stringBuilder.ToString().TrimEnd());

            AssetDatabase.Refresh();
        }
    }

For some reason this is not giving me agent names beyond the first one.

#

This is what it produces:

#
    public enum AgentTypeName
    {
        Projectile = 0,
         = -1372625422,
         = -334000983,
         = 1479372276,
         = 65107623,
         = -629701670
    }
#

Strange and confused

#

Nvm I was dumb, it expects ID instead of Index

velvet aurora
#

Hey all! I'm trying to make an extension for the editor for a project im working on, and while the extensions works fine...ish, it's not creating the asset due to the asset's class being abstract. How can I make the asset with it being abstract? Code is at the pastebin below

simple cove
#

what you should be doing instead is to change the definition of the method to this: static void CreateBlankCard<T>(T CardTemplate) where T : new(), CardTemplateSO
..and find the proper type to pass as T (e.g.: var x = ScriptableObject.CreateInstance<EnemyCardTemplateSO>(); CreateBlankCard(x);)

velvet aurora
simple cove
#

any questions let me know 😄 idea is that whatever object you pass in the parameter CardTemplate, will be used to assign the generic Type of the method

#

so if you do this: var x = ScriptableObject.CreateInstance<EnemyCardTemplateSO>(); CreateBlankCard(x);, you're actually invoking CreateBlankCard<EnemyCardTemplateSO>(x)

#

aannd.. the where T : new(), CardTemplateSO part is there to make sure you can only use non-abstract types that derive from CardTemplateSO to invoke it

velvet aurora
#

so im trying to run the method when the gui button is pressed, but I can't figure out what I need to put for it. All i've got is


CreateBlankCard(CardTemplate)

}```
simple cove
#

you check if cardTemplate is not null and then invoke the method with a completely different variable CardTemplate? 😛

simple cove
#

in place of EnemyCardTemplateSO you just have to specify a type that is not abstract and inherits from CardTemplateSO

#

like

public class DummyCardTemplateSO : CardTemplateSO { }
soft zenith
#

Hi, i'm doing a custom editor window for my Sprite Animator, how do i create a preview like this ?

#

so i can put in here >

burnt dove
#

Question, given a path, how can I know it's from an scene and (if so) how can I read the scene to iterate its content?
A simple AssetDatabase.LoadAllAssetsAtPath(path) fails

gloomy chasm
burnt dove
#

Is that path an scene?

gloomy chasm
#

Check the file path for a .scene extension?

#

Or better yet AssetDatabase.GetMainAssetTypeAtPath(someAssetPath)

burnt dove
#

But then, how can I get the root gameobjects of the scene and other assets stored in that scene (i.e: scriptable objects)?

gloomy chasm
#

What are you trying to do?

burnt dove
#

It's a bit complicated, but I'm opening all prefabs and all scenes, then iterating over all components and scriptable objects, and the through reflection, traversing all the possible paths.
Basically, I want to reach all the objects which are reachable...
Then, for each one of this objects, I check if they implement a custom interface of mine (and/or if the field which contained them has a custom attribute) and do some custom logic with that.

gloomy chasm
#

It is multi-threaded

burnt dove
#

Editor only

#

Didn't know about Unity Search.
I'll take a look.
Thanks

full moat
#

@sleek island Stumbled across your post from April of last year here while searching how to do exactly what you were trying:
https://forum.unity.com/threads/draw-a-curve-graph-in-the-inspector.1168892/#post-8090540
It sounds like you succeeded at implementing, so I'm trying to give it a go. The pieces are mostly there but just a bit incomplete. It doesn't help that I've always relied on Odin to make custom inspectors... this isn't my forte.

I don't have any console errors and it appears that the custom drawer element is there, at least according to the UI Toolkit Debugger, but I don't see it. Anyone have any ideas what I'm missing? I assume there's nothing wrong with the CurveDrawerElement.cs or ParametricCurve.cs as I copied those exactly... I built this editor script CurveEditor.cs and perhaps I'm missing something to make this display 😵

sleek island
#

I would suggest maybe try removing the whole OnInspectorGUI block from your CurveEditor.cs, as this is only for the legacy UI system

slender sandal
#

why does this text box get weirdly cut off?

full moat
#

I was monkeying around in the UI Builder and I can see what it's supposed to look like in there:

sleek island
#

Back when I did this, I'm not sure I ever attempted to draw it in a custom inspector. I managed to make it work in UIBuilder but I gotta admit I'm not sure what's missing to make it work in inspector

full moat
#

Ahh, okay. So if I want to follow in your footsteps on this one, I should spend some time learning UIBuilder?

sleek island
#

It should be possible to make it work in the inspector I would guess. Maybe a good first step would be to draw a simple box in your custom inspector, and once you have this working, try to switch it up with the CurveDrawerElement

#

(it's been a long time since I attempted editor UI programming, I unfortunately can't be of much help)

full moat
#

For sure, I appreciate the attempt all the same! ;D

slender sandal
full moat
gloomy chasm
slender sandal
#

Can the ui toolkit allow me to make ui and turn it into code for the next he ongui function?

slender sandal
#

@gloomy chasm instead how can I use a uxml file or uss?

#

if so do you have a tutorial?

#

like I found this https://www.youtube.com/watch?v=J2KNj3bw0Bw but i can't really understand it

Like building your own UI tools? Here we go step by step with the UI Builder to quickly create an Inspector for real-time Play mode debug data visualization. Then we’ll enhance it using USS Transitions and the Vector API, migrate it to a custom Editor window, and finally port it to the Player/Runtime.

Learn more about the UI Toolkit: https://on...

▶ Play video
slender sandal
#

Ok well I found out how to do it with gpt but how can I make the ui scale with screen size basically that option in a canvas

simple cove
#

anyone ever bothered trying to retrieve XML documentation in editor?
like display it in an editor window or smth

halcyon panther
#

Hello guys, I am playing around with GraphView and i am just curious - how to change the icon of the port to yellow square like this? (as default it is circle):

wise forge
#

I need some help understanding why custom propertyattribute is behaving like it is

gloomy chasm
gloomy chasm
soft zenith
#

Hi people, i have a custom editor window, and upon opening that window i get the reference to a serializedobject, the problem is whenever a recompile happens it loses reference to that object, how to avoid that ?

#

here's the code

gloomy chasm
#

Make sure to mark the field in the window as [SerializeField]

soft zenith
gloomy chasm
gloomy chasm
#

yup

soft zenith
#

it's giving me an error: ArgumentException: Object at index 0 is null

#

for some reason the "_spriteAnimationObject" is always null by doing this

#

nvm, fixed it, thank you very much for all the help

meager reef
#

What's the best way to assign a texture to an editor GUI object. Since it's a static editor window, I don't exactly want to have texture references to assign

gloomy chasm
# visual stag I haven't seen any pooling logic, but if there is any that sounds like a point o...

Hey, so I sort of figured it out. It looks like it is Unity being dumb. I switched out my header foldout with the unity foldout.
The issue seems to be some sort of binding issue. If I add a field that is bound to a bool as a child of the foldout. If the bound bool is true, than the foldout's expanded state will be true. It cannot be false, however it can be expanded without the bound bool being true.
And binding a child to the custom class causes it to have the behavior I was having originally.

gloomy chasm
meager reef
meager reef
# gloomy chasm Share the code?

Texture2D transitionArrowTexture => (Texture2D)AssetDatabase.LoadAssetAtPath("Scripts/State Machines/directional arrow.png", typeof(Texture2D));

gloomy chasm
meager reef
#

oh yeah it could be looking for packages as well

#

nope, still null

#

whoops

#

hang on

#

now it works

#

thanks @gloomy chasm

gloomy chasm
#

np 🙂

meager reef
#

How do you use GetCachedIcon()?

#

Seems smarter for this purpose

gloomy chasm
meager reef
#

ah gotcha

#

One thing I was trying to figure out is how to make the Inspector display a set of values, based on something selected in an editor window.

#

Like how in the animator state machine you click on a transition and that data is shown in the editor window

gloomy chasm
slender sandal
#

I dont fully understand what would that as a line of code look like?

gloomy chasm
slender sandal
gloomy chasm
slender sandal
#

like it doesnt work i'm aiming to get the ui to look the same no madder the window size and nothing getting cut off

gloomy chasm
#

Can you show what you do want it to look like?

slender sandal
#

I dont have an image but I can explain it. In roblox studio for example if ui elements are set to scale and not offset it will look the same if its on a computer or a phone

#

which is basically what im trying to do. In which my window size is the size of the device connecting to roblox

robust venture
#

Is there any access to the Animator/Meccanim EditorWindow API, so I can write custom node-based tools with same GUI controls? Infinite canvas, arrows, etc.
I'd like to create an FSM visualizer as a separate window...

glad cliff
#

If tool im writing uses its own resources and I locate them by EditorGUIUtility.Load("Assets/MyTool/MyFolder/Myfile"), what happens to it if I export it as a package? Should I manually change path everywhere to "Packages/MyTool/MyFolder/MyFile", or what?

peak bloom
#

the path will be carried in the package, nothing will be changed...

glad cliff
#

what you mean? this means that before exporting i have to manually change the path everywhere, right? :/

tawdry kraken
tawdry kraken
fervent kelp
#

is there a way to show a list that is in the target script in the custom editor, i have a list that is made of a custom class, this custom class contains a gameObject and an int but it only draws this, i cant get it to show me whats inside. I know i am doing it right as i have another list that is just made of ints and that shows find. i read a bit and turns out its doesnt liek the monobehaviour that is maybe in the gameobject type? any solutions

waxen sandal
#

Show code

fervent kelp
waxen sandal
#

You probably have to create a serializedObject around each field and find the children using that and draw them

#

Don't forget to dispose the serializedObjects

#

I'm going to walk the dog

fervent kelp
short tiger
fervent kelp
#

sorry didnt read that correctly

#

no

fervent kelp
short tiger
#

So I think your only options are to either draw the list and each child property manually or stop using the base.OnInspectorGUI / base.DrawDefaultInspector and draw all the fields yourself in the order you need them in.

fervent kelp
#

🥹 ok well i will look into all that, might just leave it for now as this is not a necessity, thank you anyway

tawdry kraken
fervent kelp
tawdry kraken
#

ah nevermind (you did)

fervent kelp
tawdry kraken
#

from the code example I'm seeing, I would remove [SerializeField] inside the Serializable class

#

do not think that is necessary

fervent kelp
tawdry kraken
fervent kelp
tawdry kraken
#

you could have a string name to reflect which game object it is

#

unless you need to set the references in the inspector

fervent kelp
#

i need the reference in the inspector but tbf i was thinking of somthing similar as theoretically i dont want the obj to be changed from the inspector because it has to be set from a loaded file

simple cove
tawdry kraken
simple cove
#

you may be interested in Odin Inspector if you haven't heard of it -- makes doing stuff like this a walk in the park

fervent kelp
simple cove
#

$50 asset

tawdry kraken
fervent kelp
#

well i cant use assets and i am broke

fervent kelp
#

the drawer one is the most "right way of doing it"

simple cove
#

well i would rather not have to create extra code each time I wanted to draw a list 😛 so I'd still go with the drawer

#

but if you don't mind that then sure, it'd work! (would still require drawer code to back it up though)

simple cove
#

you can iterate through objects of an array's serialized property to get the references

#

damn, those answers are so good and detailed!

fervent kelp
simple cove
#

yeah 😆

fervent kelp
#

will look into that too lol

simple cove
#

and you can use this snippet to render any serializedObject (custom class or not)

SerializedObject so = new SerializedObject(SomeSOAsset);
SerializedProperty sp = so.GetIterator();
sp.Next(true);

// Skip drawing the script reference?
if (!includeScriptField)
    sp.NextVisible(false);

EditorGUI.BeginChangeCheck();
while (sp.NextVisible(false))
{
    EditorGUILayout.PropertyField(sp);
}

so.ApplyModifiedProperties();

EditorGUILayout.Space();

if (EditorGUI.EndChangeCheck())
{
    Initialize();
    AssetDatabase.SaveAssets();
}
#

actually that may only apply to UnityEngine.Object.. let me check

tawdry kraken
#

You wouldn't happen to have a full switch for correlating property types with the serializedProperty output type? 😅

#

It's not needed from 2022, but I'm on 2021, and not motivated to make one.

simple cove
#

I recall seeing someone sending that a while ago in #archived-code-advanced lol.. they even used object casts to make it easier, sec

tawdry kraken
#

For anyone reading, 2022 introduces serializedProperty.boxedValue

simple cove
#

seems it's not full code tho, sry 😄 you can ask them 😛

simple cove
#

oh it was just a

for (int i = 0; i < sp.arraySize; i++) {
    EditorGUILayout.PropertyField(sp.GetArrayElementAtIndex(i));
}
tawdry kraken
#

still seems it could have some use

simple cove
#

maybe they're the one that added it to 2022 pog

#

@earnest talon did you end up completing your CProperty.Value thingy? 😛

simple cove
fervent kelp
earnest talon
#

Lemme get it in a mo

#

I've been working on a C# -> USS translator

#

set is basically just a bunch of castings that i can't compress to fit on an image

#

forgot to fix enum mb

#

I'll fix it later because i'm already focused on the USS conversion thing

#

for the value setting, there's actually three ways to set the value

#

property.Value

#

property.SetValueUnsafe(object value)

#

property.SetValue(type value)

gloomy chasm
gloomy chasm
earnest talon
#

thanks, the documentation can be hazy

gloomy chasm
#

iirc character is string

earnest talon
#

I'm guessing layermask is set via (int)value

gloomy chasm
#

generic means it is a custom class/struct, so basically means it is just a parent that contains other properties

earnest talon
#

how I convert that would be itself a rather unique task.

gloomy chasm
#

I think gradient references the same thing as animation curve. But that is just a guess. I never use it 😛

gloomy chasm
earnest talon
#

pretty much why I don't plan to do it

#

I am using reflection, for other things

olive salmon
#

Hi! i'm not good with editor scripting so i''l ask for help.
I have 2 cameras and i want them to have always the same ortographic Size. So When i change the values in the inspector of one of theme, in edit mode, the value of the other also change.

earnest talon
#

just generic would be pretty much a pain

earnest talon
#

fair enough

#

I don't know specifically if I'll implement it

#

as those are hefty use cases and I'll be including proper documentation for cases like that

gloomy chasm
earnest talon
#

it's neat to see bewildered-core though

#

What I might do with generic is instead of directly getting it

#

you can just do custom iteration

gloomy chasm
earnest talon
#

nice

#

you working on any new things like that?

olive salmon
earnest talon
#

create two sliders in an editor window

#

or int values

#

or whatever you choose

#

and have those sync both *cameras' edits at once

#

so instead of changing one and applying the changes to the other

#

you change both at once

#

because otherwise why?

#

you'd have to update both SerializedObjects and apply the changes to both of them

#

but it'd be the same result

gloomy chasm
#

But again, it is like 3 lines of code to do it at runtime.

earnest talon
#

you can do it at runtime and edit time

#

i'd personally say try do it anyway because even if it isn't worth it, the experience and experimentation is helpful

olive salmon
earnest talon
#

what's the fun in life if you can't break a game engine or two

gloomy chasm
dusky marten
#

Hello, I have a problem since I can not access the play mode by an error, someone could help me thanks. I have come to wait more than 30 minutes and it has not worked for me, any solution?

earnest talon
#

that's not.... an editor extension?

fervent kelp
earnest talon
#

one thing I don't think I'll do again, mech

dusky marten
earnest talon
#

write an interpreter for C# <-> USS

gloomy chasm
gloomy chasm
earnest talon
#

literally.

#

C# <-> USS

#

I don't like USS

gloomy chasm
#

I feel like you have done something very cursed, but will hold judgement..

earnest talon
#

the reason being is

earnest talon
#

I prefer to work in C-based languages

#

I can use USS and UXML, I just don't like to.

#

so my result is, what if I just make it possible to read, write and modify USS stylesheets in C#?

#

because it's a very simple language

#

you can compile .uss files easily

#

you just need a few basic pieces of information

#
  • property/selector name
#
  • property/selector value(s)
#

-property/selector type

#

etc, etc

#

I was going to do this for UIElements as a whole anyway

#

for USS and UXML

#

but i wanted to do graphview

#

then gridbackground requires USS* (oh lord help me)

#

so, when I noticed the syntax again

#

it was just a case of "why not write an interpreter"

#

can't post gifs here

gloomy chasm
#

Gifs are not allowed, because it could be a meme or reaction gif. Sad. (sometimes gifs are allowed though.. dyno bot be weird)

earnest talon
#

fair enough

#

anyhow I am very well aware that I could just use (or suggest) UI Toolkit

#

and UI Builder

gloomy chasm
#

So you write a stylesheet in C# and it creates a uss style sheet from it?

earnest talon
#

yeah

#

and you can read a style sheet into that format too

#

decompiling all the rules, etc.

gloomy chasm
#

That is really cool! I hate it xD

earnest talon
#

I knowwww right!?

#

I really hate USS so much

#

but that's why I'm building it in now

#

I know interpreters are hard but at least USS is a sandboxed/simple CSS

#

and I want to be able to have an interpreter coded for 2019.1 and onwards

gloomy chasm
#

It seems like a cool/fun project to do! But also I really hate it, it takes away so much good of uss.

earnest talon
#

plus it'll look good on a portfolio that I did that

#

I mean it does technically

#

but also

#

I plan to include every base USS Property/Style Rule used

#

and all this

#

is so I don't have to gat dang use USS to supply a graph-view based editor window extension

#

and then it became part of Cappuccino's core package

#

because yes

#

I'm also fully cognizant and aware that I would not recommend this to people who can better use USS (this is pretty much a solution to an opinion-caused problem)

#

this is just for people who want strict C# usage.

olive salmon
earnest talon
#

I can't wait to get even the basics up and running and see it work fully

gloomy chasm
earnest talon
#

I love IMGUI a lot but (@ it) my sweet summer child you cause me and my fellow peers so much pain

#

and the only reason I love it is just I can write editors strictly in C# without issue.

gloomy chasm
earnest talon
#

if I could use USS in C# directly, creating and modifying style sheets - I'd love it more

#

maybe even go further with that than IMGUI

#

but sadly I can't

gloomy chasm
earnest talon
#

oh you-

#

that won't be possible?

#

I'm not doing it to style w/o recompiling

#

if you can do that as a byproduct, neat

#

main goal is just to make it so I can create style sheets when they're missing for something.

earnest talon
olive salmon
earnest talon
#

dad's a web developer and he saw what I was doing to a CSS-based langauge

#

and even he weeped

earnest talon
# gloomy chasm

well I know you can do that but I'm not looking to create it like that myself

#

I want to be able to assemble a style sheet directly in C#

gloomy chasm
earnest talon
#

and so is IMGUI

#

but we still somehow coped with it

gloomy chasm
#

LOL

#

You do you my friend

earnest talon
#

I think that's just the beauty of this discord sometimes

#

we all have our own ways and we all get to laugh at the absurdity of some ways

gloomy chasm
#

Indeed!

earnest talon
#

also good luck with your projects!

#

I'm gonna go back to butchering the native tounge of web developers with C.

olive salmon
# gloomy chasm Correct!

I feel like im close but no getting at all. Now when i change ANY value of ANY component in inspector, it print the mainCamera ortographicSize, but not the playerCamera.

gloomy chasm
# olive salmon I feel like im close but no getting at all. Now when i change ANY value of ANY c...

Yep, that is how it works. You then do

for (int i = 0; i < stream.length; i++)
{
  if (stream.GetEventType(i) == ObjectChangeKind.ChangeGameObjectOrComponentProperties)
  {
       stream.GetChangeGameObjectOrComponentPropertiesEvent(i, out ChangeGameObjectOrComponentPropertiesEventArgs changeArgs);
       Object obj = EditorUtility.InstanceIDToObject(changeArgs.instanceId);
      if (obj is Camera camera)
      {
        // you can then see what camera it was and copy the value from one to another.
      }
  }
}

https://docs.unity3d.com/ScriptReference/ObjectChangeEventStream.GetChangeGameObjectOrComponentPropertiesEvent.html

olive salmon
gloomy chasm
earnest talon
olive salmon
#

yeah i wanted to do something cooler that those 3 lines in Start method, but im giving up

earnest talon
#

well it's not about cooler

#

it's about probably doing it

#

in a more extensible, universally appliccable method.

gloomy chasm
earnest talon
#

might as well go whole hog and not do that

#

instead doing something more reasonable like an actual editor window

gloomy chasm
#

Also, 'cooler' is 100% a valid reason to do editor scripting xD

earnest talon
#

which allows you to view the selection of and modify multiple cameras at once

#

instead of just two.

gloomy chasm
#

No, that is ~worse~ bad UX

earnest talon
#

if he's only ever doing it for two cameras for one project, yes

#

but it's more universally applicable

#

and you'd be able to modify more than two cameras

#

I don't see how that's bad UX personally - it allows you to do more than two fixed, single objects in one project's scene file

#

as a notice, it wouldn't be all in one panel

#

you'd have tabs, of sorts, within the panel

gloomy chasm
earnest talon
#

I'm guessing in this case bad/worse UX is just dependent on the house rules of the company/companies you've worked for

gloomy chasm
earnest talon
#

and what rules/guidelines you use as a basis for your UX design.

earnest talon
#

???

#

you'd change both cameras simultaneously

#

like - you can do that?

#

you'd be selecting all the cameras and you'd be able to even add restrictions as you build the editor window

#

such as - only two or more cameras may be modified at a time

gloomy chasm
#

Which means the second camera would not be updated

earnest talon
#

yes but that would be different to what I'd be doing

#

which would be actively modifying two cameras' values at once

#

using two (or more) fields and synchronising the values of both cameras

#

cause you don't have to rely on displaying one camera's values over the other's

#

you can just mass-modify

gloomy chasm
#

I know that

#

What I am saying is you might forget or someone new might join the project. And want to update the settings on the camera, so they just go select the camera directly in the hierarchy and change it's values in the inspector and never even touch the window.

olive salmon
earnest talon
gloomy chasm
earnest talon
#

any project management structure where you can just let new people join without any tool education (which is what happened at uni somewhat but between game engines) is questionable at best

gloomy chasm
#

Nah, it is pretty common xD

earnest talon
#

weird

#

you'd think someone in the development cycle would go "oh by the way we have a few changes done to our version* of x game engine. here's what we've done"

gloomy chasm
#

It depends on the size of the group and how much management experience they have

olive salmon
#

okay okay okay im alomst ther, but the problem is, I dont know how to get reference of the child camera object in editor

earnest talon
#

uhhh

olive salmon
#

this is what it prints

earnest talon
#

mainCamera?

#

so

#

what's going on with GetComponentInChildren<Camera>(); returning the main camera

#

that one is weird

gloomy chasm
earnest talon
#

or mainCamera.transform.Find(childName) also works

#

though whether or not that would work in your case is hazy at best too

gloomy chasm
#

Please don't ever do that. Someone can rename a GO so easily.

earnest talon
olive salmon
gloomy chasm
earnest talon
#

but additionally, getting children themselves are also a pain as someone can also change the order of a game object accidentally

gloomy chasm
earnest talon
#

the main questions I have is how many clueless people are being let in on projects industry-wide

#

well either way it is what it is

olive salmon
#

AAAAAAAAA!

#

i got it hahahaha

#

it works poerfect, when i change the ortograpficSize of any of them, the other change as well

gloomy chasm
#

YAY! Congratulations! 😄

olive salmon
#

this code u send me, is something u use to use often, or it has been very specific for that?

gloomy chasm
#

Nah, I use it rarely. So far I have used it once to move objects between scenes in a world streaming system. And once to create ScriptableObject variants.

olive salmon
#

Maybe this is my starting point for learning more in depth Editor scripting

#

and just a final question, i dont want to bother any more, its necessary that the class who uses the [InitializeOnLoad] attribute is an static class?

gloomy chasm
#

No, I don't think it does. All it does is call the static constructor, and if memory serves, any class can have a static constructor. But don't quote me on that, I am blanking on if that is the case or not really

olive salmon
#

nice!

#

well, so after this break, i can continue with the gameplay hahaha, if i finally end this game i will mention u on credits😂

earnest talon
#

yeah it seems to not matter on that

#

even I was curious about that

#

I think the only dependency is static constructors?

#

and static voids maybe

gloomy chasm
# earnest talon and static voids maybe

The reason for the static method is because it is used in the static constructor. So in order for it to be called without creating an instance of the class, it needs to be static.

earnest talon
#

never found an instance where I've had to static a constructor before so hey

#

learn something new every day

gloomy chasm
#

Not just static constructors.

earnest talon
#

yeah

#

I just never knew you could do it with constructors

olive salmon
gloomy chasm
olive salmon
#

so in build i will need that 3 lines code u said at the beginning of this journey

gloomy chasm
#

Yup, if you want to change them at runtime. But if they will not be changing, then there is no need since the values set in the editor will stay.

olive salmon
#

at this moment im not sure if they will change at runtime, but its good to have it in mind already

earnest talon
#

@gloomy chasm I will say that I didn't expect there to be so many USS Property types.

earnest talon
#

oh well

#

just hard-coding them all in anyway

#

(there's a reason for this, dw)

#

enum -1 : custom (not marked as variable, for any unsupported types that get added before support is added)

#

enum 0: variable, for any variables

#

i have to move this enumerator to a new script after though lol

#

100% though

#

I can see the appreciation behind USS and why it's useful

#

with all this

#

it's neat to see how I can translate it, but god damn this translator is cursed 💀

#

hurdles like this just make me more motivated to prove they won't get in the way of sheer determination

earnest talon
#

so many property types to convert to strings

#

i've done it but at what cost

earnest talon
#

well it's partly there now

#

@gloomy chasm I don't know specifically what the value types can be so I've got this for now.

#

it is cursed i know

earnest talon
#

as a naming convention?

#

only StyleValues exist which might be similar?

#

but no StyleValue

#

only reason I didn't so far is the absence of the ability to use keywords in the StyleValues type

#

such as auto, visible, hidden, etc.

gloomy chasm
#

Oh, nvm, I was thinking of StyleColor and StyleLength etc.

earnest talon
#

ah fair

#

like

#

I'm 100% aware this is a fully bad idea

#

for an interpreter

gloomy chasm
#

There is IStyleValue<>

earnest talon
#

it makes assumptions that you know what you're doing.

#

not for 2021.3

#

which is the version of unity I'm using primarily as a base for forward-porting and back-porting

#

I would love to go to 2023 if possible but it's not a personal choice sadly

#

it's a university course restriction due to the fact we don't get software installed unless:

#

A) a PC fails spectacularly and needs a reinstall of windows

#

B) it's summer and all PCs need new updated versions of software