#↕️┃editor-extensions

1 messages · Page 107 of 1

patent pebble
#

I can do that by consuming the event with event.Use()
But it seems like the event is evaluated at the end of the GUI loop internally or something, so it's either "used" for all controls or "click" for all controls

#

if I consume the event then any of the Position, Rotation, Scale fields don't get it either

#
public void DoGUI()
{
    ConsumeEvent(); // Consume the event when Red's rect is clicked with event.Use().
    DrawRedArea(); --->I want this to NOT receive the click event
    RestoreEvent(); // Restore the event to the original state (type, button, etc).
    DrawPosRotScale(); ---> I want this to receive the click event
}
#

i've tried this and every other possible order on the event handling, nothing seems to work

#

it's either consumed for all or click for all

#

any idea on how I could approach this?

gloomy chasm
#

It has to do with the rect passed to EditorGUI.BeingProperty

patent pebble
#

oh wait, let me test one thing, I think you may be right

gloomy chasm
patent pebble
#

i see i see

#

my original design is to have a PropertyDrawerBase class that encapsules all of its derived classes GUI stuff in a property scope

public abstract void DoGUI(Rect position, SerializedProperty property, GUIContent label);

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    using (new EditorGUI.PropertyScope(position, label, property))
    {
        DoGUI(position, property, label);
    }
}
#

i did this to automatically handle multi-object editing and stuff like that

#

but now I guess I'll have to change it

#

to avoid the issue with the context menus

surreal kindle
patent pebble
#

well in my particular case the problem wasn't the events it was the Begin/EndProperty that internally handles them differently
that's why I was so confused

#

doing something like this works properly

GUILayout.Button()
Event.current.Use()
GUILayout.Button()
#

the second button won't receive the event because i use it halfway

#

but the Begin/EndProperty was messing me up with the context menu

#

because what I was doing was essentially this:

BeginProperty
some GUI control
Event.current.Use()
some GUI control
EndProperty
surreal kindle
#

I might have misunderstood then. It's getting late here, but I got the impression the issue was that EndProperty triggers the context menu which you didn't want 🙂

patent pebble
#

yeah the issue was the Begin/EndProperty was using a big rect that was overlapping with the rects of othe controls

#

so I had to instead handle the begin/end differently

#

i was wrapping my entire thing in a begin/end to handle everything by default
so I just refactored my code to only use it where it's actually needed

#

triggers the context menu which you didn't want
yeah pretty much

#

the right click was triggering an ObjectField's context menu for the entire property because the original field is an object reference
I just ended up not using BeginPropert/EndProperty in this particular case

#

because i am manually drawing an object field, it gets the same context menu when the click actually happens in the rect

surreal kindle
#

Ah! ok I see then 🙂

patent pebble
#

this whole thing is a single field that uses a PropertyDrawer

surreal kindle
#

Need to go to sleep here, but glad you figured it out then 🙂

patent pebble
#

thank god for MechWarrior, this thing would have taken me hours to debug lol

solid ice
#

I'm getting an annoying custom editor error ArgumentException: Getting control 1's position in a group with only 1 controls when doing repaint, that I think should be easy to fix, but I'm not super capable with editors.. 😛
Line 112 it says.. seeing anything wrong here?

surreal kindle
# solid ice I'm getting an annoying custom editor error **ArgumentException: Getting control...

There are multiple results on google for that specific error message - for instance:
https://answers.unity.com/questions/17718/argumentexception-getting-control-2s-position-in-a.html
You can read about IMGUI here:
https://blog.unity.com/technology/going-deep-with-imgui-and-editor-customization

You need to make sure that you don't change the order/amount of controls between events. If you need to do so, you should use:
https://docs.unity3d.com/ScriptReference/GUIUtility.ExitGUI.html

solid ice
north sphinx
#

How to draw gizmo that looks like collider gizmo?

#

oh, it's WireSphere

#

got it

waxen sandal
#

There's another one that's useful

#

But I forgot where

surreal kindle
# solid ice Thanks, I googled a bit but didn't find anything that solved it for me, or that...

You get this error a lot if you have lists that change or conditional UI code (show/hide button depending on some expression etc). Just make sure you use ExitGUI when you do something that will change the layout of your GUI code - and you should read up on how events work in IMGUI. It will save you a lot of headaches in the long run (I can tell you that from experience 😛 )

solid ice
fluid wolf
#

How to make a texture field look like this

#

rather than this

#

?

waxen sandal
#

Oh wait iirc there's a style somewhere

surreal kindle
# fluid wolf How to make a texture field look like this
EditorGUILayout.PropertyField(textureProp);
EditorGUILayout.ObjectField(textureProp, typeof(Texture2D));
textureProp.objectReferenceValue = EditorGUILayout.ObjectField(new GUIContent("Texture"), textureProp.objectReferenceValue, typeof(Texture2D), true);

Results in:

fluid wolf
#

Maybe I should clarify: I'm making an inspector for a scriptable object

#

I want this field to set the SO's UITexture property

surreal kindle
fluid wolf
#

Now I have this for the start of the script

#

I tried to replace things in your code with the equivalent

#

But it says it can't implicitly cast from Object to Texture2D

#

Should I just cast it?

#

I just did that, and the inspector looks like it should now

surreal kindle
fluid wolf
#

Maybe I'm just overcomplicating this and a custom inspector isn't really necessary for this.

#

Because now I tried to add a button to save a prefab variant

#

The console says it doesn't work because a parameter "root" is null.

surreal kindle
#

But.. it seems like you're only trying to clone the base prefab?

fluid wolf
#

Yeah, but as a variant of the base prefab.

#

This made it successfully create the asset

#

But it also instantiated the base prefab in the active scene, which I don't want.

#

Do I just have to destroy the instantiated prefab afterwards?

surreal kindle
#

just skip the instantiate I guess (since the AssetDatabase.LoadAssetAtPath gives you the object you want)

fluid wolf
#

I see.

#

I was just following a forum post, but if that works...

#

Wait, it just gives "Can't save persistent object as a Prefab asset"

#

This is my current code

surreal kindle
#

ah.. ok.. then you have to instantiate it with PrefabUtility. .wasn't sure about that one

fluid wolf
#

And then destroy it?

surreal kindle
#

Yup

fluid wolf
#

Alright

#

I used DestroyImmediate since apparently Destroy doesn't work in the editor

surreal kindle
#

Anyway - need to get back to work 🙂 - ttyl

fluid wolf
#

Thanks

surreal kindle
#

Remember to update the serialized object first

serializedObject.Update();
// <----- Custom editor code here
serializedObject.ApplyModifiedProperties();
dusk bobcat
surreal kindle
dusk bobcat
#

yes someone told me that just a moment ago, can you tell me how to change it?

#

@surreal kindle

surreal kindle
#

Those are basically the things you need to put it together.. you need to get the property from the object (currently you're getting it from the editor), and then check based on the value written.

#

gtg

broken gulch
#

Is there a way to disable the component inspector dropdown like in the case of the Audio Listener? I haven't found any questions or documentation on it.

#

Right now, I just have my custom inspector render nothing at all, which gets the job done quite nicely, but I'd still like to remove the dropdown button on the left of the component header.

fluid wolf
gloomy chasm
broken gulch
#

No. That still leaves the dropdown button.

#

As I've said below, I already have an empty component inspector. I just want the dropdown button gone

gloomy chasm
#

Oh, sorry I didn't read that part.

surreal kindle
fluid wolf
#

Good idea.

patent pebble
#

and there's an undocumented method on the Editor class to make your custom header

#

one sec, gonna look for the example, I have one somewhere in my test project

broken gulch
#

Thanks a lot! I've taken a look at OnHeaderGUI in the past, but it didn't seem to do it

gloomy chasm
patent pebble
#

haven't got to AudioListener yet, but that's a good note to keep in mind

broken gulch
#

Yeah, some things just seem to be obfuscated for no reason

gloomy chasm
patent pebble
#

hmm maybe

broken gulch
#

It seems to be that way. I've seen very specific usages of type checks in the Unity source code.

hollow zealot
#

I am trying to implement drag and drop functionality for an array of custom classes, the same way you can with normal arrays. I found some code for it that would og inside of a property drawer, but it only detects mouseover on the individual array items. Is there somewhere else I should be putting this?

patent pebble
#

Custom inspector title bar

gloomy chasm
hollow zealot
#

Ok, I will look into that

patent pebble
#

how can I perform a key press through code?

#

in an editorwindow I need to perform a Tab press twice when something happens

#

is there a way of doing this?

gloomy chasm
patent pebble
#

ah right! i had forgotten about SendEvent

#

thx! 🙏

gloomy chasm
onyx harness
#

Tab, shift, alt, all those modifiers are special events

gloomy chasm
#

I don't think tab is

onyx harness
#

Depending on what you want exactly, I wouldn't be surprise if it doesn't do what you are expecting

patent pebble
# gloomy chasm Still suspicious... 🤨

i have some tools that relied on setting hotControl and keyboardControl through code based on the last controlID and stuff like that and it resulted in some weird behaviours

#

just exploring what possible solutions there's to that

#

so I'm gonna try manually sending duplicated Tab and Shift+Tab events for getting the "correct" navigation through controls

onyx harness
#

Sending Tab manually bypasses the global tab where the focus is given to the next element in queue (a control, a window)

#

if it is good for you, good good

#

if it is not, there is the OS input that you can trigger (Windows only)

patent pebble
#

hmmm I see, i'll keep that in mind

fluid wolf
#

I'm stumped as to how to use serialized object/property for this inspector

#

This is what I have now, but there's all these errors

#

All of the "cannot convert" kind

waxen sandal
#

You probably just want propertyfield instead of Objectfield

#

Also, that cannot convert error is because the parameters you're passing are in the wrong order/type

#

i.e. texture is a serializedproperty and not a Texture2D/Object

fluid wolf
#

I see

surreal kindle
surreal kindle
# fluid wolf This is what I have now, but there's all these errors

Here's a quick and dirty example. The reason for the object field is to automagically get the "texture preview box". This example shows three different ways of doing the same thing, and the result of doing it in those three different ways.
ResourceType: https://pastebin.com/ZUDsXP6x
ResourceTypeEditor: https://pastebin.com/tNQDaSjq

fluid wolf
#

Wow, thanks

#

Sorry you had to spend your time on this

surreal kindle
#

..aand now back to updating the localization sheet for our project 😴

tender olive
#

Does anyone know if it's possible to sign into your Unity ID via an editor script? Is there an API for Unity Services like that?

waxen sandal
#

IIRC you can download a license file and import that through the commandline

patent pebble
#

where are the Unity preferences stored?

#

for example these colors

#

are they stored somewhere in a folder like the Project Settings?

#

i'm learning how to use SettingsProviders and I want to follow Unit's scheme for storing settings and preferences

visual stag
#

for example

patent pebble
#

hmmmm

#

i can find some of the preferences in the EditorPrefs

#

but the naming is so all over the place

#

and I can't find any of the colors for example

visual stag
#

My screenshot contains some colours

patent pebble
#

ah right

#

i was trying to find them under "Colors/"

#

but they are each under "Animation/", "Scene/" etc

#

damn, I really wish they had put all of these settings in files like they did with the ProjectSettings

#

it's a nightmare to deal with EditorPrefs

visual stag
#

Yeah, I don't know why they choose to use the registry over files in appdata

patent pebble
#

sigh

#

Unity being Unity 😅

gloomy chasm
#

How long have constructors of ScriptableObjects been called for...?

#

I could have sworn that they weren't called...

visual stag
#

I presume since forever?

#

I don't know why they would be special 😛

gloomy chasm
#

I guess it is just one of those things that I 'learned' when starting out since you don't use constructors for creating them, and thus can't have parameters, maybe I 'learned' that you simply can't have constructors at all

patent pebble
#

is it safe to create folders under my project?
I refuse to follow Unity's convention of storing "Preferences" settings in EditorPrefs
can I just make a Preferences folder in my project? next to the Library, ProjectSettings, etc folders?

#

i'm scared of Unity suddenly exploding and corrupting my entire project or something... 💀

gloomy chasm
visual stag
#

If they're in your project they're not preferences, they're project settings

patent pebble
#

ah right i'm dumb

#

Windows: C:/Users/[username]/AppData/Roaming/Unity/Editor-5.x/Preferences/

gloomy chasm
#

@visual stag can you sanity check me here. It is fine to create folders in the root project folder right?

visual stag
#

Of course

gloomy chasm
#

Alright, I was sure, but then I started to second guess my self haha

#

thanks

patent pebble
#

it's weird that they have the UserSettings folder anyways... they store QuickSearch settings there, which are supposed to be per-user...

#

they also store some ShaderGraph settings in there

gloomy chasm
#

Well I am glad they do because I think I am going to start using it for my asset

patent pebble
#

found this in the forum

Yeah we moved Library/EditorUserSettings.asset into this new folder.

The reason being, that Library should contain only imported/cached data that can be completely reconstructed from the project. People delete their Library folders all the time, etc.

But, parts of editor settings were in Library/EditorUserSettings.asset file (things like user's perforce connection settings etc.). So now it's in that new location. The folder should not be put into version control, since it's per-user things there.

See "Editor: Unity projects now have "UserSettings" top-level folder, EditorUserSettings.asset moved from Library there" in release notes, and mentions of the folder in
#

weird decision...

#

offloading the responsibility to the user, instead of just putting that into AppData or whatever folder the OS uses

visual stag
#

That's so bizarre

#

But it is local to the project, so that makes sense I suppose

patent pebble
#

i wish they were more consistent with this sort of thing

#

it's such a nightmare

#

like I was just trying to get the TimeLine settings from the EditorPrefs, but guess what
they store them in the AppData folder, all neat and tidy in their own .asset file 🙃

#

and now I'm trying to find this one

#

but god knows where it's at

visual stag
#

🤷 look at the C# source

patent pebble
#

the Enable Deprecated Nodes is in Editor Prefs, but the Shader Variant Limit isn't

#

yeah I guess that's gonna be more reliable than going fishing for the settings in random places

#

sigh

echo glacier
gritty yew
#

how do i make unity automatically randomize tile variants

#

lets say i have grassa- plain grass

#

grassb- grass with small blades

#

how can i get unity to leave a couple of those grassb's among grassa's

#

with 2d extras

#

or would i have to manually code it to do so

waxen sandal
#

Wrong channel probably

gritty yew
#

whats a better channel?

waxen sandal
whole steppe
#

Does anyone know what this error is? It won't let me Build.

#

Nevermind, figured it out carlderp

north sphinx
#

is there any way to make serialized interface assignable through inspector?

#

[SerializeReference] private ISystem[] systems;

#

where systems are Monos

#

I want to be able to simply reference them through inspector

gloomy chasm
patent pebble
#

I'm curious, what do editor scripting magicians here do when it comes to coloring IMGUI controls?
it has been always painful to apply the intended colors because they always get multiplied by whatever transparency the background texture has
and some controls are just straight up grayscale only (i assume due to some internal stuff in their rendering)

#

i have always kinda tweaked the color back and forth by some multiplier value to get a "good" result

#

but it's just annoying

gloomy chasm
#

Oh, you mean like GUI.contentColor?

patent pebble
#

yeye

#

for example to get a pure red color on the "Box" style i need to multiply by a value of around 3.8

#

i know the "correct" solution is to probably make my own versions of those styles with the actual texture modified externally in Photoshop or whatever
but... ouch

#

there's hundreds of default styles

gloomy chasm
#

I rarely do tbh. But when I do I never multiply it or anything.
In this case, just do EditorGUI.DrawRect(..)

#

I feel there are very few situations where you should be changing the color tbh

patent pebble
#

DrawRect works fine for some basic usage
but sometimes I want to make use of the nice round and cool textures the default styles use

#

just doing squares and rectangles looks kinda rough sometimes

patent pebble
gloomy chasm
#

I would say it depends. If you are doing 'backgrounds' then you most likely should create the textures for it (please don't do colored backgrounds though, it ever looks good imo)

#

UITK is perfect for this stuff btw 😉

patent pebble
#

i keep backgrounds mostly grayscale, i mostly colorize borders and text

#

this is probably just me swimming against the tide of IMGUI

#

i'm halfway into making a tool to "bruteforce" every style's texture
iterating through every possible multiplier value and reading screen pixels to get the closest color match and then storing that in a file so I can use it later
it's not ideal, since the color is gonna be mostly dependent on the color of what's behind (usually an EditorWindow's main background color)

#

@gloomy chasm does IMGUI UITK handle coloring with "actual colors"?

#

or does it do a similar thing to IMGUI where the textures feel more like they are "tinted" rather than colorized?

patent pebble
#

whoops, yes, typo 😅

gloomy chasm
#

It doesn't use textures for basically anything besides icons (though it can)

#

You can do something like button.style.backgroundColor = Color.red to make the background of a button red, and it would be the color you set, not a tint

patent pebble
#

🔭 👀

#

damn, that sounds nice

gloomy chasm
#

Just do it, bite the bullet

#

I have been bugging you for months! You can use a uss file to change the style. That means change the background color, padding, margin , border width and color, layout direction, flex type, etc. etc. all 'instantly' without any need to recompile scripts.
It makes doing styling iteration insanely fast (compared to IMGUI)

patent pebble
#

@gloomy chasm i'm slowly dipping my toes into the UITK waters from time to time

#

but for now I can't just migrate all of my in-progress tools to UITK

gloomy chasm
#

Sure you can!

patent pebble
#

not with my current UITK skill level lmao

#

💀

gloomy chasm
#

I'm here for you! You can do it! Best way is to practice!

#

You'll like it I'm sure

patent pebble
#

100% seems like it's way better for the actual design workflow

#

i'll get there slowly

gloomy chasm
#

If ya got any questions feel free to @ me! 😄

patent pebble
#

sure thing! 💙 🙏

#

well for now i'm back to sticks and stones with IMGUI

#

scurries away into the darkness

gloomy chasm
patent pebble
#

i usually just read a global key event and got the key modifers from there

#

with the

UnityEditor.EditorApplication.globalEventHandler
gloomy chasm
#

I also figured out how to get what object(s) were undone/redone, though it isn't there

shadow violet
#

Just curios, is it possible to force the Package Manager to do stuff by a custom editor script? Im wondering if I can cause it to basically "queue" installing/removing several packages at once

karmic ginkgo
karmic ginkgo
#

we have an issue with editor generated stuff spazzing out on undo, going to use your solution to solve it

gloomy chasm
karmic ginkgo
#

meshes with hideflags dont update properly

#

ignored it until now since its not a deal breaker

gloomy chasm
#

Ah

barren moat
#

When I call DeleteAsset the reference becomes null. How can I delete the serialized file and retain the C# representation (in the same way you can create an SO and then create an asset)?

waxen sandal
#

I don't think you can, creating a copy is the easiest

barren moat
#

Yep! Just worked it out

#

Thanks :-)

devout oracle
barren moat
#

@waxen sandal oh no it doesn't work because it changes the UUID!

#

God damn it

#

It breaks all the references

#

I wonder if there's a way to cheekily set the instance ID

#
    static void SetInstanceId(Object o, int id) {
      var field = typeof(Object).GetField("m_InstanceID", BindingFlags.NonPublic | BindingFlags.Instance);
      field.SetValue(o, id);
    }
patent pebble
#

Is there a way to draw IMGUI stuff outside of an EditorWindow?

#

can't find anything online that works. I've seen people doing stuff with GUI.BeginClip and Matrices but doesn't work for me

#

any way to for example, draw a rectangle on the position of the mouse?

waxen sandal
#

You make an editor window at the position of the mouse

patent pebble
waxen sandal
#

I think someone here did it before but I don't remember how

#

There's always the, create a screenshot and align it properly method

gloomy chasm
#

But that is more for the whole window I guess

patent pebble
#

@gloomy chasm thanks for the pointer, I'll look that one up

#

if I can make the whole window transparent and still render the IMGUI stuff inside of it that'll work fine

gloomy chasm
patent pebble
#

sure thing, will report back later with my findings 👍

#

right now i'm having dinner and watching Jurassic Park 🦖

onyx harness
#

But the big drawback is that you can draw only once

#

The window freezes after that, never been able to work around that issue

patent pebble
#

@onyx harness oh, what approach did you use for that?

onyx harness
#

user32.dll

karmic ginkgo
#

2 components have custom gizmo icons, can i display them both at once, with a hack of some sort?

#

ah lol theres Gizmos.DrawIcon

fluid wolf
#

I tried to make an editor window with a setter for one of the variables. It made Unity crash

gloomy chasm
fluid wolf
#

I was dumb and deleted it, but was something like:

private string find
{
get => return find;
set
{
find = value;
Search();
}
}

(Search was a method in the same class. I tried having only debug stuff and I tried having it empty, but same result. Unity closed as soon as I opened the window)

gloomy chasm
#

That is what that code does

karmic ginkgo
#

yeah stack overflow

fluid wolf
karmic ginkgo
#
private string find
{
    get => return find;
}

==

private string find(){
  return find();
}
#

which results in stack overflow

gloomy chasm
fluid wolf
#

Wait, you’re right

#

It calls the get function, which just calls the get function

#

That’s probably the issue

karmic ginkgo
#

same with set in your code

gloomy chasm
#

Unrelated, but I have learned today that the Undo system counts selection changes differently than object changes.
The main way it is different is that changing selection doesn't clear the redo list.

fluid wolf
#

I see now that I wrote the getter wrong

gloomy chasm
fluid wolf
#

That’s what I don’t see

#

The setting part of it looks the same as in the video.

gloomy chasm
#

Walk through the code, the setter is calling the setter

karmic ginkgo
#

there are 2 parts to a full property

#

above is called "backing field"

fluid wolf
#

Oh right

#

Now I see it

fluid wolf
karmic ginkgo
#

most of the time a property is a public interface for a field

fluid wolf
#

If I’ve got this right, a property is basically the public-facing variable that hides the one used within the class?

karmic ginkgo
#

yes, 99.9% of the time

fluid wolf
#

Alright, thanks

rough raven
#

I'm looking to replace Unity's ColorPicker, and I was wondering if I could generally replace the property drawer for Colors or something in that vein. Does anybody have an idea for that?

karmic ginkgo
#

probably not achievable without code injection

#

if the relevant code is on managed side

rough raven
#

I'm fine with code injection if it gets me there

#

Actually, the ColorPicker class does something interesting, and uses Resources.FindObjectsOfTypeAll(typeof(ColorPicker))

karmic ginkgo
#

probably because its an editor window

rough raven
#

But I'm not sure how is that useful, given that ColorPicker is internal

gloomy chasm
#

Yeah color picker is just an editor window. It is like 98% C# side of stuff

rough raven
#

Ah, so that beginProperty hijacks al of the editors or something?

patent pebble
#

I made a PropertyDrawer to replace the default ObjectPicker
I assume it's doable too with the ColorPicker

#

i didn't replace the default one in all instances of Object tho, i use a PropertyAttribute to manually do it

gloomy chasm
rough raven
rough raven
gloomy chasm
rough raven
#

Ok, so I can either do that or code injection, I assume

#

Any other potential ways to take into account?

gloomy chasm
# karmic ginkgo lol legit

lol I know right, I saw something like that in some Unity code once and have used it several times since haha

karmic ginkgo
#

some poor guy debugging editor code 10 years later

gloomy chasm
#

LOL

patent pebble
#

wow, i spend all the effort making a legit re-implementation of the picker field and everything

#

and you guys just hijack the button and draw over it

#

lmao

karmic ginkgo
#

if it works, it works (tm)

gloomy chasm
#

Well you can't draw over it because the event is run first.

karmic ginkgo
#

btw unity's imgui events still propagate bottom up?

patent pebble
# gloomy chasm Well you can't draw over it because the event is run first.

i do this for mine ```cs
private void DrawControls(Rect position, GUIContent label)
{
GUIContent fieldContent = EditorGUIUtility.ObjectContent(_property.objectReferenceValue, _objectType);
EditorGUI.ObjectField(position, label, _property.objectReferenceValue, _objectType, false);

EditorGUIUtility.SetIconSize(new Vector2(12, 12));

_objectFieldID = (int)EditorGUIUtilityProxy.s_LastControlID;

if (e.type == EventType.Repaint)
{
    if (_isDragging)
    {
        EditorStyles.objectField.Draw(_fieldRect, fieldContent, _hover, false, _on, false);
    }
}
EditorGUIUtility.SetIconSize(Vector2.zero);

GUI.Button(_pickerButtonRect, "", GUI.skin.GetStyle("ObjectFieldButton"));

}

#

still needs polish, but for now works fine

gloomy chasm
karmic ginkgo
#

yeah if you have 3 buttons on top of each other, the one on the bottom will be the first to catch mouse event

#

at least on runtime

gloomy chasm
#

Uhh yes because its code is run first

karmic ginkgo
#

that is not really an inherent problem of the imgui

#

its the problem with unity's shoddy impl

gloomy chasm
#

Is that not how it is supposed to be?

karmic ginkgo
#

ofc not, the things drawn last have to be the first to test for events

#

like its done proper in dearimgui

gloomy chasm
#

Oh yeah I guess that is how makes sense huh

#

Never even questioned it lol

karmic ginkgo
#

people who use imgui for runtime have to struggle with those things

#

it can be great, like they can rewrite it, its not a big deal to refactor it for runtime, optimize, remove overhead of it just existing and so on

#

they most likely just used the same gtk they used for editor and cut on maintenance for standalone runtime version

patent pebble
#

@gloomy chasm by the way I tried the ContainerWindow's SetAlpha,SetBackgroundColor and they don't appear to work 😓
tried the SetInvisible method and it actually makes the window invisible, but it also does it for the contents... which may be useful in some cases
but yeah... seems like making tweaking an EditorWindow's background color/alpha is not possible

#

saw this in a comment in the source code

// We currently only support this on macOS
m_Window.SetAlpha(m_TargetAlpha);

so maybe transparency on EditorWindows only works in Mac? 🤷‍♀️

gloomy chasm
#

Do yall ever run in to a bug and think "Oh I need to fix this, but shouldn't take more than an hour or two" and then you are still working on it almost 2 days later...

#

Unity's Undo API is so lack luster...

karmic ginkgo
#

lts build 22 - 15 known issues, build 28 - 30 known issues

rough raven
#

@gloomy chasm I've tried looking for EditorApplication.beginProperty but there are no docs for it?

rough raven
#

Right

#

Ok, it's way too late to start disassembling stuff, so I'll give it a go tomorrow, many thanks to everybody anyway 🙂

gloomy chasm
rough raven
#

Cool, will check that out, although I normally just use Rider's decompiler, it works a treat

karmic ginkgo
#

is there any way to somehow mark object for usage with scripted importer apart from adding stuff to the path/source assets?

gloomy chasm
karmic ginkgo
#

so that its processed by custom importer

#

i.e. right click in unity editor -> import with ...

#

or maybe i could use asset labels?

#

2011

#

"should use", aha yes, thanks i "sure" will

#

genius, it works

gusty radish
#

anybody knows why my visualstudio doesn't highlights some unity classes?

visual stag
fading laurel
devout oracle
#

Is there a reason you need binary? Just curious

broken wind
#

I'm not sure if this is the right channel to ask but has anyone recently updated to 2020.3.29f1 and are using Newtonsoft.Json? How did you get the latest version installed in this new editor version if you did?

One of my assets does not recognize it as an import anymore after the update, so I thought to drag over my Newtonsoft.Json.dll file from my older editor version, but decided it might be available in the package manager but can't seem to find a valid place to import it to stay up on the latest versions of it.

#

I've also tried installing from my package manager the github location for Newtonsoft.Json but I get an error that no package manifest was found.

#

Nm, I found a section in the README that mentions to use a different URL to import into the package manager. All good.

devout oracle
#

This is a wonderful thing... back/forward buttons for the asset browser

#

Tested on 2020.3.23f and still does the trick 👍

hot quarry
#

hello fellow gamers...

#

I made this search script for the editor about a year ago..

#

At the end.. when I open the prefab you can see the Asterisk (save indicator) flickering

#

after some research my buddy pointed out:

#

In the SpawnSearchEditor.cs script which is in charge of setting the variables on the main SpawnSearch.cs gameObject

#

The Layer.. is a layermask I have on the actual SpawnSearch.cs but everything below that.. the Tags and the search buttons and verification messages are handled in the SpawnSearchEditor.cs

#

Now.. im trying to rack my brain to figure out why I had to use .SetDirty

#

any help or if u got questions or wanna see more of the scripting, @ me and let me know.. thanks for any help

karmic nova
#

How i do for download "Visual Studio Editor Package version 2.0.14 is available" in all new Projects? Without " windown - package manager" in every new project
sorry for my english and i so sorry if this canal dont its done for my problem

tough cairn
#

any ideas how to make custom editor script for terrain shader ?

gloomy chasm
tough cairn
#

that would be the top one

#

"Mat Terrain Adaptive"

#

its collapsed in the first image above

gloomy chasm
#

What?

gloomy chasm
#

Oh, you mean for a terrain layer?

tough cairn
#

yes

gloomy chasm
#

Oh, you said terrain shader originally

tough cairn
#

sorry didn't mean that

gloomy chasm
#

Np, was just confused. I think you can just create a custom editor for it and it will override the other one?

tough cairn
#

so just a custom editor for the material as usual ?

gloomy chasm
#

I think

#

OH

#

I see what you are saying

gloomy chasm
tough cairn
#

yes

#

in the second screen shot u can see the the values i want to show per layer

gloomy chasm
tough cairn
#

im not

#

i have to edit them in the material

#

the exposed values

gloomy chasm
tough cairn
#

👀

#

interesting

#

ill try this

gloomy chasm
tough cairn
#

🙂

tough cairn
# tough cairn

here is an implementation example :

public bool OnTerrainLayerGUI(TerrainLayer terrainLayer, Terrain terrain)
{
    GUILayout.BeginVertical( EditorStyles.helpBox );
    var terrainLayers = terrain.terrainData.terrainLayers;
    var i = terrainLayers.ToList().IndexOf( terrainLayer );
    var Dist2MinMax = terrain.materialTemplate.GetVector($"Layer{i}_Dist2MinMax");
    EditorGUI.BeginChangeCheck();
    Dist2MinMax = EditorGUILayout.Vector2Field( "Distance", Dist2MinMax );
    if( EditorGUI.EndChangeCheck() )
    {
        terrain.materialTemplate.SetVector($"Layer{i}_Dist2MinMax" , Dist2MinMax );
    }
    GUILayout.EndVertical();
    return true;
}
#

any ideas how to draw a texture using gui layout without serialized properties ?

patent pebble
tough cairn
#

nvm i figured it out

#
_Splat = EditorGUILayout.ObjectField( "Texture" , _Splat, typeof(Texture2D), false) as Texture2D;
patent pebble
#

yeah you need to cast it to the type

tough cairn
#

was using a [deprecated] method

visual stag
#

There's no need to use the safe cast over a normal (Texture2D) cast btw, as the field is already constrained so that you shouldn't be able to assign an incorrect type to it

gloomy chasm
#

Is there a way to create a GUIStyle not in OnGUI?

patent pebble
visual stag
#

I just use properties

gloomy chasm
#

I am using reflection to change a style in a Unity thing. So I need it to work on initialize

#

(Just messing around)

visual stag
#

This sort of thing is always my setup

gloomy chasm
patent pebble
#

i've never had any luck with that, I usually just do a flag on the first OnGUI loop and grab the style there

#

you could also create an asset with whatever GUIStyle you need

#

and use that instead

visual stag
#

I'm not exactly sure where reflection is coming into it, I'm probably missing something

gloomy chasm
patent pebble
#

@gloomy chasm your problem is that whatever style you want to use is null at initialization time, right?

gloomy chasm
patent pebble
#

hm, never ran into that particular error before, but I do get all the time the "style is null" when I try to get them on constructors

visual stag
#

There's probably a way to set the style before calling it, but I have honestly never had the need to try

gloomy chasm
#

Ehh, too much work anyway. I was just wanting to mess about with editor styling for fun haha

#

Wanted to see if I could get the editor to look more like those mockups

patent pebble
#

@gloomy chasm you can save the style you want to use to a ScriptableObject asset with a GUIStyle field and use that style instead of trying to get it from EditorStyles or whatever

#

at least I think I've done that in a couple of situations

#

can't remember exactly

visual stag
#

They're trying to modify editor styles, not use a style

#

which is why it's complicated because they would like to not run their own GUI to do that

patent pebble
#

right but can't they just assign an entirely new style to Hostview background style? instead of just modifying it?

#

i might be misunderstanding

gloomy chasm
patent pebble
#

right, you can store it in an asset and load it tho?

#

at least I think you can

gloomy chasm
#

Idk, it is getting late for me and I don't care that much about it. I appreciate the help though!

visual stag
patent pebble
#

yeah I guess it depends exactly on what the situation is

#

@gloomy chasm i tried changing the HostView.Styles.background style and the DockArea.Styles.background style
it seems to have no effect on how windows draw
Changing the HostView.Styles.paneOptions however does affect it

#

you can essentially disable the options button, it doesn't even get input if you change the style

#

so i guess the GUI for the background is handled different, maybe cached internally somewhere or something

#

maybe other steps are required such as manually triggering a reconstruction of the HostView, or ContainerWindow or something

#

but I don't know how safe that sort of stuff is, haven't dug that deep into the topic

#

and changing a static GUIStyle that is used internally in all visible windows doesn't sound like a great idea 😅

barren moat
#

@patent pebble are you trying to draw gui into the window? Can you do what you need with OnGUI?

chilly ibex
#

Hey all, I'm creating a custom editor which will allow me to quickly make xml configs for waves of enemies. What I'm currently attempting to do is get all the properties from the Wave struct and serialize it for the editor window to allow the user to input values for each section. Here's an image of what i've got so far but I'm not sure how I could then create an appropriate field of the correct type in which to pull the information back out of the editor window. I could hardcode it but ideally would love to be able to create something that will dynamically update as I inevitably add more into the Wave struct.

waxen sandal
#

You should use SerializedObject and SerializedProperty

chilly ibex
#

I see! if I'm understanding correctly this would look similar to the normal inspector? Similar to this attached image?

waxen sandal
#

Yeah you can do that if you want

barren moat
#

What do you need the XML for?

chilly ibex
# barren moat What do you need the XML for?

Trying to make my game as modular as possible, basically everything will be loaded from the xml's so it'll be super easy to customise externally.
Ended up using a SerializedObject to just expose the struct I needed to populate with information in custom editor window.

silver star
#

Hi everyone!
I have an error Internal build system error. Backend exited with code 2.. I don't know what to do...

patent pebble
#

I was trying specifically to make an EditorWindow transparent

devout oracle
#

Like see thru the editor window?

patent pebble
#

I was also trying to draw a texture outside of an EditorWindow

patent pebble
devout oracle
#

That sound sticky if so. You have to find a way to hook indo the os's window rendering I should think 🤔

#

Though you could maybe try autohotkey for something like that. They have window transparency stuff but I can't say how robust it is

patent pebble
#

I dont think so, the engine itself is in charge of how EditorWindows are rendered to the screen, not the OS

devout oracle
#

Ah, kk nvm then. :) this might be of interest though for a simple hack https://www.autohotkey.com/board/topic/92855-window-transparency/

#

Totally untested for this situation though😜

soft zenith
#

Hi people, is there a way of doing something like [Header("")] in a custom editor ?

#

here's how my editor is currently, i wan't to make some kind of header to organize things better

[CustomEditor(typeof(HierarchySeparator))]
[CanEditMultipleObjects]
public class HierarchySeparatorEditor : Editor
{
    [Header("Outline Settings")]
    private SerializedProperty _outlineSize;
    private SerializedProperty _outlineColor;

    [Header("Bar Settings")]
    private SerializedProperty _barColor;
    private SerializedProperty _textColor;

    public void OnEnable()
    {
        _outlineSize = serializedObject.FindProperty("m_OutlineSize");
        _outlineColor = serializedObject.FindProperty("m_OutlineColor");
        _barColor = serializedObject.FindProperty("m_BarColor");
        _textColor = serializedObject.FindProperty("m_TextColor");
    }
    
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(_outlineSize);
        EditorGUILayout.PropertyField(_outlineColor);
        EditorGUILayout.PropertyField(_barColor);
        EditorGUILayout.PropertyField(_textColor);

        serializedObject.ApplyModifiedProperties();
    }
}
gloomy chasm
tulip mantle
#

Can anyone point me to an example of an inspector array where each element contains it's own buttons & properties ... or how to add buttons to each array object.

tulip mantle
slim zinc
#

google is your friend

tulip mantle
slim zinc
#

you can find how to create buttons, you can find how to access elements. it's your job then to put that knowledge to use and combine these elements

tulip mantle
#

So , I guess this Discord is just a waste of my time. Ask for support because you can't find any reference to the codgin I'm trying to do and you get told to research it yourself ... Good job 😉

slim zinc
tulip mantle
tulip mantle
slim zinc
#

microsoft's documentation is really good and straight to the point. you can easily figure out what to do if you already know how to start.

patent pebble
#

i agree that providing those kind of answers isn't really helpful
it's better to do a follow up question asking the person to provide more context

#

@tulip mantle i'd also suggest you ask questions here in a more comprehensive manner
your question is a little bit generic and doesn't give too much to go on

slim zinc
#

+1 to that

patent pebble
#

telling someone who is stuck on a problem to "just google" isn't really helping 🤷‍♂️

slim zinc
#

and that is not what i did. i told them what to google and then to connect the findings

patent pebble
#

i'd try to at least provide them with useful terms or related searches so they have a little nudge in the right direction

tulip mantle
patent pebble
#

specially in the context of doing editor extensions for unity the terms are very generic and if you don't know what to google you are most likely gonna get results related to actual runtime and gameplay engine stuff

#

googling "inspector array elements" usually yields stuff unrelated to editor extensions

slim zinc
#

of course. but you can tell that they're unrelated by merely looking at the answers

tulip mantle
patent pebble
#

@tulip mantle well if you are making a custom Editor class (commonly referred to as "custom inspectors") you could get the array property, and get each array element serializedproperty and use them on your GUI/GUILayout

#

google "SerializedProperty array" and you'll probably get some examples

slim zinc
#

exactly

patent pebble
#

don't know what your level of knowledge is in terms of custom Editors so it's hard to tell

#

if you have further questions or don't understand something feel free to ask here, people will help

tulip mantle
patent pebble
#

no problem

slim zinc
#

literally the same help

patent pebble
tulip mantle
# slim zinc literally the same help

In your dreams perhaps ... don't recommend you take up a job in tech support.
*Really, I'm obviously writing a custome inspector and you tell me to "write a custom inspector" and then you tell me to Google what I'm looking for.

patent pebble
#

i think somewhere in there there's something about SerializedProperty arrays

slim zinc
trail dawn
#

Enough already

#

Why is it that every conversation you're apart of, turns into a debate.

slim zinc
#

because people don't think

trail dawn
#

That must be it

#

Move on, they're already getting enough help from MadLed. You don't need to be the dude in the corner trying to get the last word in.

slim zinc
#

also this is biased. i've had plenty of conversations in other channels, especially #archived-dots where it never turned into anything alike

#

just saying

trail dawn
#

Yes, yes, you've been muted multiple times for having a cheery attitude to other community members.

#

Keep it up. 👍

slim zinc
#

what's that supposed to mean?

trail dawn
tulip mantle
#

@patent pebble ... Found what I wsa looking for! Thanks for the 'KICK' in the right Google dirction 😉

slim zinc
#

i do happily provide help. but i hold up some standards. 1 -thinking required 2 -style required 3 -no trivial questions you could've googled yourself in 5 minutes 4 -be willing to put some effort in yourself. no bite sized feeding @trail dawn

patent pebble
#

getting started in making unity editor extensions is a pretty daunting task
custom Inspectors and EditorWindows are usually the gateway into this world
so i expect people to struggle and get stuck on those 2 specific topics
i somewhat agree that some people get "lazy" with their questions, probably out of frustration
but we have to give people some leeway, we are all on the same boat

#

at least that's my approach 🤷‍♀️

slim zinc
#

of course

tulip mantle
# slim zinc i do happily provide help. but i hold up some standards. 1 -thinking required 2...

@slim zinc ... 1. I was thinking in the incorrect terms, MadLed helped. 2. Not sure what that means. 3. Google is useless if you are not searching for the correct terms (see 1 above). 4. You have NO idea how much effeort anybody is willing to put forth. I asked for a reference, a nudge in the right dorection, not for someone to write it for me and MadLed helped whereasy you were utterly useless. Good luck with your standards 😉

patent pebble
#

instead of being confrontational we should aim to "train" people on how to ask better questions 🫂

slim zinc
visual stag
#

Making custom inspectors is only really desired when you intend to restyle or restructure content that exists across many serialized types

#

If that button does something in that object external to the type you're serializing in the array then you're going to need the custom inspector though (unless you want to get very overcomplicated)

patent pebble
#

each array item has it's own buttons and properties.
maybe they're asking about each element having different stuff in them?

#

not sure

tulip mantle
#

@visual stag ... And therein lies the trick, Custom Inspectors are suppsoed to make development easier ... so how much time do you want to invest in one Custom Inspector vs. gettin on with the rest of your developmet.
@patent pebble ... each elememt will be identical 😉

patent pebble
#

yeah then I would probably do a PropertyDrawer instead of a custom Editor

slim zinc
#

tool development easily takes at least 1 / 3 of the time you need for the project itself. they have reusability though

tulip mantle
#

Exactly 😉

#

I guess I'll just have to slep on Custom vs. Drawer then 😉

patent pebble
#

doing a PropertyDrawer will take you more time if you've never used them
a custom Editor is a little bit more manageable if you are still a beginner

#

but in the end both approaches are very similar tho, it's not like it's gonna take you too long to learn

tulip mantle
#

Does this look like beginner code?cs // Section header GUILayout.Label("Logging & Timer...", LabelStyle); // Log Failures tContents = new GUIContent(" Log Fails?", "Check if you want to log failed placement attempt inforamtion."); mtp.TreeSetup.LogErrors = EditorGUILayout.Toggle(tContents, mtp.TreeSetup.LogErrors); // Ignore Timer EditorGUILayout.BeginHorizontal(); tContents = new GUIContent(" Use Timer?", "Check if you want set the maximum 'Time allowed' for Tree planting."); mtp.TreeSetup.UseTimer = EditorGUILayout.Toggle(tContents, mtp.TreeSetup.UseTimer); if (mtp.TreeSetup.UseTimer) { tContents = new GUIContent("» Time Allowed", "The maximum time allowed (in seconds) for Tree placement. The process is exited if time allowed is exceeded."); mtp.TreeSetup.ProcessTime = EditorGUILayout.IntField(tContents, mtp.TreeSetup.ProcessTime); } EditorGUILayout.EndHorizontal();

#

I'm really asking! ... No other devs to bounce my work off so I could be doing things the hard way :S

slim zinc
#

looks ok

visual stag
tulip mantle
#

Peer review is a GOOD thing 😉

#

Have done a few custom editors ... no drawers yet so I guess it's time to get cracking 😦

patent pebble
#

and modular is cool 😎

#

@tulip mantle as a general guideline for IMGUI stuff
i'd use SerializedProperties instead of fields directly, to get undo support and automatic styling

#

it takes a smidge more time to set up, but it's a lot better

slim zinc
#

i only use UI Elements for both of these now. makes it much easier. unfortunately you, as of yet, have to write the whole inspector window from ground up since unity has not yet switched to UI Elements only

tulip mantle
#

I tend to get a bit too aestetic in my custom editors 😉

patent pebble
#

i try to stick as much as I can to the default Unity style

#

my rule of thumb is to only use stuff that I can get from the engine itself (textures, icons, styles, etc)

#

and I rarely touch colors, mostly only borders and text colors

slim zinc
#

you'll pack it into a package anyway

patent pebble
#

it's just my design philosophy 🤷‍♀️
if I can show a tool to someone, and they're not able to tell if it's a default Unity feature or something I've made myself, i count myself successful

slim zinc
#

maybe. makes it hard to distinguish features though and reduces recognizability

visual stag
#

It helps people know how to use it without having to parse an entirely new style or format

patent pebble
#

UI, as much as it is based on having pleasing, and easy to use stuff
is also about being the less disruptive possible

#

It helps people know how to use it without having to parse an entirely new style or format
this 💯

#

i've dropped plenty of my own home brew "superior" implementations because they are not aligned with the default Unity functionality

slim zinc
visual stag
#

I don't know what any of these are, whether they're headers, buttons, toggles, etc without actually looking at their content and/or using them

slim zinc
patent pebble
#

i was making a "better" version of IMGUI sliders, but i asked myself
"what's the point of making my own inspector slider, that has more features, if those features are at odds with the default Unity sliders?"
what's the benefit of having a small extra feature if I'm always gonna be confused wether the slider i'm interacting with is a default one or a custom one?

#

of course, some tools warrant that, because they offer great benefits to the editor workflow
but not all do

visual stag
#

The point is that custom looks make things less intuitive to use. The point is not about avoiding colour or icons

slim zinc
patent pebble
#

but having a slider that looks different than the default one is also bad UI design
if I look at two sliders that look completely different but they work mostly the same...
that's gonna introduce a massive amount of confusion to the user
and it's gonna break visual consistency, which it's also a bad thing

slim zinc
#

you can't just slap more features on something that already exist and expect it to not be confusing because the existing things already serve their SPECIFIC feature

slim zinc
patent pebble
slim zinc
#

that makes no sense

tulip mantle
visual stag
slim zinc
# patent pebble i disagree

if they can both work the same or different, then you can easily add something like a lock icon or similar representing this

#

because they can't do both at once

tulip mantle
#

GUIs are NOT as easy as they seem to be 😉

slim zinc
#

that's why UI designer is a real job

patent pebble
#

i was speaking in the context of adding small features
lets say slider A supports mouse scrolling
and slider B doesn't
that small change would not warrant a completely different slider style because it would introduce too much constrast and break cohesion
and having the same visual style for both sliders would also be confusing
so, in my opinion, the best outcome is to not introduce the feature at all

tulip mantle
#

And just when you think it's good they throw in 508 compliance 😉

slim zinc
patent pebble
#

i would add the feature if I was able to introduce it to the default Unity sliders

#

but since that's not the case, it's better to drop the feature

slim zinc
patent pebble
tulip mantle
#

@patent pebble... I'd have to disagree. The average computer users know what a slider is/does ... so having them on ranged properties even though for totally different things is OK.

slim zinc
#

they already serve a specific purpose

slim zinc
visual stag
#

We really do not need the ol' all-caps screaming about a slider.

patent pebble
#

sliders can be selected, or not

slim zinc
patent pebble
#

i think he was just joking 😅

#

sliders already accept keyboard input when they are selected, adding mousewheel input support can be a benefit for a lot of uses

visual stag
#

I'M NOT SCREAMING I'M MERELY HIGHLIGHTING

slim zinc
#

+1

slim zinc
#

cause that was a design decision

#

the same in programming. DO NOT modify. ONLY extend -> open closed principle

visual stag
#

I don't think scrapping a feature really feels warranted. Just adding a small icon like they say would be a fine way to indicate that change exists

slim zinc
#

+1

patent pebble
#

i just ended up dropping it mostly because i didn't want to add an unnecessary point of confusion

visual stag
#

But all of this is pretty beside the point, the point was that that icon should just look cohesive. Making it the same scheme and not look like a bug on the screen

slim zinc
#

that is definitely the case. if you have ui that looks like a bug, that's just terrible design then

visual stag
#

You don't need to redesign the wheel of how the slider looks to implement changes, and when you do for some reason need to make a whole new control, it can just use the same colour scheme and indicators

patent pebble
#

yeah pretty much

visual stag
#

Colour scheme does not exclude new colours, just means that you're not drastically altering the general values in relation to other controls

patent pebble
#

i'd definitely implement scrolling on sliders in standalone editor tools for example
but not for regular inspector stuff

patent pebble
#

blue for selection, green for physics-related sfuff, etc

#

and I think Unity's UI design is pretty good anyways

#

i like it a lot better than Unreal's

slim zinc
#

definitely. but if you introduce completely new features, don't be afraid to give them distinct design

patent pebble
#

i like minimalistic design in general for UI stuff
a lot of grayscale, unsaturated colors, low contrast, etc

slim zinc
#

yeah

barren moat
#

Can I use an attribute for a custom SO editor?

#

In the same way you can put an attribute on a property

waxen sandal
#

No

#

(afaik at least)

slim zinc
#

I'm not sure what you want to accomplish

waxen sandal
#

They want a propertyattribute for custom editors

barren moat
#

The same thing you'd do with a property attribute.

slim zinc
#

``[CustomEditor(typeof(LookAtPoint))]
[CanEditMultipleObjects]
public class LookAtPointEditor : Editor
{
SerializedProperty lookAtPoint;

void OnEnable()
{
    lookAtPoint = serializedObject.FindProperty("lookAtPoint");
}

public override void OnInspectorGUI()
{
    serializedObject.Update();
    EditorGUILayout.PropertyField(lookAtPoint);
    serializedObject.ApplyModifiedProperties();
}

}``

aren't you already always writing a custom editor for 1 specific kind of asset?

marsh grove
#

Hey how can I set a custom Icon for my scriptable object depending on an enum property?

barren moat
#

aren't you already always writing a custom editor for 1 specific kind of asset?
Yes. Hence the question.

#

I was already doing that, now I'm looking for a solution to write one for assets with a given attribute.

slim zinc
teal timber
#

can i get a Handles.Label to draw in front of unitys' default transform handles?

barren moat
gloomy chasm
#

What would you do? Like you couldn't edit any values because you wouldn't know the type

slim zinc
#

Yeah I'm at a loss too

patent pebble
#

all I can think of for a possible use case for that would be having a single Editor with selective logic instead of multiple inherited Editors
something like:

public class Parent : ScriptableObject{ }

public class Child1 : Parent { }

public class Child2 : Parent { }

[SomeAttribute]
public class Child3 : Parent { }

[CustomEditor(typeof(Parent), true)]
public class ParentEditor : Editor
{
    public override void OnInspectorGUI()
    {
        // if target type has SomeAttribute: Draw some Button

        // else: Don't draw button
    }
}
#

but i don't know how robust that design would be

#

and it seems redundant anyways

#

@barren moat what's exactly your potential use case in this?

gloomy chasm
#

@onyx harness Kind of late, but... You were 100% right! The System.IO.Directory class takes relative paths! That is going to pretty my code up in several places, so thanks!

barren moat
# gloomy chasm What would you do? Like you couldn't edit any values because you wouldn't know t...

@patent pebble @slim zinc

There are ways of iterating the fields via reflection. You can create a serialized object for example, which exposes iteration helpers.

Or you can just do something custom and call "draw default inspector", which internally uses reflection to iterate the fields.

In my case I want to add a field to set the "name" of a scriptable object when it is nested beneath another, as the "rename" function doesn't work for nested assets.

#

I mean if it wasn't possible to dynamically create an inspector then how does the default inspector work?

gloomy chasm
gloomy chasm
barren moat
patent pebble
gloomy chasm
gloomy chasm
#

@patent pebble I realized that code I posted the other day for separate undo/redo events doesn't work because selection is added to wherever you are and does not clear the redo... -_-

barren moat
#

Thanks @gloomy chasm

#

I guess the other way to write a global inspector would be to create one on Object. I think that's how naughty attributes works

gloomy chasm
# patent pebble ouch 🙃

This is the 3rd solid day messing with the undo system trying to get it to work how I need. Would be really nice if they provided some of these things since they would be so trivial to do on their end

barren moat
#

And then you can check for attribute and exit early

#

Draw default

gloomy chasm
patent pebble
plucky nymph
#

Not sure if this is correct channel, but closest I can find.

Im making a custom package (here: https://github.com/DraconInteractive/Dracon.Packages.Core.git). This isnt my first package, but it is the first to utilise the 'samples' feature. I finally got my samples working after adding the 'files' section into my package.json, but now my scripts that were working before I got samples working, are now not detecting the namespace of my package scripts (Dracon.Core). I believe its something to do with that files area in the package.json, but I havent yet figured out what. I also cant find the documentation around that section in the unity docs, I had to find it from a forum post.

Its only one error, but if I were to comment it out on that script it just shows the error for the next file that references it.

barren moat
#

Oh your samples are unity packages? They should just be raw files.

#

You can do one or the other. Either include unitypackages in the package for the user to import, or you can just have a samples folder.

#

(looking at current master of your project)

plucky nymph
#

Riiiight gotcha. I actually hadnt caught this, but when im importing the samples right now, its auto-extracting the unity package

#

which is more interesting than anything else

#

ill change them back to files

barren moat
#

Oh that's cool. Well maybe I'm wrong

plucky nymph
#

I also hadnt considered having a separate asmdef for samples, I currently just have a single one at the root of the package

barren moat
#

But it seems unnecessary.

#

I wouldn't usually include unity packages in version control, because they're binaries.

#

(unless you have a specific release branch where you bundle them up before you push to it)

#

Otherwise you won't get proper change history on them

plucky nymph
#

The packaging thing was more that certain prefabs are going to be dependent on other packages, and with unity packages the end user could choose what to import from what unity package

#

I might actually just remove the samples all together and just have the packages

barren moat
plucky nymph
#

That would be a lot of samples though

#

(eventually)

barren moat
#

Not one per currently existing unitypackage?

plucky nymph
#

My idea was to have a players sample folder filled with types of player unitypackages. VR players, mobile players etc. If each of those is its own sample it could get big quick

barren moat
#

(using "unitypackage" to talk about .unitpackage files, and "package" to talk about UPM package)

barren moat
#

But you said something about depending on other packages, were you talking about other UPM packages?

#

Because there is a tool for that too that might interest you.

plucky nymph
#

yeh I have a few packages that work together in a fun modular way to expand on functionality. So if you want VR methods, you import vr, and in another package like my stats package, you can reference the VR package for certain vr-friendly stats.

barren moat
#

Right right. Yeah I think that's a bit fiddly, but I don't see an issue with putting each in its own sample

#

The other temptation is to put each in a separate asmdef that can be included individually as required

#

But I think the assembly still gets included in the build

#

If you're concerned about optional dependencies you can use this feature

#

(screenshot from UniTask)

plucky nymph
#

My main issue is that its only 2 right now, but if i have 7 player types, 10 template scenes, etc, thats a bucket of samples

barren moat
#

It's like a la carte modules

#

It's either samples or separate packages

plucky nymph
#

Eh, feels like a bad user experience, a wall of packages. Im going to experiment with just including the unity packages in the core package

#

instead of having them as samples

barren moat
#

Isn't that the same?

#

Just means that you miss out on change history in git

#

Samples folders function in basically the same way as unitypackages

plucky nymph
#

By including in the base package i can introduce file structures to help sorting etc. So instead of a wall of package names to choose from, you can navigate to Modules->Players->VRPlayer

#

Very subjective, its just what I would prefer if I were the end-user, and I generally am for these haha

#

hmm the unitypackages arent showing up...

#

Looks like the metas are getting extracted, but not the actual file

patent pebble
#

hmmm I'm getting strange results trying to get Local File IDs for subassets...

#

the bottom result is always correct in accordance to the File ID in the actual .meta file

#

i don't even know how to interpret the result I get on the top one...
where the heck is that number coming from?

#

AssetDatabase.TryGetGUIDAndLocalFileIdentifier also yields the correct result

barren moat
plucky nymph
#

@barren moat think i solved both my initial problem and my new problem haha. The file declaration apparently needs you to specify file structure, not just filetypes. So im pretty sure samples will now work if I implement them.

zenith estuary
#

Those are the same value, the second one is just displaying it as a signed value

#

While the first one is unsigned

#

long vs ulong

#

If you cast it to ulong it should be what you expect

#

(cc @patent pebble)

patent pebble
#

@zenith estuary ooooh damn, good catch!

zenith estuary
patent pebble
#

i didn't think of that heheh, stupid me 💀

zenith estuary
#

Easy to miss 😄

patent pebble
#

what a weird design decision in their part...

#

given that the .meta files have signed longs

zenith estuary
#

I'm surprised the meta files don't store them in hex

patent pebble
#

so much for GlobalObjectId: Struct providing an API for stable, project-global object identifiers.
such a stable identifier that doesn't match the meta file 🙃

#

i wonder if this is a bug or just one of those weird design decisions they do sometimes to not break some of their internal things

zenith estuary
#

I wouldn't be surprised either way honestly

#

lol

patent pebble
#

gonna file a bug report anyways, just in case

zenith estuary
#

Looking at the PDB files included with the engine, which reveal the internal data types

#

It appears to be signed in the C++

patent pebble
#

hmm, interesting

#

so i guess this is probably just an overlook

zenith estuary
#

Yeah I can't find any instances of it being unsigned inside the engine

#

So it's probably just a mistake or weird decision to expose it as unsigned in GlobalObjectId

#

That said, it being unsigned does make more sense

patent pebble
#

yeah

#

maybe they wanted it to be more "readable"? not that such numbers are human-readable anyways lol

zenith estuary
#

Honestly no idea

#

It's weird all around

patent pebble
#

It's weird all around
that's the Unity life 🙃

zenith estuary
#

What I'm more disappointed about is that GlobalObjectId is editor-only :(

patent pebble
#

lots of cool things they do that are editor-only

zenith estuary
#

One of the most painful ones is SerializedObject & SerializedProperty

#

They're essentially a way to expose the internal TypeTree/TypeTreeIterator classes to C#, which still exist in builds, yet we can't use them

#

As a result, there's a lot of dumb API mistakes you can't work around like Font.lineHeight being read-only

#

You can create a Font at runtime, but not change its line height, so it's basically useless 🙃

#

If you want to take a dive into insanity, I wrote this article for a third party Unity wiki a while ago that shows how you can work around that one specific example: https://uninomicon.com/objectlayout

patent pebble
#

insanity
that's the Unity life 🙃

patent pebble
zenith estuary
#

I have so much random obscure knowledge about engine internals I should put together somewhere

#

It's just that writing it all up takes so much time

patent pebble
#

yeah

#

i have a bunch of tutorials and stuff for editor tools on the backburner, but it's just like... "eh, got other things to fix first"

zenith estuary
#

That's basically what happens every time I think I should write something lol

patent pebble
#

i feel like we are gonna lose a bunch of collective knowledge because of Discord

#

everything used to run through the forums

#

in 5 years, there's not gonna be anything useful on the forums because everything is just gonna be outdated

zenith estuary
#

I feel that's already starting to take root

patent pebble
#

where are asset's LocalFileIDs stored?

#

i remember maybe they are somewhere in the Library folder? not sure

#

but can't remember exactly where

zenith estuary
#

I don't think all assets have one, for those you have to rely on the guid

#

LocalFileID is only for assets that have multiple objects within them, after all

#

If you think of an asset like an array, the local file id is like an index into it (sort of)

patent pebble
#

@zenith estuary hmmm so for example i have an asset with this LocalFileID
-3064384677914267713
but I can't find it in the class ID reference

zenith estuary
#

Those aren't local file IDs

#

Those are internal IDs referencing serialization info

#

They correspond to internal C++ classes

#

I'm actually surprised those are documented

patent pebble
#

i thought the LocalFileIDs were the same as those Class ID references but multiplied by 100000

zenith estuary
#

Nope

#

There's no correlation

#

The class IDs are what you see after !u!

#

the class ID for RenderSettings is 104

patent pebble
#

a TextFile (TextAsset) gives me this LocalFileID
4900000
and the reference ID for a TextAsset is
49

#

hmmmm

zenith estuary
#

That's likely coincidental

#

Or perhaps they use the class ID to generate the file ID sometimes

#

But as far as purpose goes, they're unrelated

patent pebble
#

it's consistent across many types: MonoScript, Text File, AnimationClip, etc

#

and every time I need to figure out what a FileID was, i've used that Class ID Reference list

zenith estuary
#

Looking at disassembly of some of the engine functions, it looks like the local file ID is a hash of sorts, and the class ID is potentially one of the sources for that hash

patent pebble
#

but this LocalFileID is a custom file type (a text file that uses a custom Scripted Importer)
-3064384677914267713
so I guess I'm trying to understand how it's generated

zenith estuary
#

A TextAsset only has one asset in it, so nothing else is merged with that value, so the hash ends up being equal to the class ID * 100000

#

Yep, it looks like it is indeed just a hash of class ID + offset

#

int64_t MakeLocalFileIDSequence(int typeID, int64_t offset)

#

There's also int64_t MakeLocalFileIDWithHash(Unity::Type const *type, int64_t offset)

#

So that solves that mystery

#

The latter appears to hash the type name with the offset, which would explain the large value you got earlier

#

So a file ID is generated by hashing either the type name or ID with an offset value

patent pebble
#

@zenith estuary ah, so it's just probably generated from the name of my custom asset type?
the name is "Example"

zenith estuary
#

Most likely

patent pebble
#

is there an exposed API to generate the same hash manually?

#

this is a little bit out of my knowledge

zenith estuary
#

Here, I reconstructed the function from the assembly:

public static long MakeLocalFileID(int classId, long offset)
{
    offset *= 2;

    if (classId >= 0x800)
        return offset + 0xC7282226 * classId + 0x1C6BEEECF2EED000;

    if (offset >= 100000)
        return offset + 1000000000000000 * classId + 9999900000;

    return offset + 100000 * classId;
}
#

I really don't want to reconstruct the one that uses a name lol

#

As far as I know there's no function for this exposed publicly

#

Also I'm not 100% confident in my assembly transcribing skills, so try verifying that against some examples

patent pebble
#

@zenith estuary alright! i understand a lot better what's going on behind the scenes
unity IDs stuff has always been a bit of a confusion-inducing topic for me

#

thx a lot! 💙

zenith estuary
#

It's a bit of a black box yeah

#

I guess I can add this to the long list of random obscure knowledge I have lol

patent pebble
#

hehehe yeah

zenith estuary
#

Not that I'm ever going to remember that algorithm

#

One has to wonder though

#

Why does this concept even exist

#

Why don't they just store the offset?

#

The class id is already known in the file, so what purpose is there in this being a hash?

gloomy chasm
#

Yup everything is fine with my code... no problems here xD

patent pebble
zenith estuary
#

Yep, I'm intimately familiar with that source file

#

persistentTypeID is another name that class IDs are referred to by

#

UnityType is basically the C#-side version of the RTTI class in the engine code

#

Or rather, Unity::Type, which is just a wrapper for RTTI

patent pebble
#

ah right maybe they do the offset thingie to get a long

#

because the UnityType uses an int for the identifier

#
public int persistentTypeID { get; private set; }
#

there's an obsolete method for LocalFieldIDs that used ints before, but now they use longs

zenith estuary
#

It's an int since it's just an enum internally representing what C++ class it is

#

The class IDs page is basically just a list of values from that enum

#

I'm really not sure why they even need longs here tbh

patent pebble
#

they have this warning in the docs

Warning: Avoid the obsolete versions of this function, which use int for the localId parameter instead of long. Local Ids can be longer than 32 bits in some cases, such as for Prefabs. When Unity serializes an asset reference it points to two things: the GUID and file ID. GUID is a unique hash, and file ID is a value relative to the asset. Both of these values are used when a serialized asset references another asset.
so I suspect it's related to the reason why

zenith estuary
#

if an asset has over 4 billion objects inside it, I think you'd have other problems lmao

patent pebble
#

yep lol

#

maybe some weird obscure internal reason

zenith estuary
#

probably

#

I don't know enough about this specific corner of the engine's depths to say for sure

patent pebble
#

hmmmm, seems like ScriptedImporters don't register their types as UnityTypes
can't find mine on the static list of all types....

#

so i'm still at a loss as to where the LocalFileID is generated from 💀

#

in fact, calling this to try to get the Class ID crashes the editor lol

[FreeFunction("AssetImporterBindings::LocalFileIDToClassID")]
extern internal static  int LocalFileIDToClassID(long fileId);
zenith estuary
#

There's similar behaviour for ScriptableObjects

patent pebble
#

right, but for example some of my ScriptableObjects were part of those IDs along with the Native types, that's why iwas expecting my custom asset types to be assigned IDs in a similar fashion
didn't dig far enough to see what was different about those specific ScriptableObjects

#

eh, i give up for now, i was just curious to see if there was a unified way of getting those IDs

#

I guess it's yet another one of those unpredictable Unity quirks 🤷‍♀️

barren moat
#

Does anyone know how to rename a nested asset and have it update in the project window?

#

None of this seems to do the job:

 using UnityEditor;
 using UnityEngine;

namespace EffortStar.Editor {
  [CustomEditor(typeof(AttackActionConfig))]
  public class AttackActionConfigEditor : UnityEditor.Editor {
    public override void OnInspectorGUI () {
      var prev = target.name;
      var next = EditorGUILayout.TextField("Name", prev);
      if (prev != next) {
        target.name = next;
        EditorUtility.SetDirty(target);
        AssetDatabase.SaveAssetIfDirty(target);
        AssetDatabase.ForceReserializeAssets(new [] { AssetDatabase.GetAssetPath(target) });
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
        AssetDatabase.Refresh();
        EditorApplication.RepaintProjectWindow();
      }

      base.OnInspectorGUI();
    }
  }
}
#

But if I close and reopen the project window it will update.

#

This is me basically throwing every conceivable operation at it, to no avail.

whole steppe
#

I wanna revert to this commit

#

when I click it it creates error files

barren moat
#

If you want to revert a commit you can do git revert <sha>

#

I don't know what program that is

whole steppe
barren moat
#

Usually you can right click on the commit and choose "revert"

whole steppe
barren moat
#

You'll need to resolve the conflicts

whole steppe
#

what does that mean?

barren moat
#

It means that there is no automatic way for git to revert the file, probably because you've modified the same line since.

#

So it doesn't know what line to revert it to

patent pebble
#

@barren moat iirc i have a utility class thaf rebuilds the project view to refresh its state, i think i used it for dealing with sub-assets too
not at my PC right now, about to hit the bed
I can dig it out tomorrow for you

zenith estuary
#

The commit hash

barren moat
#

It sounds like they've already worked out how to revert it.

zenith estuary
#

In GitHub Desktop you can switch to the history tab and right click the commit to revert it

barren moat
#

Just that there are conflicts

patent pebble
# barren moat Thanks, that could be useful!

I've learned that dealing with stuff like that often requires to "rebuild" things
i have to do it for a bunch of Inspector tools
and for the Hierarchy and Project, because it's often not enough to change an Object's data, you need to force the engine to reflect those changes in the internal data structures (TreeView, etc)
there's probably ways of refreshing the data without forcing a rebuild, but it's just way easier to do the rebuild

slim zinc
zenith estuary
#

I simply do not encounter conflicts woke

barren moat
barren moat
patent pebble
whole steppe
barren moat
#

You'll need to do that in your text editor.

#

Or a conflict resolution tool

#

I don't know if GitHub Desktop has one, but I use p4merge

#

(kind of annoying to download, but it's very good)

slim zinc
barren moat
#

That's what I'd expect. Does it come with one?

#

I think most IDEs should have built in conflict resolution.

slim zinc
#

i think so. i always use vs code though

barren moat
#

I can do it via VSCode.

whole steppe
#

and creates conflicted stuff

#

@barren moat

barren moat
tough stream
#

Hi! i'm having some struggles with GUIStyle.CalcSize, i think.

#

Here's a bit of my code:

labStyle.fixedHeight = labStyle.CalcSize(lab).y;
                labStyle.normal.textColor = Color.white;
                Rect labelRect = new Rect(rect) {
                };
                labelRect.height = labStyle.CalcSize(lab).y;

                EditorGUI.LabelField(labelRect,lab,labStyle);
                Rect buttonRect = new Rect(labelRect) {
                    
                };```
#

so i've got a label, which may or may not be on several lines. My question might be simple: does CalcSize take wordwrapping into account?

#

because rn, my button is set to have the exact same size as the label, and in reality, here it is:

#

oh well

#

this is... Peculiar.

#

(even more peculiar is the fact that this might juste have been patched? Cuz it's not working for me now, on unity 2021.2.8; here's my new code:)

GUIContent lab = new GUIContent(actionsStr);
                GUIStyle labStyle = new GUIStyle() {
                    wordWrap = false,
                    alignment = TextAnchor.UpperLeft,
                };
                labStyle.fixedHeight = labStyle.CalcSize(lab).y;
                labStyle.normal.textColor = Color.white;
                Rect labelRect = new Rect(rect) {
                };
                labelRect.height = labStyle.CalcSize(lab).y;
                labStyle.wordWrap = true;
                EditorGUI.LabelField(labelRect,lab,labStyle);
                Rect buttonRect = new Rect(labelRect) {
                    
                };```
slim vector
#

so i've created a custom editor and i want the Preview Material to remain the same after closing and opening Unity again

#

is there a way where i can ensure the material assigned persist?

tough stream
#

well, only thing i see is maybe saving it in a file on your computer. Or maybe just saving the reference to the material

slim vector
#

damn....

patent pebble
#

@barren moat

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;

public class ProjectBrowserAccessor
{
    private object _instance;
    public static Type AccessedType = typeof(Editor).Assembly.GetType("UnityEditor.ProjectBrowser");
    private static MethodInfo MI_GetAllProjectBrowsers = AccessedType.Method("GetAllProjectBrowsers");
    private static MethodInfo MI_ResetViews = AccessedType.Method("ResetViews");

    public ProjectBrowserAccessor(object instance)
    {
        _instance = instance;
    }

    public static List<EditorWindow> GetAllProjectBrowsers()
    {
        object obj = MI_GetAllProjectBrowsers.Invoke(null, null);
        return ((IEnumerable<object>)obj).Cast<EditorWindow>().ToList();
    }

    public void ResetViews()
    {
        MI_ResetViews.Invoke(_instance, null);
    }
}
#
using System.Collections.Generic;
using UnityEditor;

public static class ProjectBrowserUtility
{
    public static void ResetViews()
    {
        List<EditorWindow> allProjectBrowsers = ProjectBrowserAccessor.GetAllProjectBrowsers();
        foreach (EditorWindow projectBrowser in allProjectBrowsers)
        {
            ProjectBrowserAccessor accessor = new ProjectBrowserAccessor(projectBrowser);
            accessor.ResetViews();
        }
    }
}
#

this should do it

#

just call ResetViews after you've changed the names of your sub-assets
you may need to save and reimport the assets before ResetViews

gloomy chasm
#

@patent pebble I am so sad, I now realize what the problem is with my Undo code, and that is that if you undo 2, register a new undo, and then undo again it will think it is a redo because I am only storing the count when an undo/redo operation happens. I some how need to get a event every time a new undoable operation is added 😭

gloomy chasm
brittle acorn
#

undocked editor windows remaining on top of the main window when losing focus - any way to fix this?

#

only occurs on PC, no issues with the same release (2020.3.25f1) on OSX

barren moat
gloomy chasm
# barren moat What are you trying to achieve?

I have certain events that are triggered when an SO is changed in a certain way, but of course currently the events do not get triggered when an Undo/Redo happen. I also need to save the SO when it changes, but I think I have figured out how to do that.

#

So basically I need to know when a undo happens and when a redo happens so that I can invoke the events appropriately

#

There is Undo.undoRedoPerformed, and I can get the number of undos and redos

barren moat
barren moat
gloomy chasm
barren moat
#

Oh nice. So just run your code every time.

#

Problem solved!

#

Is it expensive?

gloomy chasm
barren moat
#

What does the code do?

gloomy chasm
#

What does what code do?

barren moat
#

The code that runs when you change something on the SO

#

sorry that was very vague ha

gloomy chasm
# barren moat The code that runs when you change something on the SO

Ah, so my events have info that is passed with them (like what was changed, how many items added etc.), so I store those in a stack, and what I want to do is to pop them from that stack on undo and 'reinvoke' the event with that data. When the data is popped, I push it to a 'redo' stack so that on redo I can again pop that data and 'reinvoke' my event.

barren moat
#

What do you need that for though?

gloomy chasm
#

A. for reliability, and B. so my editor window can update properly.

barren moat
#

Is it for runtime tuning?

gloomy chasm
#

Nah, all in editor

barren moat
#

I mean playmode sorry

gloomy chasm
#

No it doesn't touch playmode

#

It is for an editor tool

barren moat
#

What if you had a global undo/redo counter and then stored each change event in a stack along with an ID

#

I'm assuming that's the kind of thing you're thinking of

gloomy chasm