#↕️┃editor-extensions
1 messages · Page 72 of 1
Yea I know.
And the illusion here is created either by the test you did
or UnityEvent doing something else
or an other factor
Can you collapse one of the other?
Maybe the illusion only works on the first element
All the others are gonna do shit
No they do shit
The next unityevent was smaller.
I changed GetPropertyHeight. Instead EditorGUI.GetPropertyHeight I use base.GetPropertyHeight. Now they collapse and draw like it should.
But also if you say layouts will make problems in the feature I will change
I will mark it in red in my futur tutorials
Do not use GUILayout in PD if you don't grasp how works GUI and GUILayout
For your case, a lot of things might be done under the hood
That's maybe why when you fixed your GetPHeight it worked
But in any normal PropertyDrawer, when you draw from them, you use GUI.
Which is fixed in the 2D space.
By using GUILayout, you will draw after the latest GUILayout drawn.
Which can be anywhere.
If you are at the top, it will be right below the Component header.
That's why your case above (first element of the Component), it works. But it's an illusion
Yeah being forced to use absolute instead of relative layout in PD sucks
I'm too much into UIE, becuase of that now all IMGUI code looks ugly to me 
@onyx harness If you have time, I suspect I need your editor genius. I have a property drawer which draws a dropdown. On press, pops up an editor window. Code a bit like: cs bool pressed = EditorGUI.DropdownButton(btnRect, content); if (pressed) { dropDownRect = EditorGUIUtility.GUIToScreenRect(btnRect); EditorWindow.CreateInstance<MyEditorWindow>().ShowAsDropDown(dropDownRect, new Vector2(200, 200f)); }
So far this has worked well.
The problem is if I override the height for my property drawer (as I want to draw an additional element), it seems to mess with the popup window location.
I'm guessing I have a basic misconception somewhere. EditorGUIUtility.GUIToScreenRect is returning sensible values in both cases (though I've just noticed the height is 17.8 instead of 18 🤔 )
Gah, rubber ducking fixed it - thanks 🤣 . Likely because I didn't round the height for my additional value 👍
@split bridge Good job 🙂
Dont mind him, he is reluctant to open his eyes 🍿
it saves time ¯_(ツ)_/¯
also i have something to show u mikilo
Reflected code from an assembly scanned the method body into graph view
indeed
wasn't expecting so much lag
it was fast when the assembly was small
( less then 1k nodes )
but once i gave it real stuff ( in that case i was looking at Obi physics ) it was too damn slow
was thinking to auto hide elements when outside of the view port
not sure how to do that yet
gonna be adding forces to the graph next
so it will auto align using a physics simulation
aka "Force-directed graph drawing"
was thinking to auto hide elements when outside of the view port
@tough cairn It's called culling
not rly ... anyhow ill ping u if i end up doing it 🙂
||Fuck IMGUI and anyone who was developing it thinking "yeah, that shit would be scalable and actually save time!" /rant||
Yes, and it's a popular one 
ur anger is ur opinion i have nothing against u or UIE
Then why respond? 
🤷♂️
I like IMGUI for the speed.
Kinda very good for Editor world (while also very weak & poor), where you are not "really constraint"
But where I am confused is how they decided it would fit for runtime
I like UIToolkit for the speed
specifically, you get more consistent speed because you don't need to understand as much about how IMGUI works on a low level to make sure you produce high performing code
something I always like to say, Your tool could solve pi to a billion places in 30 minutes, and no one would care if they couldn't figure out how to use it
Ease of consumption is an exceptionally important facet of product design
Gah, rubber ducking fixed it - thanks 🤣 . Likely because I didn't round the height for my additional value 👍
@split bridge I find it very surprising that rounding the height fixes your issue.
I think when the height of the popup param is less than the height of the button or something like that it thinks the most optimal place is above the button - I believe anything less than 18 it would be above, anything >= 18, below
@tough cairn Graph View has a hard render limit of like 600-700 items it seems like.
if you find a way to render more let me know ;p
526 items pictured their
wouldn't instantiate more
(or maybe just stopped drawing them)
@civic river I would be surprised if that was the case tbh. But if there is a hard limit, I would imagine it would be with UIToolkit, not the graph view. That is about 18k Visual Elements there if I had to guess.
Yeah it looks like they're added to the UI elements just not rendered
childCount still goes up
I'm working on an asset that I'd like to sell on the asset store. There are features I am specifically building this asset for that are only available in versions of Unity newer than 2019, yet the Asset Store Importer says packages must be submitted with 2018.4 as the minimum. I'm having a bit of a dilemma here because I can't just disable most of the functionality of my asset to submit on an older version, that would miss the point of the asset entirely. So what do I do here?
You can submit for versions above 2018 @leaden lodge
The requirement is to handle 2018 or later
They oldest LTS
You can hit the support to ask
So I can choose to have 2019.1 as my minimum version?
hm
Yeah I think I'd rather have a definite answer, no offense
I'll contact support
Also yes - I had an asset valid only for 2020.1 or newer accepted
🙂
haha for sure yeah they're not clear sometimes
I was wondering if this was an oversight or something
But it was brought to us to support the LTS and no the 2017 or lower
For when 2019 LTS was to come
If tomorrow I am releasing an asset for 2020.1 only, they won't have a word on it
I might even say, it is somehow "advised"
Yeah I guess it's a suggestion
Because scripting editor can be hard to maintain in the long run
It's a way to release a version per yeah
2019, 2020, and so on
So now I'm sure, yes you can
The asset I'm working on is using VR features only available in 2019+ so to go back and redo parts of the asset to work with the old VR stuff would defeat the purpose, so I'll definitely just try to submit with just 2019 and see how it goes
I'm willing to guarantee if it gets rejected it won't be for lack of support < 2019 😄
What are some common things assets get rejected for?
that first one sounds harsh lmao
It is possible
If they judge that your asset is poor quality or there are already too much
it is possible
But they recently made a huge change in their backend
To automate validation
We, publishers, are pretty pleased by this change
It was hell, now it is just a little less hotter
interesting
I'm a bit nervous, this is my first asset so I'm trying to make sure all my t's are crossed, i's dotted, etc
You have a long road ahead
I hope that's a good thing!
is it possible to display the AnimationClip preview window, inside my own editor window?
my use case is i want to use it to select a frame/time in an animation
Unity's type cache doesn't scan properties, so I'm having to manually scan assemblies
public List<Assembly> GetLoadedUnityAssemblies()
{
var unityAssemblies = CompilationPipeline.GetAssemblies();
var systemAssemblies = System.AppDomain.CurrentDomain.GetAssemblies();
List<Assembly> compilationAssemblies = new List<Assembly>();
foreach (var asm in systemAssemblies)
{
foreach (var uAsm in unityAssemblies)
{
if (asm.FullName.Contains(uAsm.name))
{
compilationAssemblies.Add(asm);
}
}
}
return compilationAssemblies;
}
This works but it seems pretty hacky (and potentially slow), is their a better way to get the loaded unity assemblies for the compilation?
Also on the same line of thought, if anyone knows of a way to checksum an assembly or something, I'd like to skip scanning assemblies that haven't changed since the last time I looked
Though this whole process is way faster than I expected it to be lol
You could make hashtables of the names
But it probably doesn't matter much on that scale
How do you guys solve the loading or icons and stuff for editor stuff?
AssetDatabase requires a full path so you can't really move your directory and afaik there's no easy way to detect where it is right?
Eh, just finding the asmdef and combining it with a relative path works fine for now
How do you guys solve the loading or icons and stuff for editor stuff?
@waxen sandal I embed icons in code.
wdym?
Unity's type cache doesn't scan properties, so I'm having to manually scan assemblies
public List<Assembly> GetLoadedUnityAssemblies() { var unityAssemblies = CompilationPipeline.GetAssemblies(); var systemAssemblies = System.AppDomain.CurrentDomain.GetAssemblies(); List<Assembly> compilationAssemblies = new List<Assembly>(); foreach (var asm in systemAssemblies) { foreach (var uAsm in unityAssemblies) { if (asm.FullName.Contains(uAsm.name)) { compilationAssemblies.Add(asm); } } } return compilationAssemblies; }This works but it seems pretty hacky (and potentially slow), is their a better way to get the loaded unity assemblies for the compilation?
@civic river do you really need to compare?
yeah unless there's some some better way to get the loaded assemblies
CompilationPipeline doesn't return System.Assembly
that's why I need to compare
You can get them by name
yeah unless there's some some better way to get the loaded assemblies
@civic river OK, that's why I hate those 'var' keyword, makes code unreadable.
@onyx harness oh are you one of those var haters? Sure, it makes code unreadable when you work in notepad++ where there is no intellisense 
If code is unreadable the problem is certainly not in var
I'm in Discord, and I don't have intellisense over there unfortunately
I'm in GitHub and also don't have it
I'm on my smartphone and still no sign of it
I was referring to why you don't use it in your code
You work in IDE like VS or Rider
When in a professional world, you have to review a colleague
You won't have intellisense
Sure, but the problem is usually in variable names, not in vars
asm or uAsm is very poor names but code above is still pretty readable, no?
I don't see a problem with a small code example above, but when you get to look at 100+ line method and there are variables with weird abbreviations you can easily get fooled
I'm not even talking about local methods... That's another topic
var in foreach it's kinda obvious what's going on, unless you're casting to another type, then yeah var will be confusing
var in small local scopes is fine too, the key is proper naming, if you're gonna show your code to someone and expect them to quickly understand what's going on
Eh, just finding the asmdef and combining it with a relative path works fine for now
@waxen sandal Fwiw I also do this and don't know of a better way. Have to be really careful with UI Builder not saving asset relative paths if you use it fyi.
var in small local scopes is fine too, the key is proper naming, if you're gonna show your code to someone and expect them to quickly understand what's going on
@chilly stone And what do you think happened just there? Small code, small scope, got fooled
I will correct the word if you prefer, it makes the code less clear, less understandable
Might sound strange or even stupid for most
And I will never blame someone for not liking my way of coding
But I code in a veeery verbose way.
That's a personal preference then 👀
For the simple reason, when I read my code, my brain does not process
Yeah yeah, I'm not saying the opposite
But "var" making the code less clear is not an opinion, it's more a fact
It's making code less verbose, but that isn't always a bad thing
Dictionary<int, List<GameObject>> gameObjectDictionary = new Dictionary<int, List<GameObject>>();
In those cases I prefer var
@waxen sandal Unity uses a different naming convention to store assemblies
Or at least the compilation pipeline does not conform to anything system.app domain likes
Dictionary<int, List<GameObject>> gameObjectDictionary = new Dictionary<int, List<GameObject>>();
In those cases I prefer var
@chilly stone I would also agree, because it's redundant
and Microsoft is thinking the same
As they introduced a new way of declaring variable
C# 9 if i remember
What's the new way?
Oh that...
Interesting, so in that case there's no need for var
But that doesn't... reduce the amount of code?
If it makes the code harder to read, yeah var is necessary
Point p = new (3, 5);
var p = new Point(3, 5);
Literally the same
Few characters, negligeable. Like a lot of sugar syntax
I like syntax sugar like expression body methods
In the case of an allocation, it makes it clear
But in the case of a return, you won't have the Type
It depends on people, debating about that is not useful, but even in VS/Rider, I don't want to "hover" to get the information
Well in Rider you don't even need to hover, it's there
That's good, but I don't use Rider
You should 👀
It's free for students 👀
😄
Ahh, that explains why you don't like var
I was like Rider tells you exactly what the type is
whats the problem officer
Ahh, assembly.load not loading from app domain. That worked, nvm @waxen sandal thanks ;p
@whole steppe just use this https://github.com/cfoulston/Unity-Reorderable-List
sorry for bad screenshot :/
working on a node editor for dialogue but a lot of things end up really hard to do because of unity GUI not being built for this kinda stuff
any suggestions?
ping if u respond
Yeah, they have an API that is made for that kind of stuff though @elder marsh
https://www.youtube.com/watch?v=7KHGH0fPL84
There's also https://github.com/Siccity/xNode if you hate unity api's for whatever reason
Everytime I apply my Prefab, I still see stuff in the overrides, what's the issue here? It's happened in the previous versions I tried too for a while
ah nvm, it's probably because of something weird with an asset I have, but it hasn't affected me negatively, I'll just ignore it
I am trying to make an EditorWindow that replaces selected GameObjects with prefab instances. It mostly works, but though the object I supply it as "prefab" is indeed a prefab, the objects that are created are not blue. How do I make it keep these prefab relationships? https://hatebin.com/eviupkpoqm
Thanks! Will try it
so i am using Cinemachine for my third person camera . I was wondering if there was a way to make the camera only move when i hold the right click button ?
Hi, i'm using animationCurve, how do i make the line thicker ?
it's hard to see
or just color the area under the curve
Hey guys, I want to use the new build settings asset to run multiple builds for different platforms of my game. Problem is I need to change a scripting define symbol for every platform and add a specific prefab to the Initialization scene. Also I cant find a reference for how to use the build settings asset from a editor script. Anyone done this before ?
Looking for a way to make a tooltip for EditorGui because i am using Reoderable list and i can not use EditorGuiLayout( where you can use tooltips)
GUIContent?
Almost any GUI can have a tool tip
but i don´t know how to implement it
ok got it working:
item.id = EditorGUI.IntField(new Rect(rect.x, rect.y + 40, rect.width, EditorGUIUtility.singleLineHeight), new GUIContent("ID", "Unique ID"), item.id);
thanks Navi
The first item has so alot of empty space at bottom while other items are normal. how comes?
Been trying to figure this out for a few hours now.
even if i remove all items and list is empty, then if i add some items to the list same behaviour
Code, we need code
what a bug.
i will just use my backup form yesterday. woudl take too long to find out what the issue is
because even if i replace the whole code from this script with my backup script the bug is still there but when i open the backup everything is normal
Code, I ask for code
Maybe he doesn't wanna share his sacred code, because it'll blow your mind if you look at it... He's doing you a favor 
nothing special, but as mentioned it seems like something else is causing this weird behaviour
Remove line 44
You used GUILayout in a fixed GUI code, that is the first mistake
Then the HeightPerElement, hum... Might not be reliable
Tell me if it changes /fixes the result
still same
something else is causing this.never mind i will just use my backup.thanks guys.
i was just really curious what could be causing this.
@shrewd remnant no You just make a new one and name it w/e you want
you didn't understood i have an asmdef in it i want to define Assembly-CSharp dll as reference
Oh, no
Assembly-csharp automatically references your asmdef, so you would have a circular reference
but looks like its not as when i try to refence a namespace with says its not possible
is the OnInspectorGui a good place for this:
serializedObject.ApplyModifiedProperties();
There is no good place for this
As long as you modify a SerializedObject, this can be invoked
(It is not related to UI/GUI if you prefer)
because i have a UnityEvent field called OnInteract
SerializedProperty itemProperty = serializedObject.FindProperty("items").GetArrayElementAtIndex(index);
SerializedProperty unityEventProperty = itemProperty.FindPropertyRelative("OnInteract");
EditorGUI.PropertyField(new Rect(rect.x, rect.y + 60, rect.width, EditorGUIUtility.singleLineHeight), unityEventProperty);
What am I suppose to do with this information? 🥷
IIRC Unity checks whether something was modified so it shouldn't really matter
It's still good practice to wrap it in a changecheck though
Nah
I've got a quick question about extensions and add ons in general. If I'm working in a small team and purchase an asset from the asset store, will that be available to everyone working in my team? (For example, peak from the unity humble bundle)
well if you check the license in the asset store it says "Extension Asset
One license required for each individual user."
Thanks for the info
So Im experiencing a bit of a conundrum here. I'm writing a little build system to handle my builds for different platforms and I need to change the scripting define symbols for each platform, but that triggers a recompile and then the build cant run and I cant for the life of me find a way to wait for the compilation to finish from the same script since it gets reloaded. Any ideas anyone ?
Write a file
After recompilation, check if the file exists
If yes, continue your operation
Or use SessionState instead of file
well I did go that way but instead of a file I used EditorPrefs but that seems like a bad hacky way lol
i was asking this in general-code but it may be more on topic here
i am trying to write a script to automatically generate spritesheet data
but nothing i do with textureimporter actually saves
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
https://pastebin.com/UkVh1KgG this also doesn't work
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
ok i got it to save the changes but it resets any pivot points i give it to 0.5, 0.5
omg i wasn't setting the alignment
sigh
how do you get the serialised property value within an editor script
so there's serializedProperty.vector2Value, serializedProperty.stringValue, serializedProperty.gameObjectRefrence, etc. but what about custom objects
You cannot get the whole object using serialized properties, though you can display it with a PropertyField
like this, how do i access a and b within an editor script
if you have a SerializedProperty of your Container instance then you can FindPropertyRelative("a")
ah, thanks
@visual stag fyi you can get the whole object from SerializedProperty using some reflection trickery 😉
I know
XD
Here's my terrible bullshit way of getting it https://github.com/vertxxyz/Vertx.Utilities/blob/eb244b2d4ed6241de36e8b7f409814b076868c02/Editor/EditorUtilsProperties.cs#L145
Not super relevant though
While Krendel's implementation is easier to read.
I find it funny that you implemented Property lookup in there, and also that you keep searching if the path has a null
All of my utility functions are shite refined when I needed it, I think half of them are copy pasted from various utility things I wrote years ago. Maybe I'll clean them up... Too many other things to do first
It's also very easy to write things that work just for you, and then later on you realise it doesn't handle some BS generics scenario or whatever
Then make a test to check whether you can get every single property successfully in an entire project... Really just tainting that original thing you wrote that may have been nice and condensed :D
I have some runtime code with tests I want to run only when in editor. These editor tests I'd like to have optionally run based on a setting stored in preferences (settings provider). The issue is the setting lies within an editor asmdef and the runtime within the runtime asmdef. Obviously I don't want to add the editor asmdef as a reference to the runtime one. Is there a common pattern for dealing with editor-only runtime tests? Ideas I've come up with so far:-
- I could have an editor script that sets a runtime static e.g. after compile/domain reload but that feels gross.
- I could maybe ifdef Unity_Editor and do an EditorPrefs check with a duplicate of the settings bool.
- I could potentially pull the settings out into a third shared asmdef. Seems a bit of a shame with the majority of other settings being editor-only.
Any thoughts / approaches I haven't considered?
Things are gonna get real when properties will be able to receive SerializedField attribute
The issue is the setting lies within an editor asmdef and the runtime within the runtime asmdef.
@split bridge I'm kinda confused here, what runtime?
playing in editor
in my case it's not unit testing
For warning a user what they're doing is non-deterministic
Ok a little convoluted. I went with the 3rd asmdef route for now. This asmdef requires AssetDatabase so doesn't want to be included outside of editor or bring any editor namespace into build/runtime. Looks like I can walk the line by setting a define constraint of UNITY_EDITOR for the shared asmdef yet supporting all platforms and wrapping runtime calls in #if UNITY_EDITOR. Just in case anyone needs to do something similar.
Hi guys,
I believe this is a pretty common problem, but google has failed me.
I have a custom PropertyDrawer using EditorGUI.Popup to show an array of strings.
It works as intended until I select multiple GameObjects in the hierarchy.
How can I get the correct behaviour for editing multiple objects?
Code here:
https://hatebin.com/lcdzgmypql
It always overriding is probably an issue in your code since it shouldn't unless you change it
possibly, my code to change the dropdowns is only the following:
private void OnValidate()
{
if (pageManager)
targetPage.strings = pageManager.GetPageNames();
else
{
targetPage.strings = new string[] { "No Page Manager Found" };
targetPage.selectedIndex = 0;
}
}
If I understand correctly, Onvalidate shouldnt even be called (I can check this) and even if it is, each OnValidate only has reference to its own StringListDropdown class.
Shows your propertydrawer
Shows your propertydrawer
@waxen sandal Sorry I don't follow?
I have a custom PropertyDrawer
Show the code
The code for the property drawer is in the link: https://hatebin.com/lcdzgmypql
property.FindPropertyRelative("selectedIndex").intValue = EditorGUI.Popup(position, property.FindPropertyRelative("selectedIndex").intValue, possibleNames.ToArray()); is the issue
Only set the value if it's changed
You can do a changecheck
And you might be able to use this https://docs.unity3d.com/ScriptReference/EditorGUI-showMixedValue.html
To show the multi select value
Not sure if popup supports that though
ok I'll have a read.. just jumping in trying the following:
EditorGUI.BeginChangeCheck();
// Display list of dropdown options
int newSelection = EditorGUI.Popup(position, property.FindPropertyRelative("selectedIndex").intValue, possibleNames.ToArray());
if(EditorGUI.EndChangeCheck())
property.FindPropertyRelative("selectedIndex").intValue = newSelection;
^ It works!
Thank you so much!
Really appreciate it
That feel when people don't cache things like FindPropertyRelative 👺
I do now, I was just getting it working first 😉
Though do you cache it inside or outside of OnGUI?
Mine is currently inside
To check if you do good code.
Run the profiler in deep profile.
Inside, or OnEnable/Awake or equivalent when you can
GUI stuff can only be initialize in an OnGUI() context
Cheers, I'll try that now
Actually, tomorrow now is more likely.. I'm out of time
@onyx harness What's the equivalent OnEnable/Awake for a PropertyDrawer? I looked at the docs and tried CreatePropertyGUI but no luck.
It is GetPropertyHeight if you use it
I've used it elsewhere, I'll try it now..
Ok, I'll cache in OnGui 🙂
could I be cheeky and ask another question..
In GetPropertyHeight, I've overridden it for another propertydrawer..
If I have an array of these PropertyDrawers however, they all have the same height as the last one in the array
I dont see the question
yeah I was just trying to phrase it when I noticed it's more complex than that.. let me get a video...
It's hard to see... but the line "Possible Values: ...." is under the "On Value" property.
The height of the PropertyDrawer in the first element in the array is affected by others in the array.
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return base.GetPropertyHeight(property, label) + extraHeight; // Add # pixels height to this property drawer
}```
I have an array of these PropertyDrawers however, they all have the same height as the last one in the array
@frozen cove I want each one to have its own individual height. (Not all InputValues have "Possible Values:..."
how is calculated extraWeight?
Outside OnGui:
private int extraHeight;
private const int EXTRA_HEIGHT_EXAMPLE_LINE = 18;
...
So is it 0?
to begin with extra height is 0, when I want to add an extra line I call:
extraHeight += EXTRA_HEIGHT_EXAMPLE_LINE;
... from inside OnGui: Based on the selection of dropdowns
This is an issue.
GetPropertyHeight is called before OnGUI
That's why I mentionned GetPropertyHeight if you use it, or OnGUI
Ok.. but it does it correctly increase the height of a single property drawer...
I'm sure there must be an illusion somewhere
You shouldn't use ongui to calculate your property height
It'll turn into a buggy mess
What you see here is the correct behaviour
oooh my code size will explode
You are doing something wrong then
GetPropertyHeight will calculate the height
You are not sppose to do it twice
Because the height will be provided into the Rect position
Also use EditorGUIUtility.singleLineHeight
Ok I'll see what I can do.. but it does look like GetPropertyHeight is called more than just once, perhaps after OnValidate?
So will this really prevent other PropertyDrawers of the same type affecting the height of others?
Look at it like you are late when drawing
Element A will draw with original height.
Element B with A's height.
Element C with B's height.
ahh I see! Yes that's definitely what's happening
I'll have to look at implementing the fix tomorrow, I have to run now.
Many thanks to you both.
Allo all. I'm trying to draw a procgen mesh (so NOT an asset) in an inspector so I try to render it in a Rendertexture with graphics drawmeshnow after setting up material and matrices but it doesn work...
It seems everything is the clear color
Where is it failing?
here is the code, and its just white in the end
oh damn i though this could be folded
When posting code, either use an external site, or at least, remove the indentations
And don't forget to append "cs"
ok taking care of it.
Otherwise pretty hard to read on a mobile
whats the goto for code sharing these days ?
ok here it is https://pastebin.com/1LENhzq8
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
My question is more about, where it fails, is it the rendering into the texture, the generation, the drawing of the texture?
im guessing the rendering because the texture show, in white, the clear color of the render texture
im using the main cam matrices so i can move around in case my mesh is misaligned
yes
and drawing it
im wondering if its because it's happning in a oninspectorgui and the render states are all weird
i cant check in renderdoc either because I don't think we can look into things that are not a scene or gameview
it probably was bad matrices because sundenl now it works
yeah I moved my camera a nd found it. I think the camera might have been inside it ? I don't know
On a custom PropertyDrawer:
Can anyone help explain what this error means, and why the same call to fieldInfo.GetValue() errors in one script but not the other?
Full code: https://hatebin.com/rgntgrluyj (Included working and non-working code)
Error: ArgumentException: Field IC defined on type Test_InspectorComparator is not a field on the target object which is of type UnityEditor.SerializedObject.
The argument provided o GetValue is of type SerializedObject.
While you are willing to work on a Test_InspectorComparator
So it is.. I'm wondering if that's a copy paste error to hatebin..
no, that's my error everywhere..
should open my eyes..
Cheers @onyx harness
when the simplest most obvious things waste the most time 😦
It happens
Now my property drawer is nested and inside an array, inside a class, the 'fixed' line is erroring again:
InspectorComparator IC = fieldInfo.GetValue(property.serializedObject.targetObject) as InspectorComparator;```
I essentially have the following:
http://codebin.herokuapp.com?s=5f73b5cc08fe0e0004000002
I guess I need a different method of getting the target script in line 21 now?
There is no best to debug than to print a debug
In your case, you are still confused by the Object
targetObject is the base object. Could be your Component, your GameObject, your Transform, any Object
Here we have a MonoBehaviour.
You need to extract inputValues first, then only you will be able to access onValue
@frozen cove
Ok I understand, so I can do the following:
ComparatorData[] inputValues = fieldInfo.GetValue(property.serializedObject.targetObject) as ComparatorData[];
inputValues[i].onValue ...
However is there a solution which works in both scenarios, a nested and none-nested PropertyDrawer?
Nope you got it wrong
inputValues is ComparatorData.
Not ComparatorData[]
Yes, using the propertyPath from property
ahh you are right, I have since modified my code.. one moment
Look up this channel
Krendel and vertx provided 2 solutions to fetch an object based on a SerializedProperty path
just this morning
thanks,I'll take a look now.
The updated code http://codebin.herokuapp.com/?s=5f73b83008fe0e0004000003
The array above is now correct.
Thanks @onyx harness I have it working utilising @chilly stones EditorExtensions.GetTargetObject which I mostly understand.
Krendel are you happy for me to use this?:
https://github.com/Krendeled/Untitled-Ball-Game/blob/master/Assets/_Project/Scripts/Editor/EditorExtensions.cs
The project is for an internal tool and wont be part of a published application on any store.
GetTargetObject code itself is copied from someone I can't remember, feel free to use it :)
Thanks 🙂 appreciate it.
does anybody know how to default fields to being "unfolded" that start as folded? Like, I have a 3x2 array that I want to not have to click to unfold
Hi there ! I have no idea in what channel to ask this but have you ever encountered a bug between Visual Studio and Unity where they don't sinc eventhough I've set Visual to be my default code editor and I have the right plug ins from visual's side of things and the right assemblies
When do people will put on glasses and read channel descriptions...
yes that's exactly why I started with "I have no idea in what channel to ask" if you could at least redirect me to the right channel ? I did not put it in any random channel, I just genuinely have no idea in what channel this belongs...
@split gulch #💻┃code-beginner
thanks a lot 🙌
Trying to use EditorGUILayout.Popup(), and the Popup value never "sticks" when I alter it, and the return value is always the same as initially. https://hatebin.com/rknwudovyh
Possibly related: this is not inside an Editor extension, but a runtime MonoB's OnGui().
Hum... should not be related
is it possible to create a reorderable list within a reorderabel list? Right here:
i have a List<MyCustomClass> and i want the user to be able to add as many items as he wants
a smaller, pared down failure case: https://hatebin.com/mbuusrmtsd
@kind vector I just think Popup can not be used for runtime
how weird. I can't understand why these two realms are split, anyway. At least, not in this case. It there a simple alternative that I can use (other than an array of buttons)?
Popup implies the use of a real menu (the popup)
yes
Use a button
When you click, you increment, if you pass, you go back to 0
so needlessly restrictive. The whole thing appears to work, except for the part of not working at all 😉
if it works, it works
Popup just like all other controls returns the new value
And doesn't adjust the parameter you pass into
Why do you say that? O_o
Look at his code
And what should I see?
Test index is never changed because he's not using the popup return value
how do i make a menu please help
This code was a test
Maybe you can help me, i was just really curious how to add a target to a UnityEvent Component, been looking everywhere but i can not find any related topics on the internet. There is unfortunately not the "SetPersistantTarget" like the GetPersistantTarget.
He does indeed change the index correctly
Look at the code previously mentionned
(Not his latest hatebin, the one above)
i just wanted to save the user some time and make it more user friendly, so that the target (GameObjetc) is inserted automaticly
Anyway, the problem in his latest code is that, nothing will ever be printed
Right that's different, I assumed that the last one was a stripped down repro case
@whole steppe There is some API to register/unregister callbacks
Could you redirect me to somewhere.
UnityEvent.AddListener
Well i looked into the AddPersistantListener and stuff
SerializedProperty unityEventProperty = itemProperty.FindPropertyRelative("OnInteract");
this is the UnityEvent field.
You should look into the structure of the Unity Event Class
i did, but there is nothing like SetPersistantTarget
I wonder if unity is considering on buying odin inspector. That would make the default editor much better.
You wish 
Hey all 🙂 I have a class with an array of classes, and each of the children classes has a GameObject field. How would I go about showing this within a custom inspector?
I usually use serialised properties for gameobjects, but that wont work here
Why is that?
Because its a list, and the items change. Hard to prepopulate a serialised property if it doesnt exist.
I think ive found a way using ObjectField though
is it possible to create a reorderable list within a reorderable list?
if i could do that then my project would be pretty much finished.
Anyone know how to center the buttons to the objectfields? Code is as follows:
EditorGUILayout.BeginVertical();
Item i = cc.inventory[counter];
if (i != null)
{
i.icon = (Sprite)EditorGUILayout.ObjectField(i.icon, typeof(Sprite), false, GUILayout.Width(128), GUILayout.Height(128));
} else
{
cc.inventory[counter] = (Item)EditorGUILayout.ObjectField(cc.inventory[counter], typeof(Item), false, GUILayout.Width(128),
GUILayout.Height(128));
}
if (GUILayout.Button("X", GUILayout.Width(100)))
{
cc.inventory.RemoveAt(counter);
break;
}
EditorGUILayout.EndVertical();
why is the 2. reorderable list not being drawn inside of the tab3 but outside
it is being drawn outside of the reorderable list 1
so i am probably trying something that no one before tried to do. reorderable list inside another one. not sure if it is possible tho.
You used Layout I guess
line 87 Mikilo ?
wow it works, you are right man!
DoList(rect); did the job. Thank you so much!
Anyone can help me with Odin to understand a few things?
@sand lava Nobody? 😦
There's probably an odin discord that can help you better
I already was there and ask but got simply ignored 😅
Does anyone know if there's a hook to run code when specifically "Save Project" is called? (Not AssetPostprocessor or AssetModificationProcessor)
I'm trying to write a script that removes empty folders on "Save Project", but not immediately after creating them, nor while playing around with the Project inspector.
there's one when you save a scene but i don't think there's one for the whole project
I want my asset (on the store) to use Unity.Entities Only if it's installed. To do this, I believe I need to have an entry in the asmdef with a conditional compile flag. The issue is, the presence of this entry in the asmdef seems to cause Unity to download the package as a dependency. Is there anything I can do about this other than somehow offering two completely separate packages?
@split bridge I suppose you could have an editor script that checks if Unity.Entities is installed and if so, it somehow enables something else
Maybe by unpacking a unitypackage
Hmmmm
It's also possible to ask Unity to ignore folders by adding ~ to their name
Either in front or at the end, can't remember
But I don't know if that would work inside Unity packages
Maybe it wouldn't import it then
Appreciate the thoughts. Perhaps I could add the asmdef entry after installation 🤔
I want to make second checkox in first line invisible
How can I update its visibility based on the first checkbox's bool
@sand lava I did the same thing. Can’t believe they have thousand of members? In the end we just didn’t buy their plugin. Odin looks good we know but their discord sucks really bad.
Well today they appoligized for not answering and helped me now with every little thing I need today
Good for you. I hope unity made their editor api much easier like in odin soon. For now, we’ll just stay on what’s in unity. Good luck
@prime mulch Don't raise your hopes too much 🦧
Hi - how can I style foldout to look like a bar/box instead of it being simple icon + label...? I think I've done such thing once but can't remember how...
Foldout is just a texture + some text that changes the state of SerializedProperty.IsExpanded
Can easily add something around that if you want
By just changing the position of where it's drawn
Or just making your own
public float Completeness {
get => completeness;
set {
completeness = value % 1;
UpdateDoor();
}
}
Is it possible to show the non-encapsulated "Completeness" get/set in the editor?
nvm i can do something like
private void Update() {
if (Application.isEditor) { // because I can't set "Completeness" in editor, only "completeness".
UpdateDoor();
}
}
It's like asking "can I show methods in the editor?"
No, you logically can't, and why would you? Properties are just get/set methods. Underlying value is what needs to be shown
@empty island OnValidate might be a better fit here. It's called when values in the inspector are changed.
OnValidate might work (didn't know about this method), I'll keep that in mind 🙂
Hi guys. I got my custom editor working before, values are saved etc. I'm using the new UIElements and nested subasset SO
A subasset has List<OtherSOClassThat'sAlsoSubAsset>, but for some reason now i have 3 problems:
- The values of the OtherSOClass are just not saved after editor reopen
- The references of the List also become empty
- Sometimes, OtherSOClass appears blank in inspector, even in Debug mode
All my previous instances of the SO structure still have the values and references saved no problem
Only the new ones now, so i definitely changed something but really dont know where to start now...
Ok i feel like an expert back then when i managed to make all these stuff fully working, then come back in a few months asking again some basic questions..
numField.RegisterValueChangedCallback((t) =>
{
num = t.newValue;
});
This is enough to save the data, right? I dont need any more ApplyModifiedProperties() or AssetDatabase.SaveAssets() or AssetDatabase.Refresh()
Well, clearly i didn't have to back then and it worked, so is there any reason why
Basically i'm just trying to change some value in a FloatField, close editor, reopen and found the value is back to before it was changed
When doing this, ctrl+S doesn't seem to save anything (but i think back when it worked, it also didn't save anything..)
I recently added Json .Net for Unity, even though it's for completely different purpose. Could this (unintentionally) be affecting all these custom editor stuff too?
Num is public field of OtherSOClass
The context is kinda complicated.. i can post a pastebin but it's really long..
Involves nested ListView, polymorphic SO etc
Hello there, do any of you suggest UIElements over IMGUI for Editor at current state? I was experimenting with IMGUI and learned about UIElements, tried them out as I have a strong web background. Information about it is scarce and I couldn't manage to make it work. So, does it worth the hassle, should I tackle it?
UI Toolkit is definitely the future, is it bullet proof? Not yet.
I guess i have to tackle each of these from the start..
I have a button that does this
damageOut.Add(new NumberFormula());
//
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
damageList.Refresh();```
damageOut is a List<NumberFormula> in a SO
damageList is a ListView
This works, but when restarting editor, none of the adding changes are saved. What's the proper way to persist?
And if this is enough and should work, what could be making it not to work?
Selection active Object?
no
i need to get current path
i dont select anything
Selection active Object?
@waxen sandal oh yeah it works
how i can call begin rename file action?
@waxen sandal or its imposible?
There's an api somewhere I just forgot where
and one more. How i can disable field changes?
i want to show them in inspector for debug but dont want to allow change value
There's an api somewhere I just forgot where
@waxen sandal If you don't remember, tell me where to look for it?
Gui.enabled to disable controls
i need smth like attribute
unity registry = all
ayo is it weird i use atom as my code/text editor?
Can anyone help me out with this? Pls guys
So my prob is I have a FloatField in an editorwindow (using UIElements btw) which is bound to a serializedProperty of a float in the same editor window so that unity automatically handles the undo/redo.
After changing the floatfields values a few times and the undo stack is updated with the change cuz its bound to a serializedProperty, now if I close the editor window the undo operation for changing the floatfields are still present and if I hit the undo Ctrl Z now there r empty undos in the place of the floatfield values being undoed cuz the editor window is closed.
What I need is to be able to undo the floatfield when the editor window is open but when I close the window I want to delete the undo commands in the undo stack for the times I changed the floatfield
Pls I really need some help in this. Editor scripting is killing me
@real ivy u need to use the other commands u mentioned
@real ivy r u could bind the field to a variable and then u wouldn't need to
Ok, so fixed my issue by simply doing SetDirty. Setting the object's field directly works (like how it has been for me), not sure why i need the SetDirty now and not then
@stray hemlock No, i only use RegisterChangedCallback and directly set newValue to the field
Keep in mind tho my setup is already pretty far and tbh i cant remember the whole "workarounds" i did so far with this thing, so.... "setting fields directly instead of from SerializedProperty" may not apply for everyone
hello!
how would I make an editor slider without a label at the left side and without a property feild in the right side?
Any idea why my Anchors Presets get restart after save project?
Before save
After Save
hi i found an amazing autosave extension i love
And you expect us to download and import this package like that? X)
I've been talking through a gradient mapper editor extension in #archived-shaders. What changes would I need to add to my script to change the Gradient Property Name field to a dropdown menu that lists all Gradient References I have in my shader graph blackboard?
PropertyAttribute & PropertyDrawer
currently I have these parameters declared at the beginning of my script
[Header("Gradient map parameters")]
public Vector2Int gradientMapDimensions = new Vector2Int(128, 32);
public Gradient gradient;
public string gradientPropertyName = "_GradientMap";```
where would I add in PropertyAttribute and PropertyDrawer
Attribute must be on gradientPropertyName
Because you want to modify how it is drawn
And then you will have to implement a PropertyDrawer to make your own GUI for it
hmmm
Are shader references a serializable class I can put in a CustomPropertyDrawer?
I'm reading in the documentation that CustomPropertyDrawer expects me to pass in the type of serializable class it's a drawer for.
never mind!
I now see the whole other section of documentation on Property Attributes 
would shader references be a string class?
If you know how to convert from String to Shader ref & Shader ref to String, yes.
Right now I'm looking at this documentation and this tutorial
https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Property-Types.html
https://youtu.be/a4hQ76HvjKs
Game Programmer Course - STARTS MONDAY: https://bit.ly/3i7lLtH
Learn how to customize properties in the inspector with simple PropertyDrawer scripts. I'll cover a simple integer propertydrawer first, then move onto a more complex example with a dropdown menu to togg...
Where are you blocking?
I'm sorry - I don't know what you mean. I'm a novice when it comes to editor extensions and tools
you are not blocked yet then
I'm just not sure how to pass in the property references from a shader graph into the typeof() for the CustomPropertyDrawer
Should I be looking at this documentation?
https://docs.unity3d.com/ScriptReference/Shader.html
it looks like I should be using PropertyName?
https://docs.unity3d.com/ScriptReference/Shader.FindPropertyIndex.html
How would you normally extract those property references?
How do you get them
PropertyDrawers are to draw custom UI. From there you can do whatever you want, like a dropdown of your Shader refs
Yeah I would like to have a dropdown of my shader refs that include "Gradient" in their name
I knew that - I was asking for help with syntax since this is all new to me.
I've been looking at some tutorials and all the example property drawers they create are very complex. Meanwhile I am trying to just return all Shader PropertyNames including "Gradient" in their name
Based on the structure of Property Drawer this doesn't seem like it should be complex yet every video I find about Property Drawers is overly complex with explicitly defining too many values for their inspector

I would have help you more if only you answered all my previous questions
Especially this one
How would you normally extract those property references?
Can anyone help me out with this? Pls guys
So my prob is I have a FloatField in an editorwindow (using UIElements btw) which is bound to a serializedProperty of a float in the same editor window so that unity automatically handles the undo/redo.
After changing the floatfields values a few times and the undo stack is updated with the change cuz its bound to a serializedProperty, now if I close the editor window the undo operation for changing the floatfields are still present and if I hit the undo Ctrl Z now there r empty undos in the place of the floatfield values being undoed cuz the editor window is closed.
What I need is to be able to undo the floatfield when the editor window is open but when I close the window I want to delete the undo commands in the undo stack for the times I changed the floatfield
Pls I really need some help in this. Editor scripting is killing me
Editor Window Code: https://pastebin.com/w73tHZkH
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I tried that but
The description says that u have to have used Undo.RegisterCompleteObjectUndo first
But since Unity is Handling the Undo functionality cuz the float field is binded i dont know if thats called
And Undo.ClearUndo(this) didnt seem to work in OnDisable()
@brisk nova
@brisk nova
yeah, i dont wanna do dat
I think i could work around this issue if i knew something else
Can you help me out with this?
VisualElement Fields call RegisterOnValueChangedCallback when the user is sliding through the values right?
Is there an event or is there a way to know when the user actually stops sliding through the value so i can set an Undo point there?
What i mean by sliding is when you change value of an object by clicking and dragging its name
VisualElements fields call RegisterOnValueChangedCallback for each small change when ur sliding through them
@brisk nova Thanks anyways for trying
Really appreciate it
Can u point to a place where i can get answers quick for UIElements probs??
Attempted to update project that is not loaded: /Users/user/Desktop/game/game-proj/Assembly-CSharp.csproj```
Can't get auto complete in vs code
.NET framework installed
vs code unity extensions installed
checked in unity > editor > visual studio code
Hey is there a way to set up a menu only if the selected Build Platform is WebGL ? #if UNITY_WEBGL doesnt seem to work
@minor salmon wrapping your menu item in that should work
@minor salmon wrapping your menu item in that should work
@waxen sandal Hmm. i even tried adding UNITY_EDITOR but still i dont get a menu item. Any chance you can spot the culprit here?
Your methods need to be static
Your methods need to be static
@waxen sandal Thanks Navi! 🙂
hi, how do i change the disabled guistyle ?
for example, my animation curve is faded when i disabled it
i wanted it to be disabled, but not faded
any ideas ?
is anyone familiar with reorderable lists because i have a complicated issue
been trying to fix this for a few days now but i am doing somethign wrong here.
I have logic created in an Editor class which creates an Integer in EditorPrefs. I want to use that integer when building my application, how can i achieve that? I cannot use (Platform)EditorPrefs.GetInt("SelectedPlatform") because editor is not supported when building the application.
The only thing i can think of is writing to a file which seems overkill.
You got it.
Are there events for object added, object modified or object deleted in the editor?
Any other clean way to detect changes to specific objects in the scene? I really don't want to add a custom script to every object to detect these changes myself or loop through all of the scene objects and check for changes :/
I guess I have already answered that question
@cloud wigeon i literally have been learning c# and unity for 3 days, but i think that could be a use case for c# attributes?
Lean toward this direction and you will suffer in humongous pain 🙂
There are a zillion things you won't see coming even before finishing your implementation
haha, ive been programming for a bit, so im used to banging my head against wall until 3am 🙂
once you label your objects, you could have some code that gets objects by that attribute and then do what you need.
you still have to label every object you want to track, but maybe a clean implementation.
Which basically means marking every single fields of your project 🙂
it's declarative and easier than adding a script to every object i think
Is it possible to do a distance based LOD group?
Or manually setting the bound for LOD Group?
I created an editor menu which sets an integer value on a scriptable object instance. This part works i can see the changes on the SO. In another non-editor class i load that instance to the SO and just grab the value to set it on a static field (without any references to the editor class anywhere) . After building and trying to run i get this (see image). Can someone help ?
@minor salmon the most likely cause is you have some property that is only serialized in editor. For example if your scriptable object had smth like #if UNITY_EDITOR public float Bob; #endif
private void OnDrawGizmos( )
{
#if UNITY_EDITOR
UnityEditor.Handles.BeginGUI( );
var click = GUI.Button( rect , text);
...
im having trouble getting the events to work , any ideas ?
I don't think you can use handles in OnDrawGizmos
it works ok , renders and all but the current event is always stuck at repaint
any change i could use UnityEditor.Handles.Button with a flat button skin ?
ah nvm its the same problem , though there is a quicker way for this, gonna do a custom editor instead
I have got a reorderable list which works great. This List is a List of item. Now on every item itself i want to draw another reorderable list. It has to be a List of properties. I have already a field on the item which is a List of properties. I tried a few things but i am drawing the list not individually for each item but it is being drawn for all items, which is not what i want. I have attached a gif too, if you take a look you´ll know what i mean. Thanks.
codeshare or paste of code for the code.
Do i have to use something like:
SerializedProperty itemProperty = serializedObject.FindProperty("items").GetArrayElementAtIndex(index);
Ok, i got it working somehow.
But i have to make a few changes, i can not mark the individual list elements. i can only add them rn
You are using the same reorderable when drawing
MenuItem: can I call some dialog box to input some parameters?
Sure, open an editor window
and?
wait, I will explain. I have MenuItem that calls function BUT it needs parameters
Menu items don't have parameters
Sure I cn create special component that will store all data I need and then get ti's data while execution, but It is not very comfy
I know that menu items don't
Or open an editor window from the menu item, and handle it there
sorry, I din't get. Open editor window - what do you mean?
What part do I need to explain?
What it will give me?
[MenuItem] this
I'm adding additional components for object (context menu of another component). these components should have values in them to be set. To pass these values I need some mechanism.
Perhaps you want to use presets then
googling...
nah, every time they are different
but, hm
I till have limited objects/abstract object at the scene, so should I make presets for every 'limited' type?
But at least I have to tell MenuItem what preset to choose
Is there MultiPreset?
I have about 20 components to fill with values
Doubt it, but I imagine it wouldn't be too hard to combine multiple with a scriptable object
any ideas why I'm only getting the first property shown in the editor for this property drawer? https://hatebin.com/tjeawmcevf
Only the "source" property is shown, if I swap them over, then only "tangentType" is shown
have you overridden the property height so it's the right size for two fields?
i'm not sure what you mean
how to make several fields displayed in one row in Inspector?
Right now every field occupies full row
i want 2 rows, not a single row
do i need to do another BeginProperty block for the 2nd?
i have 2 variables that i want to show on different rows, are you sure I need to override that?
@visual stag now I found EditorWindow
overrideing GetPropertyHeight, just seems to make the 1st field extra tall now, still on one line
that is because you are using position.height
You should use EditorGUIUtils.singleLineHeight
Which is like 16 or something
as your second field is at position.y + 165
that could also be very far away
The label isn't being displayed correctly, it just reads the variable name with no tooltip, instead of what I've set in the GUIContent labels? https://hatebin.com/qlfwmsbjqo
ie, inspector reads "Tangent Type" instead of "Tangent" and has no tooltip; "Interpolation tangent type"
Anyone know of a editor tool that makes it easy to visually align sprite pivot points? I have lots of frames, and it would be easier to have them overlaid with onion skinning or something like that.
Anyone know how I can invoke a reflected method in an editor window?
Just like any other way?
Im getting a random crash (without logs) with UI Elements generated from the following code:
public static void DrawPropertiesExcluding(this SerializedObject serializedObject, VisualElement container, List<string> exclude)
{
SerializedProperty iterator = serializedObject.GetIterator().Copy();
bool enterChildren = true;
while (iterator.NextVisible(enterChildren))
{
enterChildren = false;
if (!exclude .Contains(iterator.name) && !exclude.Contains(iterator.propertyPath))
{
container .Add(new PropertyField(iterator.Copy()));
exclude .Add(iterator.propertyPath);
}
}
}
yeah the function completes and outputs visual elements.
But once i feed my root via CreateInspectorGUI unity just crashes silently, no crash log.
I narrowed it down to this by commenting it out, and voila - no crash.
no idea how im gonna fix this.
could someone give the above code a test to find out if their unity also fails silently
it also crashes unity within a simplified inspector:
public sealed override VisualElement CreateInspectorGUI()
{
//DetectProperties();
root = new VisualElement();
serializedObject.DrawPropertiesExcluding(root, new List<string>());
return root;
}
my issues are always the non-debuggable-unsolvable ones.
Have you tried to narrow down the DrawProperties? @whole steppe
By just adding one by one the PropertyField
If the first one crashes, and not the 2nd
or only the 3rd, or whatever
You might be able to understand more
my issues are always the non-debuggable-unsolvable ones.
@whole steppe Maybe because you lack of debug skill
@onyx harness - the entire function executes successfully. The crash happens in unity space.
the crash happens after unity has my visual element structure.
try to debug something in unity space - with no crash log, in a space where your C# debugger cannot travel.
My DrawPropertiesExcluding is an exact copy of unity's DrawPropertiesExcluding, but converted to populate as UIElements. It executes in it's entirely, as I said before.
It crashes universally regardless of what properties are fed through it - after the entire UI is generated.
the previous IMGUI version of the same inspector runs flawlessly.
No crash with that.
using NGTools.Tests;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
public static class Extension
{
public static void DrawPropertiesExcluding(this SerializedObject serializedObject, VisualElement container, List<string> exclude)
{
SerializedProperty iterator = serializedObject.GetIterator().Copy();
bool enterChildren = true;
while (iterator.NextVisible(enterChildren))
{
enterChildren = false;
if (!exclude.Contains(iterator.name) && !exclude.Contains(iterator.propertyPath))
{
container.Add(new PropertyField(iterator.Copy()));
exclude.Add(iterator.propertyPath);
}
}
}
}
[CustomEditor(typeof(SimpleLog))]
public class TestEditor : Editor
{
public sealed override VisualElement CreateInspectorGUI()
{
VisualElement root = new VisualElement();
serializedObject.DrawPropertiesExcluding(root, new List<string>());
return root;
}
}
Unity 2020.2b1
- the entire function executes successfully. The crash happens in unity space.
@whole steppe it is not because the crash is in Unity space that you can't prevent it to happen.
If the bug is 100% provoked by your code, you made an impact, you can do something about it.
Perhaps Unity is doing something wrong on its side, but it doesn't mean you did nothing wrong. You made it crash I recall.
try to debug something in unity space - with no crash log, in a space where your C# debugger cannot travel.
@whole steppe Well I narrow down my code until I find the culprit...
My
DrawPropertiesExcludingis an exact copy of unity'sDrawPropertiesExcluding, but converted to populate asUIElements. It executes in it's entirely, as I said before.
@whole steppe The problem is not this code executing til the very end. It is the consequences that you want to address.
UIToolkit != IMGUI, there must be an underlying behaviour that we miss.
If you can reproduce this bug 100% on different versions of Unity, just report it
the bug 100% fails on Generic serialized lists of serialized generic types (which can only be tested on 2020 editions).
the same serialized types are succeeding 100% when rendered within the IMGUI version of the inspector.
Which means PropertyField in UIElements cannot handle serialized types accessed though an interface correctly.
Here you go, make a bug report and you good to go
this is annoying as I hoped to convert all of my inspectors to UIE before this month ends.
If you know exactly what is causing the issue
Just replace PropertyField with an IMGUI container to draw the element
hi i am creating an image using UIElements and adding it to the rootvisualelement
is there a way to set the pivot of the image that i create? because i want to drag it around
and when i click on it it always starts at the top left
i want to set the pivot to the centre but i cant seem to find a way to do so
Alright so, I’m having a problem of the editor not starting up. I am using 2018.4.20f1 (I use Unity for vrchat.) I can get to the hub, Unity will package resolve and the editor will not open. Here’s the list of everything I’ve done:
-4 completely clean uninstalls and reinstalls
-Updated my license
-Tweaked my firewall, even made file exceptions for both the editor and the hub
-Unplugged and unnecessary usb devices (being a gamepad)
-Reinstalled on my new SSD
-Tried unplugging my Ethernet and connecting, restoring connection after
- Restarted my PC multiple times
-Updated my drivers
Here’s some photos I have taken that might be helpful. The version prompt seems to not be what’s keeping me, as from researching people can still start up the editor. A file path is blanked out for my privacy. Just refer that file path as Aki.
^ I have installed the version I needed and applied it and I still get “unavailable” or unknown
I troubleshooted this for 5 hours.
Only hardware change I’ve made since I last used Unity was an SSD but that shouldn’t be affecting it. Last time I opened Unity was roughly a little over a month ago.
Also, image with two prompts hasn’t showed up again since I moved Unity back over to my main drive.
Editor itself just doesn’t open, btw. It doesn’t open entirely.
Hey anyone can tell me what the serializedObject in this tutorial is? https://va.lent.in/unity-make-your-lists-functional-with-reorderablelist/
In Unity 4.5 we got a nice (undocumented) built-in tool to visualize lists in IDE. It's called ReorderableList. Let's see how to code beautiful interfaces in Unity IDE using ReorderableList
The tutor forgot to explain where he got the serializedObject smh...
There are many refs to it
Can you point out the one?
@mild reef serializedObject comes from Editor itself
I have been trying to fix this or a few days now. I can not select any propertylist items. I am able to add them but not able to delete or select them.
i am using a reorderable list within a reorderable list
I thinkit has something to do with
serializedObject.ApplyModifiedProperties();
because i am using FindPropertyRelative("propList");
I think this is because you allocate a ReorderableList every single frame.
where else would i draw the reorderablelist2, because i can not do it in the onEnable since i have to do it when a new item is added to the Items list
let me see if i can transition the code into the OnEnable too
since i have to do it when a new item is added to the Items list
You just said it
So into the AddItem method instead Miki?
Yep
@onyx harness Ok...
But there is major problem, the DrawElement method gives me the index the AddItem doesn´t , how could i fix that? I need to acces the index somehow.
ok that makes sense.
let me see what i can do.
thank you for this very important hint. i knew it was a very bad idea to draw the reorderablelist2 every frame
When you select an item, it is saved in the index of the ReorderableList.
Since you create a new one at every event, index is lost.
How would i draw the list in the case 3, i can´t wrap my head around that problem. i got the whole code in the AddItem method.
Read about API DragAndDrop and ReorderableList events.
hi want to ask, how do we implement EditorUtility.SetDirty?
i made SO file and System.Serialized it, in the Editor i called the object of it and set it with dirty but it didn't work
you should use Undo.RecordObject before the change
and you want to record the parent object that is serializing this change, ie. your ActorData object
(that is the same parameter you would want to use for SetDirty, but SetDirty sucks :P)
so i just like Undo.RecordObject(player[index])?
sadly it didn't work (idk why)
so it should be like this?
not sure i've been doing the right thing
I don't think you can combine Undo and SetDirty
alright so i just let undo alone right
didn't seems to work
should i declare something or do something?
or it's only work on OnInspectorGUI not OnGUI?
Anyone knows when TypeCache was introduced?
The APIVersioner doesn't work for some reason
Cheers
I confirm 2019.2
I tried it right away, saw critical bugs right away, decided to throw it right away
But when it was working, I saw interesting gains in lookup time.
Does anyone know if there is an asset database find format like t:MyType that works with generic base types?
similar to how you can do a GetType("MyType`1")
@visual stag For your information, I think you can get the list of available types at UnityType.ms_types
The AssetDatabase lookup is done in ObjectListArea.RefreshBuildinResourceList with this line:
UnityType unityType = UnityType.FindTypeByNameCaseInsensitive(name);
UnityType is available since Unity 5.5. The message above should be pretty reliable.
I don't know if my types are actually in that list
Seems to be internal types, not ones in scripts
I think it uses TypeCache to do it
From UnityType.Internal_GetAllTypes()
But you are right. In my test in 2018, the list contains Unity types, not user types.
I don't know how it manages to find the right user type
I don't have more type to investigate, if you find anything, feel free to poke me
I think it's all internal
it creates a HierarchyProperty set to HierarchyType.Assets and passes a SearchFilter to it (SetSearchFilter)
hi, any way to save a scriptable object value on quit unity editor ?
i'm using custom editor to edit my scriptable object
and i wanted unity to save the value when i quit unity
Hello. Are there any python plugins for Unity?
why is my scriptable object not saved when i quit unity ?
Undo needs to be called before changes are made
what if i callit on OnGUI ?
i want my scriptableobject "values" to stay intact even when i close unity
If you recorded the changes using Undo properly https://docs.unity3d.com/ScriptReference/Undo.RecordObject.html
Then they will be saved properly
ah, so undo.record, saves the data on the scriptableObject right ?
i call the method on OnGUI, so isnt the data saved everytime OnGUI is called ?
It marks the object as dirty if changes occur after it is called (in that editor frame)
If the object is dirty then Unity will save the data to disk when it closes or when File/Save Project is called
The example shows how to use it properly
okay, thanks a lot
i'm trying it out
yea. still no luck 😦
i'm a newbie here, i just started making custom editor about a month ago
i re-read the docs. it said it records all changes after the record function is called
how do i retrieve the "stack"
i've used setdirty, but i still dont get how it works and how to implement it
anyone else that can help me ?, i'm still stuck for a couple of hours now
How do I get a reference to a scriptable object in a custom editor window without it needing to be selected in the project view? I want to have settings for my window but I can't seem to find a clear answer.
You could use the AssetDatabase to search for an asset of a specific type
Perhaps.. I'll try that.
TIL DrawDefaultInspector(); exists. I spent a lot of time trying to do it myself. I succeeded. I them wanted to move it to a new base editor class I could then use and tried naming the method DrawDefaultInspector();. To my surprise unity said "Lol, dude, dude, we have that already haha. You got punk'd bro"
@short tiger That worked fine. Thanks for the suggestion.
Hello, me again. Long time no spam... I can't find how to create a ScriptableObject from code. I have the menu item and all that, I just want to create a new scriptable object file from a custom editor script.
@south fox ScriptableObject.Create
@minor salmon did u try PlayerPrefs for that.
I just now found this http://www.li0rtal.com/unity-scriptableobject-factory/
You will need to save it though. I believe it is AssetDatabase.CreateAsset
@aki#5910 I'm pretty sure its cuz ur project was first created with a different editor version.
I have two GUI controls that overlap, I can't remember, how do you set which one gets priority?
Both, but event is what I mean.
I am using a EditorGUI.BeginFoldoutHeaderGroup(...), and want a int field on the same line.
The first to execute will receive the event first
That is what I thought, but when I do that it breaks. I want it to look like this
But when I do it before it looks like this. If I hover over it the field appears on the right, where it should but the name is still 2.
Because BeginFoldout is drawing its background color over it
Right, but you see the problem though, if i move it below it will draw right, but not get the events.
Just reduce the width of the BeginFoldout
I could, but then it looks ugly because it highlights on hover.
didnt understand
Basically, I am just trying to recreate the 2020.2 reorderable lists, but for a dictionary.
This is not what I stated
I didnt understand "it highlights on hover"
Who is "it"?
Yeah, I was just trying to add some more context. 🙂 EditorGUI.BeginFoldoutHeaderGroup(...)'s background changes when the mouse hovers over it.
I never understood why people used this version of foldout
Idk, but Unity seems to be using it now for most of their controls in 2020.2, so figured it would be good to for consistency.
if you don't need the hover because you find it ugly, just use Foldout
I do actually kind of like it. But I may if I can't figure out a way around this.
I don't think you can bypass the hovering
I mean, you can
but it's gonna cost you too much headache if you don't master IMGUI
The hover isn't the problem, the problem is that for the foldout, clicking anywhere on it will collapse/expand it. (Apposed to just on the label or the arrow).
Just reduce the width
To be honest, your issues are so not issues, you just don't wanna go simple 🙂
I mean, yeah, I could just shorten it, but then it wouldn't look like Unity's which is the goal. But yeah, I just don't wanna do it the simple way. 😛
It wouldn't look like Unity...
Sorry I just don't understand what you are willing to do
Does Unity have hovering or not?
Yes, well you had it and said it was ugly
If no, I suggested you the simple Foldout, and it becomes not Unity-compliant
Got that in front of me
Yeah, that is exactly what I am trying to do.
If you reduce the width, you feel it is ugly because the background does not go under the IntField
Correct
I don't have time to dig into their code
But I would double draw
You lose the visual focus with this trick
Yeah, all good. Double drawing doesn't seem to work. I will dive in to their code again to see if I can figure out what they are doing. Appreciate the help! 🙂
Because when you do 2nd draw, you have to do it on Repaint event only
Ah, got it.
First draw handle input, 2nd over draw
@onyx harness Found it, this is basically what they did to get it to work.
EventType prevType = Event.current.type;
if (Event.current.type == EventType.MouseUp && sizeRect.Contains(Event.current.mousePosition)) Event.current.type = EventType.Used;
// Foldout header
property.isExpanded = EditorGUI.BeginFoldoutHeaderGroup(headerRect, property.isExpanded, label);
EditorGUI.EndFoldoutHeaderGroup();
if (Event.current.type == EventType.Used && sizeRect.Contains(Event.current.mousePosition)) Event.current.type = prevType;
And then after that they have the field.
Basically I guess they set it as used, and then 'unuse' it.
This is exactly the kind of headache I said earlier 🙂
Lol, it's like 3 lines, pretty clean lines actually.
It's not about the size
It's about how to find this trick
Do you think you could have find it?
This is typically the kind of stuff you have to do when you deal with Z-ordering in IMGUI
Oh, got it, you mean headache like to find/know, not implement.
I was close to it, had the right idea, I didn't know you could set the event tpye to Used, and it would work. I wonder if/what is the difference between setting the type, and calling the method Use()
If you never knew you could set the event type, yep this trick will stay far away from your mind 🙂
Oh, definitely, wasn't trying to say otherwise.
Not sure, but yeah I would say Use just change the type
But good job for digging into the code 🙂
That's the way
For sure.
The more you do that, the less you will spend time in here
I will be of no use then 😄
I had actually done it first, but reached a dead end, I thought they were using ListView, but nope, just a wrapper around ReoderableList.
Literally called ReorderableListWrapper, if it works it works I guess.
Man using UIToolkit is so much nicer than having to deal with this old stuff, lol. Stuff is everywhere, and there a so many small 'hidden' things everywhere.
Oh you will deal with an equivalent amount of shit with UI Toolkit
I can guarantee it
I'm not used to see Unity dropping a miracle in no time
I think there will be less, they have been doing pretty good with it. There will for sure still be some, always, but hopefully, it will all be in the same place though.
Instead of like GUI, EditorGUI, GUIUtility, EditorGUIUtility, etc.
https://twitter.com/_Mikilo_/status/1261383803060142080
You see this one? Mix of IMGUI and UIT, ugly hacks
Revisiting the Inspector (Poke me to join the future open beta of NG Flow Inspector)
#madewithunity #indiedev @AssetStore #unity3d #gamedev #ngtools https://t.co/gB74rQwqqE
UIT is in better shape in 2019 and later
Unfortunately, still have to deal with 2018
Oh yeah, I saw that. No how did you get stuff to draw outside of the window? I mean, I both love and hate it because it breaks the bounds of the window, but it is cool!
It is just another EditorWindow? Did you clamp it there? More importantly, how the heck did you remove the header?
Border and good positionning is the key, you got fooled huh 🧙♂️
You just need to create an EditorWindow borderless, by manually creating it and showing it as a popup (and also setting the min-max sizes)
Very cool! I'm going to finish up my thing, and look in to making a window like that. I have been wanting to see about making a pin/tool bar ala visual studio. But didn't bother because of the border on windows.
Take this
NGSpotlightWindow window = EditorWindow.CreateInstance<NGSpotlightWindow>();
window.position = new Rect(Mathf.Clamp(mousePosition.x - NGSpotlightWindow.WindowWidth * .5F, r.x + 5F, r.xMax - NGSpotlightWindow.WindowWidth - 5F), r.y + r.height * .5F - NGSpotlightWindow.WindowHeight * .5F, NGSpotlightWindow.WindowWidth, NGSpotlightWindow.WindowHeight);
window.minSize = new Vector2(NGSpotlightWindow.WindowWidth, NGSpotlightWindow.WindowHeight);
window.maxSize = window.minSize;
window.ShowPopup();
window.Focus();
Oh, thanks @onyx harness! 😄
Do you happen to know if it works with other window types besides popup?
What do you mean?
you can't have a borderless floating window (docked)
I can't be docked if that what you mean
Ah, that's a shame. Being able to have docked borderless window would be cool.
