#↕️┃editor-extensions
1 messages · Page 13 of 1
If you do [FilePath("MyPackage/MySaveData.dat")], The file should be MY_PROJECT/ProjectSettings/MyPackage/MySaveData.dat
weird, it's not created in my project, really.. see the above screenshot
proly the ProjectSettings one , but ProjectFolder creates it outside my project file
man, unity is on crack
🤣
WAIT WAIT WAIT.. NO
Idk, you can see what it is doing https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/ScriptableSingleton.cs
it creates new folder in my root project folder
so yeah still in project folder.. and relative path.. ahaha me on crack once again
YOU're correct Mr.MechWarrior!
OOh right, sorry about that. I just always put ProjectSettings/ in the file path xD
it's in my root project folder, yeah , due at 1st I thought it was the ussual Asset folder if I picked ProjectFolder
so it created new folder (that I was assuming in my Asset folder) in my root project folder instead
lmao
you're correct
Ahh, nope. Also if you think about, not even AssetDatabase is relative to the assets folder
You always start a path with Assets/
yes, I did not put that Asset/ path due to my false assumption 😅
hhahaha
nice dude, thanks a ton once again 👍
it is solved!
also, true dat 👆
I just wanted to check in and ask if anyone had any insight to this question I asked over the weekend.
[CustomEditor(typeof(ConversionConfig))]
public class ConversionConfigInspector : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.HelpBox("This is helpbox", MessageType.Warning);
}
}
okay, so this draws the warning at the bottom of the inspector. It's totally expected, because I first call base and then do my thing.
the question is - how do I "interfere" with base implementation? I want to draw warning after/before some specific field / header
obvious solution is to just manually draw everything and throw away base.OnInspectorGUI() call completely, but it just feels extraordinary dumb and requires me to rewrite my inspector script each time I add or remove a property
is there a better way?
I couldn't achieve helpboxes with attributes either
would be nice to have a simple attribute [HelpBox("message", messagetype)] which would just simply draw a helpbox, but I don't see a way, since PropertyDrawer doesn't have HelpBox method
wait I'm dumb, it's extremely simple
I just call EditorGUILayout.HelpBox() from the OnGUI 😆
nvm
how can i render Inspector Some Part of code?
such as i want render part "Fire Setting" from code line 8 --> 13
and render part "Recoil Setting" from code line 14 --> XXX
couple of ways, EditorPrefs, as physical assets (.asset), or ScriptableSingleton
EditorPrefs is the easiest here, it's the same workflow as PlayerPrefs
the rest, you can try to google it for more elaborate answers or once you hit a brick wall using them you can post it here
oh that is nice ideas
thanks👍
oh wait.. I misunderstood
I thought it was about saving states 😅
@dull mango you'd have to make a custom inspector for it
It's for UIToolkit, you can use UIBuilder for dragNdrop workflow even for custom editor or pure code
oh sad haha
you can show/hide whatever serialized properties on your custom editor, the same logic as you would in c# but with slight different concept
the linked page should get you going
Guys, I have a question..
I tried to copy GUI.skin.button style without passing it to the constructor, but now it looks like it won't listen to mouse event.. I don't want to use it because looks like we can't get rid of the bg texture of it.. do I have to trigger a repaint manually by checking where the mouse is?
I have this.. I want to imitate a button (imagine all the states are there for now lol)
I don't wanna copy the button style like new GUIStyle(GUI.skin.button)
And I'm using the style like so
EditorGUI.DropdownButton(midRect, s_operatorContent, FocusType.Keyboard, OperatorPopUpStyle)
Why don't you want to copy
also does it work if you copy
Can you show the code surrounding EditorGUI.DropdownButton
It does work but only like in the following picture.. and it looks like a regular button.
If I uncomment the bottom part it doesn't repaint and also doesn't look right..
It looks like that
Basically I want a flat button style lol...
Can you eliminate which part of those custom settings don't work?
Also why are you using a dropdown button and not a normal button?
I tried GUI.Button() too, it behave the same
The normal state does change the base button style but it doesn't make it green or removes the background
When I move the mouse around the button, it won't repaint..
The hover state looks good
Maybe I'll try EditorStyles skins..?
Nope..
It's the normal state, if I remove my override, it works fine
If I change the background of the normal state of GUI.skin.button, I lose all mouse event repaints... for everything that uses it
Except for MouseDown and MouseUp which work.. if I hold the mouse button down on a button with my style, it does repaint on mouse enter\leave
Try setting the background to editorguiutility.whitetexture and using the background color instead to ting it
I tried whiteTexture same behavior but what did you mean "using the background color instead to tint it"?
Oh I thought there was a background color field
I guess there's GUI.BackgroundColor
Alright I tried that.. same behavior 😔
This works basically.. but I am trying to avoid lines 74-75
I guess I'll have to use something like that.. maybe I'll wrap it in my own "editor helper static function"
Thanks @waxen sandal for the help! ❤️
If I understand you correctly, it is the hover state that is not changing, right? If so, fun fact, the built in styles (like button) are treated special by unity internally, so they will repaint and handle mouse hover, but copies and other styles will not. I haven't found any way around this. And the code that does this is in C++ I think, so... yeah...
I recommend looking in to UIToolkit, this sort of thing is much easier with it. 🙂
100% agreed.. customEditor with UIToolkit is like waaayy too easy, no lie 😄
I did suspected that! nice to know now, thanks! I guess I have to implement my own thing now lol
I'm sure UIToolkit is the future! I need to read about it more should I wish to incorporate it in assets..
Hello there, I'm a bit unsure where exactly to search for this: I'm trying to duplicate an animator controller and change some animations inside of a blend tree. Here are some pictures and my current code. Can someone help me get on the right track? Thanks.
private void GenerateAnimatorController(GameMode mode)
{
string newPath = $"Assets/Resources/Animation Controllers/{characterName}_{mode}.controller";
AnimatorController template = (AnimatorController)AssetDatabase.LoadAssetAtPath("Assets/Resources/Animation Controllers/Template.controller", typeof(AnimatorController));
AssetDatabase.CopyAsset("Assets/Resources/Animation Controllers/Template.controller", newPath);
AnimatorController newAnim = (AnimatorController)AssetDatabase.LoadAssetAtPath(newPath, typeof(AnimatorController));
// Idle
newAnim.layers[0].stateMachine.states[0].state.motion = idleUp;
newAnim.layers[0].stateMachine.states[1].state.motion = idleRight;
newAnim.layers[0].stateMachine.states[2].state.motion = idleDown;
newAnim.layers[0].stateMachine.states[3].state.motion = idleLeft;
}
A picture of the base layer, in case that's of any help.
Here's my new code. Am I doing stuff the way it should be done? Or is this code stinky?
private void GenerateAnimatorController(GameMode mode)
{
string newPath = $"Assets/Resources/Animation Controllers/{characterName}_{mode}.controller";
AssetDatabase.CopyAsset("Assets/Resources/Animation Controllers/Template.controller", newPath);
AnimatorController newAnim = (AnimatorController)AssetDatabase.LoadAssetAtPath(newPath, typeof(AnimatorController));
// Idle
BlendTree idle = FindBlendTree(newAnim, "Idle");
RemoveBlendtreeChildren(idle);
idle.AddChild(idleUp);
idle.AddChild(idleRight);
idle.AddChild(idleDown);
idle.AddChild(idleLeft);
// Run
BlendTree run = FindBlendTree(newAnim, "Run");
RemoveBlendtreeChildren(run);
run.AddChild(runUp);
run.AddChild(runRight);
run.AddChild(runDown);
run.AddChild(runLeft);
if (mode == GameMode.HideNSeek) return;
// Attack
BlendTree attack = FindBlendTree(newAnim, "Attack");
RemoveBlendtreeChildren(attack);
attack.AddChild(attackUp);
attack.AddChild(attackRight);
attack.AddChild(attackDown);
attack.AddChild(attackLeft);
}
private BlendTree FindBlendTree(AnimatorController controller, string name)
{
foreach(var layer in controller.layers)
foreach(var state in layer.stateMachine.states)
{
var blendTree = state.state.motion as BlendTree;
if (blendTree != null && blendTree.name == name) return blendTree;
}
return null;
}
private void RemoveBlendtreeChildren(BlendTree tree)
{
for (int i = tree.children.Length; i >= 0; i--)
tree.RemoveChild(i);
}
}
How can i custom gui on right click at properties in inspector?
Check an Event.current for Right Click and create a custom GenericMenu. Probably need to place this in a Property Drawer or Editor class, depending on what you're doing.
There is a thread, already with a better answer
That will actually come in handy 🙂 I always wondered how could I extend the built-in GenericMenu
@gloomy chasm is ObjectChangeKind.DestroyGameObjectHierarchy can't detect objects destroyed via DestroyImmediate?
If I removed from right click->delete in the hierarchy it works perfectly, but won't work with destroyImmediate
or should I just use OnHierarchyChange?
I wish NOT to use OnHierarchyChanged tho, but if there's no other choice then.. eh
🙂
I swear to god.. that thing won't work
ObjectChangeEvents only works with things that register undo
wait, so you suggest that it's working with DestroyImmediate or nah? sorry english isn't my 1st language 😅
oh I see now
how can one change the opened folder in the project window?
I'd like to programmatically navigate the user to a given asset in the project (interface)...
I am trying to remember, I think something like EditorUtility.Ping(object)
I also thought of this, but I think it only pings the object to the user, and doesn't actually change the current opened folder for the user...
or at least that's what I thought...
and yeah! you almost got it! it's more like: EditorGUIUtility.PingObject()
I actually didn't just want to ping an asset, I wanted to know what's under the hood that makes the project window navigate, so I could replicate that action for things like:
step back | step forward, type of thing...
arigatto! ❤️🔥
is there a way to draw gizmos for a gameobject that allows the gameobject to be selected when its clicked?
are you simply asking if there's a method that draws a GameObject's gizmos whenever it's the active object?
no, I have made it so the gizmos for my objects are always drawn, Im making a node-like system and for easy editing I would like to be able to select my node gameobjects through their gizmos
does that mean you'd like to be ablet to obtain a node's GameObject when you select a node's gizmos?
@quasi depot
sure
what's does the node in question inherit from?
anyone know what GUIStyle this button is or what I could do to easily remake it?
monobehaviour
the GUIStyle for that button is called monobehaviour?
no I was responding to Ophura
oh
also, why does this not give me the blue button for selected?
normal = GUI.skin.button;
selected = normal;
selected.normal = normal.active;
Might be normal.onActive. I can't remember when the styles with the on prefix is used. You can always open the IMGUI debugger and take a look at a button in the editor, or even specifically the "Edit Collider" button 🙂
this might be super wacky, however I think it answers your question...
yes, there is a way or 2 that I can think of, but they are mostly likely not the best suit for a reason or another!
you could make a CustomEditor for your MonoBehaviour (node),
then in the OnEnable method, get the GameObject of the currently clicked on node gizmos, like so:
private void OnEnable()
{
var go = ((CustomNode)target).gameObject;
}```if you do choose this way (which isn't necessarily recommended)
remember to have those too:```cs
override public void OnInspectorGUI() => base.OnInspectorGUI();
override protected void OnHeaderGUI() => base.OnHeaderGUI();```
@gloomy chasm just found out about this api Undo.DestroyObjectImmediate
so for example, if I removed a component it will fully restore it as well?
by fully I mean, the index or order of the component in the gameObejct it's attached to
hey, I wondered if you might know something alike for mouse input instead?
specifically for the 4th and 5th buttons...
never-mind, just realized that Mouse.current work in the Editor too!
if you're working with uitk you don't need that
also regarding this @gloomy chasm , does it also destroy it + recording in single call? if so, that's kinda neat
tell!
well, lots of mouse/pointer events in there.. also depends on what you're doing due to they require it to be VisualElement or it's derivatives (GraphElement)
you can register callback to your heart content in uitk
well, the thing is...
I'd like to receive any mouse button clicks through a solution that's independent from EditorWindow (or alike)
I'm looking for a static callback...
Not quite sure it records index, but might https://docs.unity3d.com/ScriptReference/Undo.DestroyObjectImmediate.html
tried it, it records index too, yeah 👍
But I vaguely remember there being another way too but I forgot
also as mentioned in the docs, here
how would you have access to the buffer?
is that even posibble?
I mean I can do bunch of validation in my api if I can do that.. and would be very neat
oh this guy, was reading his stuff in here at this time xd
https://forum.unity.com/threads/unityeditor-global-mouse-key-events.1312002/
Native input handlers is not a good idea
MenuItem is nice nowadays since you can change the shortcuts in the shortcut manager
Nope, the best you can do is get the list of string names of the undo/redo actions
But it used to be fixed
ah i see..
I even considered that, however, that's not what I was originally looking for 😅
you see, I was looking for mouse events, not keyboard events...
I imported it to the project, in fact way back since this answer:
#↕️┃editor-extensions message
however, this seems to only be handling keyboard events...
🤔
Ok there's one more hack that I know of
It's using onSceneGUI
It works as long as the scene view is visible
And returns mouse coordinates outside the window (but iirc relative to the scene view)
Or at least, that's how it worked many years ago
I'd still really hope seeing it working in that format though!
it's better than what I currently have, a combo of Mouse.current (which works in Editor 😳) along with EditorApplication.update
I'm trying to make it as performant as possible...
I'm using EditorApplication.quitting, it's nice and dandy so far, but there's a problem, when the Unity editor crashed, it won't invoke it
are there any way get around this?
The definition of crashing is that it's unexpected and thus it can't invoke quitting
yeah, that sucks 😭
so i have a scriptable object i want to apply two labels to and i want to create it with through [CreateAssetMenu(menuName = "MyScrObj/Type A")] so i would use AssetDatabase.SetLabels(), but it warns me about doing it in it's constructor and rather do it in OnEnabled. Wouldnt that be called every time it recompiles that way? I only want it to happen when its created. I want to avoid it doing stuff when it recompiles to keep the editor fast
I mean, the easiest thing is to handle creating the object yourself. The other option would be to do it on asset import.
I recommend the first option though
so then i would rather have a method that creates and saves the asset and have that be called in the asset menu?
Yeah
gotcha
You can look here to see how Unity does it if you want https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/ProjectWindow/ProjectWindowUtil.cs#L243
nice, thanku
Sure thing, and a forum thread that might help. Though I recommend the source code since the info on the forum thread might be a bit iffy in some places https://forum.unity.com/threads/how-to-implement-create-new-asset.759662/
ok so this just popped into my brain. Is there a way to tell unity to stop compiling if there is a specific asset missing if it is needed for a plugin or something like that?
No, that would be very messy. And the two systems are unrelated (compiling C# code and the asset database)
what about builds? same thing there as well?
I'm not sure. You can look in to it. This might be a good spot to start https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.OnPreprocessBuild.html
tho probably not something super useful as im sure if the plugin needs to check that its already badly designed but just a thought
But really, you should have it should solve itself at runtime normally if an asset is missing or something.
Basically
Is there a way to make a custom property drawer show up in an object that doesn't have a custom editor?
It does that by default... Did you forget to add the attribute to the drawer class?
Huh? What do you mean by that? Do I just need to add a variable of the type that I'm using into the drawer class?
Hmm, have you already looked at the documentation, if not I would, that might clear things up for you. https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
Ok. I have seen that, but I really wanted to work with the drawer in UI Toolkit, so I hadn't tried that out yet. Is there any way that I can do it there?
Awake should be good enough for that, unless that API isn't allowed inside Awake neither
Awake isn't called when (re)loading
Ooh, oaky. So you are wanting to use UIToolkit, but I assume you are on 2020 or 2021? Then, you are correct that the only option is to use a custom editor, or use IMGUI instead of UIToolkit for the property drawer.
If doing a custom editor, you can make a default editor that acts as a fallback for all monobehaviours and ScriptableObjects. You would have to iterate over every SerializedProperty and add a PropertyField for them. You might be able to get away with only iterating over the top level properties I think. Anyway, depends on how much work you want to do for it. You can google the specifics if you want to do the default custom editor like I mentioned
While that might work, it would be a pretty bad practice. It is best to never mix editor and runtime code if you can help it at all. And iirc Awake is called when a ScriptableObject if first loaded in to the editor when opening the project. (I could be mistaken though)
Not in 2021 at least, not sure if changed in 2022, but dont think so
What are you referring to?
About Awake, it is only called as result of a CreateInstance method, if the asset already exists in the project only OnEnable will be called (as result of loading it)
I feel like I remember Unity calling it on assets some other time as well. But again, I could be misremembering
For ScriptableSingletons, but those are editor-only anyway
That is kind of the same thing, as CreateInstance. They are loaded via InternalEditorUtility.LoadAndForget or something like that
I'm on 2023.1 ; does that change anything?
Yeah, that means the property drawer using UIToolkit should work just fine on default drawers. If it isn't feel free to share the PropertyDrawer code, the code for the class/struct it is for, and a snippet of the class where it is used. And I would be happy to take a peek at it and see what's up 🙂
Ok. Here's what I'm using (for the drawer class):
[CustomPropertyDrawer(typeof(Skill.EffectField))]
public class EffectField_PropertyDrawer : PropertyDrawer
{
public VisualTreeAsset m_DrawerXML;
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var container = new VisualElement();
VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/Editor/EffectField_PropertyDrawer.uxml");
visualTree.CloneTree(container);
return container;
}
}
That looks fine, what does the inspector look like?
This is what it looks like (type is the name of the variable the the drawer would refer to).
Is it a custom editor?
It should be working just fine.
The editor isn't custom there.
Hmm, only thing I can think of is to make a really simple setup and see if that works. A custom class with like, a single float field, and then a new monobehaviour with only that class as a field. And then a simple property draw for the custom class that just shows a label or something.
Sorry I'm not really able to give much more advice or insight on what the issue is
Ok, I'll try that out and see if that works.
It's okay. Thanks for the help so far!
That works. Also, now that I think about it, the editor that I was showing it in was actually custom. I just had it inside of a struct, so I wasn't thinking about it like it was part of the main editor.
Ahh, and that editor was using IMGUI wasn't it.
The custom editor was made in UI Toolkit.
Oh really? Odd
@gloomy chasm do you know how to SendEvent to IMGuiContainer?
So I'm wanting to trigger the ColorPicker which is a imgui method in ColorField from uitk
turns out uitk's ColorField element is basically a IMGuiContainer wrapper for Imgui's ColorField
sorry if it sounded too confusing 😂..
.SendEvent(..)?
Or, you can just open the color picker manually
SendEvent won't work apparently with object wrapped in IMguiContainer
Query the IMGUIContainer and send it directly?
reflection work, but I prefer not to do that if I can 
I did everything, including capturing the Event via HandleEvent so i can make sure where I should send it..
they just won't work with ImguiContainer
I've no clue why they wrapped UItk's colorfield with Imgui one.,.. kinda stupid tbh
I think it was only in older versions. In newer versions it is its own thing
2022.2.x.. too?
will upgrade once 2022 lts out 🥹
No, in 2022 it should be fully UITK...
it is IMGuiContainer, I swear to god 😭
Well, uh... reflection! 😓
yes it works, without a doubt, but as we both know it's not future proof 
Nah, it is pretty solid like 80% of the time. Like the color picker API is probably not going to be touched anytime soon
Aight, just reflection for now, I guess
One more, while you're here.. How can we SaveAsset but only for 1/single asset
SaveAssets seem to save all dirtied assets which can be problematic to other external libs in a project
AssetDatabase.SaveAssets(); :/
That was sarcasm, there isn't a way to save just one, sorry.
lmao, yeah I thought I was, "proly I was blind when I opened the doc multiple times already " 😂
then what is your workflow for such use case?
What is your use-case for saving an asset?
it's graphs data basically
pretty huge too
so every little thing changed in the graph will always saving it to asset
There is no need to do anything, as long as it is dirty, it will be saved by Unity automatically
Me just being paranoid and all 😂
Also, is the uitk schedule.Execute sync up with Editor thread? Pretty sure some of editor apis are multithreaded, just out of curiousity kind of question
there's the case of when I did schedule.execute it skip to the next node
so related to that too
There are only 3 things that I know of that are multithread that can run user code. That is asset import, ISerializationCallbackReciver, and UnityEditor.Search indexing.
What do you mean?
so I have a dialogSystem, so when I hit play (in playmode), the graph will open, it will follow/sync-up with the progression of the playing dialog but. there's a special node that I need to get it's resolved-style while the game is running so I need to schedule it, so it won't throw NaN value, only once i a blue moon tho it would skip
Huh, I would need to see the logic. But the style could be getting resolved before/after the execute runs.
nda'd so I can't unforutnately
Ahh good old NDAs.
What type of execution are you doing?
Could do like a really short delay or something. Or could try using GeometryChanged maybe depending on what the style is
I did add delays, but it would make the skipping much worse..
Then something in your code is real funky 😛
it's not my code 😅 it's the same dude who made this humongous thing without binding properties we spoke the other day, you know the undo/redo thing 😂
he resigned and somehow I'm handling this mess
Oof
You could try, abstracting the code that runs in the execute method and removing specific things, and share that?
duplicate apis all over the place 😂
I'll try but definitely not now, it's Saturday night here 🥹
Yeah, totally!
aight, that's all for now.. thanks, dude! you're awesome as always 👍
You're welcome! 😄
and sorry for always pinging you 😂
Lol, all good
is this not it? I thought so back then... but I still on the same old Editor version...
https://docs.unity3d.com/ScriptReference/AssetDatabase.SaveAssetIfDirty.html
It saves all assets, not a single specific asset.
I had a stupid idea, nvm xdd
im making a setup scriptable wizard for my plugin and i want to render a texture in the window. How can i make sure it always renders the correct texture? as the texture will be located in a different file once the plugin is installed. in my development project i have the entire plugin in its own folder in the assets folder, but when its installed it will be in the plugins folder
Maybe add it to a resource folder within your plugin's directory and load it via name? like so Resources.Load("TextureFileName")
i didnt know that worked for plugins
if it does that makes it pretty simple
Or you can get the path to your script's cs file and from there it'll be lot more easy..
Let me fish a method for you lol...
static string GetFilePath([System.Runtime.CompilerServices.CallerFilePath] string callerFilePath = null) => callerFilePath;
Usage within a method:
string pathToThisScriptFile = GetFilePath(); // don't pass in parameters to GetFilePath()
You're right, don't use resource folder......
Just to add on to what Roy said. You can then get the your plugin's folder from that, and easily load your texture or other plugin assets.
And yeah, it is better to avoid using the Resources folder.
You end up with really ugly paths too Assets/YourCompany/YourPlugin/Editor/Resources/YourCompany/YourPlugin/YourTexture.png
Oh and the returned path is absolute
when i make my own gui for a scriptable wizard, to do that i use OnGUI, but doing that removes the create button. so that doesnt seem to be the intended way to use make the gui, how am i supposed to it instead?
Removes what button from where?
defining OnGUI removes any of the existing ofc which also removes the button in the corner
there doesnt seem to be a way to override it and use base.OnGui()
What even is this? Are you inheriting from something?
its a scriptablewizard, its inheriting from editorwindow. its in the engine by default
Looks like you are not meant to override OnGUI. If you want to, it is best to just use a normal EditorWindow
This seems like a good source of how it is meant to use https://giannisakritidis.com/blog/Unity-Scriptable-Wizard/
oh, isee that makes more sense
is there a way i can run a method once a package has been added to the project? i were using InitializeOnLoad but that proved to be causing issues
or even when an update is installed
now im getting an error when i open the setup window after detecting an update or the installation of my package. so apparently EditorStyles.centeredGreyMiniLabel is creating a null reference exception. i assume it has something to do with when i open the window automatically. as it only happens when its opened with a method added to Events.registeredPackages. any idea what is wrong here?
i guess this isnt really an editor extention question, though there isnt really much of a place to ask questions about packages 
i found a solution to the issue. i just moved the code to a different part of the script and it works every time
This don't seem to work. It works fine in my development project, it returns the cirrect path. But when its installed it returns the wrong path. Instead of being
E://..../myproject/Packages/script.cs
It still returns
E://..../myproject/Assets/script.cs
Where are you calling it from? The path will be for the script that calls the method
its within the awake event in an editor window which should be within .../Packages/Mypackage/Editor/myScript.cs otherwise it should be in the assets folder.
could it be something weird with how im adding the package when im testing it?
as im adding it from disk, so if its technically being called from there then it could make sense?
yeah, it does in fact seem to be returning the path from my development project isntead of the project its installed in
IDK about how you adding the package.. but as @gloomy chasm mentioned this method will give you the caller path
If you have duplicates of this script, then you need to make sure the one you need is executing.
You can also create a script (a helper script maybe) just for that in the root of your directory, where you keep the assembly definition file
And within the script expose that method
Obviously you'll have to manipulate the given path for your needs
i guess ill check out if it works when i install it with a github link instead of from disk. though this could be a good idea
That won't change anything. I can almost 100% promise you it is because you are calling it from a script that is not in the package
It is being compiled into a DLL btw?
idk how it works in the background, but im just using assembly files together with the scripts
but why is it not even returning a path within the project the package is installed in then? its returning my development project instead. these are two completely seperate projects in different locations 
I think the packages is outside of the project, and in the project you only keep them as dependencies (someone correct me 🙂 )
Try this. Put this in your package.
YourProject/Packages/YourPackage/Editor/TestScript.cs
public static TestScript {
public static void Test([System.Runtime.CompilerServices.CallerFilePath] path) { Debug.Log($"FilePath: {path}"); }
}
And this in your other project. Run the MenuItem and tell us what it logs please.
OtherProject/Assets/Editor/TestMenuScript.cs
public static TestMenuScript {
[MenuItem("Test/Run Test")]
public static void Test() { TestScript.Test(); }
}
ok so if i put this in my package:
public static class TestScript {
[MenuItem("Test/Run Test package")]
public static void runTest() => Test();
public static void Test([System.Runtime.CompilerServices.CallerFilePath] string path = null) { Debug.Log($"FilePath: {path}"); }
}
and this within the other project:
public static class TestMenuScript {
[MenuItem("Test/Run Test")]
public static void Test() { TestScript.Test(); }
}
then when i use the menu item from the package Run Test package when its installed in the other project, it returns the file path of the project the package is developed in even though its triggered from the other project.
But the menu item from TestMenuScript returns the correct path from that project.
Ahh I see, you are misunderstanding a bit. CallerFilePath is the path to the script that directly calls the method.
ok so it should work if i dont have the package locally from another project then right? as then its not being called from there anymore?
No, it only matters where you call it from. It doesn't matter if a package is local or not.
then what happens if its installed from a git link?
would it just throw an exception?
No, let me try to explain it more
It does not matter where the method is that has the CallerFilePath attribute
The only thing that matters, is where you call it from.
You can think of it as passing a reference to the class
You can sort of think of it like doing this. (This is not valid code, but I hope illustrates what it is doing)
public static class TestMenuScript {
[MenuItem("Test/Run Test")]
public static void Test() { TestScript.Test(typeof(TestMenuScript).GetFilePath()); }
}
yeah tho i wanted it to be called from a script inside the package go get the package location. so if its isntalled from a git link, the location its called from should be from within the same project right?
If you call it from within a package, then the path will be within the package

is there a way i can stretch the image of a GUILayout.Label
GUILayout.Label(m_PaletteTex, GUILayout.Width(m_PaletteTex.width * 4), GUILayout.Height(m_PaletteTex.height * 4));
GUI.DrawTexture is the right way iirc
what about only displaying a slice of an image?
Im making an environment palette editor, the preview image i have here is a texture that contains all of the palettes in sequence, each being a 1px tall horizontal slice; could i display a texture of only the specific slice that is selected?
Is there a way to make property drawers use conditional logic?
In what way
Something like if (exampleBool == true) popup.Add()(new PropertyField(property.FindPropertyRelative(exampleEnum), "Example Enum");
Yeah? Why wouldn't you be able to
Are you running into some issue trying tod o that?
How do I actually refer to the bool? Since its a property drawer, I can't just use exampleClass.exampleBool.
What does that mean? Are you saying that I need to have the bool have its own property drawer?
property.FindPropertyRelative(exampleBool).boolValue
Ok, that works. Thanks for the help!
is Application.logMessageReceived called even when unity crashed?
it is not.. F this...

There is nothing to get when Unity crashes by it's very nature. Imagine if the reason Unity crashed is because you forced classed it because there was a infinite while loop. What/how is it going to call?
back in the day we can do this on the c# side AppDomain.FirstChanceException but that thing been broken since 2019.. kinda unfortunate
also AppDomain.FirstChanceException is native call so nothing on Unity side can affect it
How to reproduce: 1. Open the attached "Unity_ExceptionHandling_Error.zip" project 2. Open the "SampleScene" Scene 3. Enter the Play...
very unfortunate
Looks like it is a Mono issue
their fork of mono to be exact
What is it that you are trying to do when Unity crashes?
lmao, yeah that's still unfortunate
saving states bunch of scriptableSingletons
all editor configs are in there
Just save when the value changes
unfortunately it's not that simple, turns out some of the internal undo/redo are handled internally (without Unity's undo class)
so the system was made to wait for other changes to meet certain requirements first
the buulk save them all
uhhh... i am like 98% that is not correct... Do you have an example of one these things and why it is causing an issue?
aight, think it like this.. so we have bunch of tabs, some fields related to each other and must be filled before we can carry on or save them
this wasn't mine originally
and I'm not going to re-implement this from scratch.. it's massive
wai a sec.. dont type yet
So we have this internal tests for editor crashes, which we should pass, before we consider that the tool is done
aight thats it 😂
the system gets f'd during this test badlly
So, if you need to modify all the ScriptableSingletons before saving. But crashing doesn't save them at all... I kind of feel like that solves the issue... no?
unfortunantely, they tested it when all fields were filled and they crashed it. I failed that part.. also I know what you mean
Something breaking when Unity crashes is a symptom of a problem. Not the problem. The best I can say is to either save them after each value is set, or change something else, whatever it is that is breaking. But trying to do something when Unity crashes is not the right approach
I know, I was trying to avoid bunch of tinkering and as said this is a one massive internal tool
one fella told me to capture via winApi, which I'm trying to do now 😅
if this is a no go then yeah will do what you usaid
I'm sure that will not lead to any extra bugs or technical debt in the future! 😄
theoritically this can work, iirc we have something for tihs as well to one of our tools
man, I just want to NOT touch this project again asap 😅 ...
it's too massive for one person to handle tbfh
Man... I so want to know what it is xD
Understandable
big O will put me in jail 😅
how come I'm having issues with element.FindPropertyRelative(value);?
I have a custom class I'm trying to display:
public class Attribute {
private string _key;
public string key {
get => _key;
set {
if (_key != value) {
Debug.Log("Key changed:" + value);
_key = value;
}
}
}
}```
void DrawListItems(Rect rect, int index, bool isActive, bool isFocused) {
SerializedProperty element = list.serializedProperty.GetArrayElementAtIndex(index);
SerializedProperty property = element.FindPropertyRelative("key");
if (property != null) {
EditorGUI.PropertyField(
new Rect(rect.x + 20, rect.y + 1, 80, EditorGUIUtility.singleLineHeight),
property,
GUIContent.none
);
}
but it's not displaying the values properly
however, if I change _key to public and use:
SerializedProperty property = element.FindPropertyRelative("_key"); instead it works fine
even though as far as I can tell, key should be returning _key anyways?
Properties are not serialized so you can't use serializedproperties (I know confusing name)
why does _key work but key doesn't?
_key is field, key is property
so is there no way to get the property instead?
@gloomy chasm Is your editor extension here: https://github.com/MechWarrior99/Bewildered-Core made in IMGUI? I asked about some issues I was having with property drawers here the other day, and you said that trying to use a UI Toolkit property drawer in an IMGUI-based extension might be causing the problem. The particular drawer I was having issues with was inside one of that extension's UDictionary data types, and I'm not having issues with that drawer anywhere else, so I was thinking that that might be the problem?
yeah it uses IMGUI. So if you have a PropertyDrawer that uses UIToolkit, it won't show up in the dictionary
Ok. So if I rewrite the drawer with IMGUI, it'll show up? Would doing that break it showing up in UI Toolkit based custom editors, or would I still be fine with doing that?
You would want to override the CreateGUI method and have both that and the OnPropertyGUI overrriden so that it could work in either
Ok. Thanks for the info!
How can I show the gizmos of a component which I used hideFlags to make it invisible in the inspector?
Show it from a different component.
mmm, the idea was to have the gizmos in that component
Why? If you can't see it, that means you can't remove it. So I assume you have another component that is managing it, no?
The manager component isn't a MonoBehaviour so it doesn't have gizmos.
I rewrited my gizmos to use handles instead... thought for the next time I would like to have used gizmos
You could have your manager add a callback to SceneView.duringSceneGUI and check against Selection.gameObject
duringSceneGUI support Gizmos?
I don't remember, I think so... maybe
But Handles has almost all the exact same controls
Yeah I went with poor man's way of handling it
1, Serialize to json (only for the active/related tabs)
2. Use SessionState(int) to check on 1st boot after crash (default SS is 0, means it's fresh start)
3. Have a boolean in ScriptableSingleton subscribed to EditorApplication.quitting if quit normally = true, else false
4. Crash the editor.
5. on initializer [InitializeOnLoad] check for SessionState if = 0, means fresh start then check the bool in ScriptableSingleton if false = was crashed, else was fine
6. Deserialize back the json , then reset the states in ss
🥹
@gloomy chasm
Did it via WinApi too, it worked but was a bit iffy so, yeah
time to go home now *putMySunglassesOn 😎
Hi! I'm having issue with a property drawer suddenly stopping working and now keeps sending me nullref errors I cant track. I tried rolling back the custom drawer to find out what it was but it's straight up broken it completely and not even reimporting works
Atm the property drawer just calls a EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); wrapped around a "BeguinProperty"
Nevermind, solved
Nice, that is a good solution! 😄
almost getting used to this whole custom editor thingy.. still a lot to learn lmao
Same mate, same
I just learned how the error of trying to FindPropertyRelative with a bad string looks
if it wasn't bcos of uitoolkit I'll never want to dive deeper into custom editor stuff
It's not that bad
IMGui was super bad
.. UITK made everything, way way easier
Anyone know why this doesn't work, but if I set the main container it will set the background color for the title container and main container of a custom node?
I just want the title to be a different colour, and set the background color for the main container separately....
No idea, it depends on what the uss is that you are using and what the structure of the node looks like
Maybe the misspelling of dialogue is an issue, who knows
Anyone knows how to get these foldouts? I cant get the dark background using EditorGUILayout.Foldout or EditorGUILayout.BeginFoldoutGroup
You have to do the styling yourself unfortunately.
With a GUIStyle?
Yeah, or you can just draw rects
I think there might be an internal class that handles drawing that one. But it is component specific. Really, for both you can open up the IMGUI debugger and inspect their style and see for yourself what it is called and what is set
Hello, I hope this channel is close enough to the topic i need help with:
My editor is giving me this error and i think i'm close to solving it but idk where is the right address (see image)
If i could make a forum thread out of this that would be ok too. This problem isnt urgent. Thanks for your time🙏
I wasnt aware of the IMGUIDebbuger, it seems like a powerfull tool thx
Has anyone gotten EditorGUI.ObjectField() to take an interface as a type constraint?
There are lots of examples in git repos of this working. But those examples no longer work in the current versions of Unity. I wonder if support was actually dropped for this at some point.
turns out. there is! https://docs.unity3d.com/ScriptReference/AssetDatabase.SaveAssetIfDirty.html
Yeah it's pretty new
I can only find examples of it not working, but I thought Unity added support at some point to define public fields with an interface type 🤔
hey, I'm manipulating directories via code (editor script) (to be specific and speak about Y right away, I'm making a package template, which automatically renames folders, asmdefs, etc), e.g. deleting, moving, renaming and it works fine, except I can't get Unity to properly register my changes. it requires me to restart editor and everything works then. this is unacceptable. I added AssetDatabase.Refresh() and UnityEditor.PackageManager.Client.Resolve() callbacks, but still no luck. specifically I get this warning:
Couldn't create 'C:!my\gamedev\unity-projects\testing-package-template\Packages\com.company-name.package-name/~UnityDirMonSyncFile~44d261d1b2c0f344499aeafe0c15a0ca~'
(it tries to create some sort of internal file in a folder I renamed)
and this error:
ArgumentNullException: Value cannot be null.
Parameter name: _unity_self
UnityEditor.UIElements.PropertyField.<CreatePropertyIMGUIContainer>b__43_0 ()
// etc...
how do I mitigate it? is there some guide on manipulating directories from within scripts?
in what condition an Undo would lose it's states or cleared from the buffer? I have this weird quirk where one of my Undo.DestroyImmediate and it's derivatives would lose their undo states
Show code
It shouldn't? Unless you didn't register it properly
yeah thats what I thought, still looking for the cause of it
TIL Unity has UnityEditor.FileUtil, I will try using this instead of System.IO, hope it helps, if not, I'll comeback
(I should always prefer using FileUtil over System.IO functionality, right?)
I'm not sure what exactly you're trying to do but I'd guess so
this question is detached from the original one, in general I mean
I'd guess so
alright
I hope it handles meta files automatically 😄
otherwise will be pain in the ass
Is the source
but where is actual api 🤔
oh thanks
Looks like somethigns are native unfortuantely
yeah, I will just test how it works practically
https://docs.unity3d.com/2022.2/Documentation/ScriptReference/FileUtil.MoveFileOrDirectory.html#:~:text=Make sure to include the name of the files or directories at the end of the "to" argument.
I can't understand what does this quote mean?🤔 what is "to" argument?
Which bit specifically?
I linked to specific quote, it opens like this highlighting it (in edge at least)
anyway, here it is:
Make sure to include the name of the files or directories at the end of the "to" argument.
ehm then it's also kinda meaningless 😄
i.e. just "make sure your path is correct"
whatever, thanks for clarification
Yeah it is
ok it doesn't work either way, here is the code
https://paste.ofcode.org/yf8SYvZWQD9ggjptkpYSGn
What doesn't work?
exactly as described here
nothing changed when I replaced System.IO with FileUtil's functions
still getting same errors
the thing is
everything works
except I get these errors
which is unacceptable since I'm going to ship this
well after editor restart, definitely
it's just I need to somehow tell Unity that "hey I just renamed these folders, hey I deleted these folders" so that it doesn't try doing its' things to them and throw errors
(presumably some refresh callbacks but idk)
ok I now manually remove .meta files of folders I delete, still same errors (warning and error)
I'm totally stuck at this point 😦
do your own filtering there
or this one. The awesome MechWarrior99 told me that it only works with Undo record objects iirc
https://docs.unity3d.com/ScriptReference/ObjectChangeKind.html
Hey, anyone with some knowledge of the Asset PostProcessor? i.e: OnPostprocessAllAssets()
I wrote an Editor script to mass import asset (models/textures) and auto assign textures/materials to models, then generating a prefab.
The problem is that whenever I disable that script (In the Editor folder), my prefabs models loose their materials list.
Am I missing something and there's some api call to make the imported assets "permanent" (so they don't get re-imported again if the script is triggered?)
Any ideas? thanks
It's been a while but that sounds like something else is setting them to null
You are assigning materials to imported models?
Your import stack needs to be deterministic. If you disable a script that performs a postprocess step then that means you've changed the deterministic output and have no reason to expect the imported assets to remain the same (whether that is immediately, after a reload, or if cloning the project directory to a new location).
If you perform a postprocess step that modifies an import then you need to always apply that step. There's no such thing as "fire-and-forget" when dealing with importers
But that shouldn't change assets that are not being reimported (and disabling an importer shouldn't reimport assets)
Which is at least my interpretation
The argument I'm making is that it is moot because the import stack is not deterministic and any future reimport for any reason will overwrite his changes
For sure
It also sounds like an xy problem, why do you need to disable that script anyways
I'm assuming because it is not efficient
But I am also curious why you're disabling it
Well then lets solve that
Since the issue is likely that it's ran for everything
OnAssignMaterialModel TIL this callback exists
I don't understand how I make use of it
what filtering are you proposing me to do?
and this one don't get too
can you perhaps suggest where in this code I use these things and how?
I think I can trigger editor restart, but it's not ideal and I want to avoid that
@rain beacon call AssetDatabase.ImportAsset or one of its variants
and use DeleteAsset instead of file APIs to delete the folders
CreateFolder to make folders
etc.
and use StartAssetEditing and StopAssetEditing to make sure all your changes are batched
AssetDatabase has most of the methods you need to do manipulations so you shouldn't need to use raw file apis most of the time
just for file writing usually, in which case you'll use ImportAsset
Oh, but you are dealing with packages, not project assets?
How does that work?
yeah I mean asset db is about /Assets/, right?
not /Packages/
AssetDatabase is relative to the project root, not the assets folder
so there's nothing stopping you from accessing the Packages folder, I don't think
well I will try that when I'm home, thanks
👍
so far neither FileUtil nor System.IO work properly
(they work, just Unity doesn't register changes properly)
fileutil is for raw file manipulations, so it doesn't have any knowledge of the asset structure of unity
(or vice versa)
then I don't get purpose of FileUtil
other than it being from Unity, and therefore knowing about its asset structure, and therefore working with them properly, I don't see it's purpose compared to System.IO
I think it's on the tin -- it's literally a util for File operations. It looks like it provides a simpler API for common file operations that aren't as intuitive using the std library
sometimes there are reasons for doing raw file operations
in project directory and not respecting unity specific things?🤷♀️
what is example use case
for deleting or moving specifically
anything regarding streamingassets directory
I've also done some editor plugin stuff that requires manual file operations
but I then import those files using ImportAsset
okay I will try that👍
yah, so use DeleteAsset when deleting (inc. folders)
and ImportAsset for created stuff
@rain beacon and dont forget to bookend with StartAssetEditing and StopAssetEditing
it will batch all of your operations so they happen at once
rather than import, wait, import, wait
it'll be one import op
well don't we start optimizing what is not even working yet😄
but okay, it's nice thing to include, thanks
it's not really a micro-optimization, it's just a best practice
no reason not to get into the habit
gotcha
does it actually do anything in this case?
AssetDatabase.StartAssetEditing();
if (pathsToDelete.Count != 0)
{
AssetDatabase.DeleteAssets(pathsToDelete.ToArray(), new List<string>());
}
AssetDatabase.StopAssetEditing();
it's like a single operation, but at the same time multiple operations 🤔
(well, it's better to make these calls from inside if, but that's not what question is about 😄)
what is the best way to get duplicates of objects in hierarchy, like when people doing ctrl+d in hierarchy?
I mean, without having to iterate all unrelated objects via HierarchyChanged
(pretty sure there's no other way to do it) 
Instantiate should do the trick
there's new and pretty neat api that Navi and some good fella found on c# server 😆
https://docs.unity3d.com/2022.2/Documentation/ScriptReference/ClipboardUtility.html
you're late this time Mr. MechWarrior!
😆
[CustomPropertyDrawer(typeof(ItemSpawnConfig))]
public class ItemSpawnConfigEditor : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
float height = EditorGUIUtility.singleLineHeight;
if (property.isExpanded) height += 2 * EditorGUIUtility.singleLineHeight;
return height;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, label);
if (property.isExpanded)
{
var itemIdProp = property.FindPropertyRelative("ItemId");
var weightProp = property.FindPropertyRelative("Weight");
EditorGUILayout.PropertyField(itemIdProp);
EditorGUILayout.PropertyField(weightProp);
}
}
}
I have this custom property drawer (for Item0, 1, etc), but it renders below where the items are supposed to be; am I missing something? I tried using EditorGUI instead of layout as well, it seems the input rect is just starting at the end of where it would've been without a custom drawer
You cannot use Layout methods in PropertyDrawers. You need to use the manual positioned Rect methods
because I want to import other (same type of asset) models with different settings
I would recommend separating by folder or name then
I see, thanks, so there's not really any way around it, no way to "hard-code" the imported assets?
I am dumb, I tried that but I modified the rect.y instead of rect.height 🤦♀️
thanks
Not as such.
Sounds like you need a custom importer
afaik it's not tremendously straightforward to extend the functionality of existing importers
the 'easiest' way to do this based on what you've said so far would be to create a custom file extension that has its own scripted importer & creates the models with the appropriate settings
how can I hide this?
second question : How can I prevent user adding new component via dragNdrop on the inspector?
Currently I'm thinking of doiing it via MonoB.Reset but proly there's a more graceful way of doing this
Reset won't allow you to prevent the adding of components
Why would you want to prevent the user from adding components
I know, I meant as quickly remove newly added one
it's a request which I don't know either why they wanted that 😂
Reset would only get called if they're adding a component that has a reset callback, it doesn't get called for every component on the gameobject
oh!, that is nice to know!
You may be able to do something with hideflags
HideFlags.NotEditable
Maybe setting that on the gameobject will prevent adding new components?
I think their reasoning is that they wanted to keep the order/index of components of certain classes added to the inspector
It will also prevent values in components from being editable, though
Wut
you heard me right, they're doing binding to another api, and the gameObjects in the scene are for retaining some states
like there are tons of componnenets there
Order of components should never be relevant
it is, apparently the order/index of components soorta important for their use case
doon't ask me why 😂
youu mean we cant doo muuch prevennting user adding componeents?
I don't think GetComponent even makes guarantees about the order in which components are retrieved
my keybvoard is broken so pardonn for dplicate lletters 😂
switching to my other keyboard.. it should fine now 
NotEditable is your best bet, but it has other tradeoffs
such as?
Can't edit component values
yeah, that's not an option sadly 
I would seriously question the architecture of something that depends of component order, tho
Is this a professional project?
it does apparently, I tested this myself with same components
the last added will always be put at the bottom/last order
just like list
this is what I mean: https://docs.unity3d.com/ScriptReference/Component.GetComponent.html
Note: GetComponent returns only the first matching component found on the GameObject on which it is called, and the order that the components are checked is not defined. Therefore, if there are more than one of the specified type that could match, and you need to find a specific one, you should use Component.GetComponents and check the list of components returned to identify the one you want.
The API does not guarantee that the components will be checked in a specific order
That's what I thought too when I 1st read the docs, but it actually getting the last order... give me a sec I think this part of code isn't nda'd
Just because it's doing something specific now doesn't mean it can't change later
Practically it's a moot point because as you say it likely iterates down the list in order in the implementation.
ah, they're doing GetComponents and getting the last index
I'm more pointing out the principle that the architecture is poorly thought out and isn't technically to spec
this whole thing originally wasn't mine 😅
but yeah, they're doing that to get the last added component 👆
I tested this myself as said, it is guaranteed to be always in order with GetComponenets
Anyway, it's not really possible to prevent people from adding components
yeah, which is kinda suck 
It's one of the core features of the engine 😄
You're missing the point.
If there's a surface with a sign on it that says "slippery when wet", it would be incorrect to assume that the surface will never be slippery because it is currently dry.
Ergo, it is incorrect to assume that the order of components is always guaranteed just because the order is guaranteed now, when the docs say it is not guaranteed.
agreed
If the project you're working on is an asset that will carry over multiple project versions then this is relevant. If it's a product that is fixed to one version then I'm making a purely rhetorical point since the handling of component order will not realistically change randomly within the same version.
And at the end of the day none of this matters because its not your code and you can't make structural changes to it sounds like
I did not lie, see this 🤣
also, this part is not nda'd so I can share it here
2023.2.0a17 (https://unity.com/releases/editor/alpha/2023.2.0a17)
Editor: Added a
PropertyCollectionAttributethat can be used to implement custom drawers for collections.
Editor: Removed importing of scripts and plugins. The import artifacts for script and plugins are now generated in each Unity Editor session as transient artifacts. This change improves Editor performance as the transient artifacts are faster to generate than performing the imports.
This is also a cool change
Oh interesting! I thought it was a property drawer, but it is a base class for creating attribute/decorator drawers
(Even has an example already 😄 )
Yes (the docs didn't exist when I posted it)
I just looked at the source, which was up to date
Yeah, I was just confused at what it was. So I figured I would check the docs before he source code haha
I do kind of feel like they could have just addded support to the existing attribute system instead of creating a new attribute that you need to inherit from though
I imagine it's a performance consideration or something
It has been a while since I looked at the property drawer code. But from what I remember, they do special handling for lists/arrays. And this would have been the easiest way to do it with the existing code
it is weird, because built-in things like Header presumably won't work
What... looking at the code, it looks very unneeded
and something like that will now need to have [CollectionHeader] and [Header]?
I suppose you do already have the PropertyAttribute there in that case, and the other case I'm looking at
OOOh, I get it, they did it this way because decorator attribtes apply to the elements in the list.
But wouldn't it be better to simply add a optional bool to the decorator drawer like applyToCollection or something
That seems like a much cleaner way to do it. And lets you use Headers and stuff
Since it is a alpha, I am going to make a forum post and hope that maybe they will be willing to change it to do that instead
It would be so much nicer implementation and usage
Not that I am holding my breath
Like am I crazy, but you can't even make Header inherit from PropertyCollectionAttribute to give it the additional functionality of applying to collections instead of the elements
because that would make it so you can't apply to normal fields?
You are not crazy. You would need to make a whole new set of attributes just for collections
Like Header and CollectionHeader, Space, CollectionSpace, etc.
Just seems like a totally nonsensical way to write this
Thinking about it more, it is even more code too then just a bool
Yes, you should really open the source with your IDE
Why is that?
to see what code is relevant with find references
Github lets you do that now 😄
Poorly and slowly
Seems to work fine enough for this
Like, do they have some usecase where it would make sense to restrict a PropertyCollectionAttribute from being applied to normal fields
Is it like "what if I read arrayLength and use that somehow and now need to handle single fields too"
one usecase that I can't even think of a reason for, vs duplicating attributes for most other decorators
And you could get around that usecase by having the bool be virtual so you can just force it to always be collections only
Did you make a post?
Just finishing it now.
DecoratorAttribute isn't a thing
Right thanks, I was thinking of DecoratorDrawer 😅
Now, here's hoping they can and will change it! 🤞
Has anyone figured out the correct way to sync transition animation USS classes in UIToolkit with the Unity Editor for Editor Tooling?
I'm currently using EditorApplication.update with some boolean checks
private void OnEditorUpdate()
{
if (_updateButtonVisuals)
{
_updateButtonVisuals = false;
DisplayCorrectButtonVisuals();
}
if (_updateFieldVisuals)
{
_updateFieldVisuals = false;
DisplayCorrectField();
}
}```
I don't understand
So, I have this custom UXML element. It uses context menu (Generic Menu) to switch between some fields with animations (swipes out right one field, swipes left in another field). Turns out that at some given times, if I spam the switch button, the transition animation skips to the end.
The way I worked it out is to let the EditorApplication.update do that work for me with the if statements you see in the code
But I'm thinking I might be doing something wrong.
This is an editor-only tool.
So, what is wrong if it skips to the end?
because the transition animations of the USS classes take 0.25s, not 0s.
I guess I am not understanding the issue. So if you spam the button it can sometimes skip the transition. Besides looking a bit ugly. What is the issue that this causes that the above code is fixing
The issue the above code fixes is that it will never skip. It's synced with the Editor and will work as intended
So it is the ugly skipping to the end that you are trying to fix?
Exactly. I'm just wondering if there's a better way to do it. await Task.Yield(); also seemed to work but I was advised not to use it.
It made sense to use it since they are supposedly using async methods in UIToolkit (BindProperty() for example)
Tbh, I wouldn't worry about it. The chances of someone spamming it are not very high imo. Though would report the issue for sure.
Unless they just changed it recently, BindProperty doesn't use any async code.
https://forum.unity.com/threads/registervaluechangedcallback-had-a-breaking-change-in-a-recent-update.1036942/#post-8898624 the source of that statement I made
Huh, thanks for the source 🙂
is there a good way to store cached session data in the editor, in a way that serializes/survives assembly reload without a lot of boilerplate handling?
I've often used hidden game objects with a component on it but it's always felt like such a hack
OdinSerializer? Free and open source
without using third party solutions!
SessionState not appropriate/too restrictive?
(this is for a plugin of my own, I don't like having dependencies)
Just to clarify, you can use it for your own stuff and sell it with your package.
No licensing
yeah, way too much boilerplate, it's quite a lot of data, things like selection states and references to currently living objects in the scene and whatnot that I want to keep intact
Also note that both editors and editor windows can have stuff serialized in them while they are open, I feel like a surprising amount of people don't realise that
yeah, in this case it's data I need across separate windows and states
Darn. Mostly painful then afaik
(it's currently living in an editor tool for example, but I need access to it even when the tool isn't open and from gizmo drawing calls and whatnot)
Everytime I went down that road, the answer I always got was: build your own serializer 
the serialization itself isn't really the issue
it's more about lifetime, data storage method and ease of read/write
I was thinking maybe I can do the hidden gameobject thing but with a ScriptableObject instead? like a SO HideAndDontSave singleton just sticking around as a data holder. but idk if that's possible
you know this kind of thing
You can just use a ScriptableSingleton to do it
what kind of issues?
It was like 1 year ago. I can't remember, sorry
But it was giving me exceptions
I might have a commit somewhere in my version control. I will investigate
The logic is super simple for it
https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/ScriptableSingleton.cs#L71
ScriptableSingleton is just too awesome, lemme tell ya!
sad I just found out about it like 4 months ago 
Yeah I use it a lot. So does Unity internally
mmkay, gonna try this, thanks!
https://forum.unity.com/threads/error-scriptablesingleton-already-exists-did-you-query-the-singleton-in-a-constructor.880258/ I found the google search I did at the time of the Exception I was getting.
hmm, okay, we'll see if I run into that
my use case is that, I'm making a spline tool, and I need data on which spline components you have selected in the editor, along with which control points on each spline are selected, as well as cached data about each spline (for editor performance reasons)
and I have multiple different things that need access to this (inspectors, EditorTool, EditorWindow)
and so I wanted to centralize this selection and cached data someplace that survives assembly reloads and isn't tied to any of these other temporary/optional tools/windows
literally first thing that happens lol
A Blackboard
Sorry for jinxing it :\
what do you mean?
I was mentioning the Blackboard pattern. Maybe it is something you want to pursuit
oh, I, have no clue, I don't know any patterns haha
anyway I shouldn't have to initialize it in a static constructor so I think I shoooould be fine
I think the actually issue is that you are initalizing it in its own static constructor. I feel like I have some code somewhere where I access a ScriptableSingleton in a InitalizeOnLoad static constructor. But I could be wrong.
I feel like it shouldn't matter where it's initializing from
I would expect the same issue in a different static constructor
I was thinking that maybe the InitalizeOnLoad was playing funny with the instance constructor. But I guess not
Is it not the InitalizeOnLoad + Static CTOR?
Just tested it. I was right. It is the InitalizeOnLoad on the ScriptableSingleton.
Works fine calling it from other a InitalizeOnLoad static constructor
oh, huh, bizarre
I don't thiiiink I'll need to statically load it anyway, so I should be good
thanks for the help!
Sure thing!
@gloomy chasm is ObjectFactory.componentWasAdded gives the actual reference to the component that's just added to the gameObject or not?
Yeah, what else would the returned component be?
Just to be 100% sure, so it's basically the same as we're doing GetComponent manually?
It will give you the same component yes
aight, thanks.. as usual 👍
is there a SerializableDictionary in editor yet?
I vaguely recall there was some
in some obscure namespace, like Rendering or something
oh here we go lol
love it when Unity.Cloud.Collaborate.Common
There is one in Rendering, or in the SRP at least. But realistically, not really. Still gotta role your own.
If you want editor support I have my own that has it and is MIT https://github.com/MechWarrior99/Bewildered-Core
You would think that at this point they would have added one. I know there are a number of internal implementations like that one in cloud. But here we are, still not serializable dictionary.
yeeeah it's odd
Unity has commitment issues. Easier to make another internal implementation and not have to deal with writing documentation for it and supporting it forevermore.
Or in this case, copy one from Unity Answers :P
yeah I just stole the same code that unity did
lol
I need a camera object to always look at another object in the scene view. that is in the editor window. am i in the correct chat section
Yes
The simplest way to do this imo is by using a script annotated with the ExecuteAlways attribute
It's kinda odd that they added dependencies feature to their own official packages but would not allow us to have access to it
my concern is that I'm planning to make an asset store package but it depends on another package on assets store, and we don't have a way too automagically download the dependencies on AssetsStore
I'm guessing their burden on this matter related to licensing issues
Yes, I am creating/assigning materials and textures manually then turning it into a prefab, but there's also the model asset which "holds" the materials. (script: https://pastebin.com/UiRTLf89)
Thanks for explaining, and sorry though, I need to wrap my head around this, I (wrongly) assumed the processed assets would become a unique "piece" of data, as unique assets and it's components.
But it does seem that removing the custom AssetProcessor script from the Editor folder, causes the assets to re-import and of course no custom processing, the assets are re-imported with raw default settings.
Is there some way the processed assets can be saved for lack of a better word "be hardcoded" and not be re-imported if the AssetProcessor script is triggered?
Thanks
that worked 🙂
using UnityEngine;
using UnityEngine.PostProcessing;
namespace UnityEditor.PostProcessing
{
[CustomPropertyDrawer(typeof(MinAttribute))]
sealed class MinDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
MinAttribute attribute = (MinAttribute)base.attribute;
if (property.propertyType == SerializedPropertyType.Integer)
{
int v = EditorGUI.IntField(position, label, property.intValue);
property.intValue = (int)Mathf.Max(v, attribute.min);
}
else if (property.propertyType == SerializedPropertyType.Float)
{
float v = EditorGUI.FloatField(position, label, property.floatValue);
property.floatValue = Mathf.Max(v, attribute.min);
}
else
{
EditorGUI.LabelField(position, label.text, "Use Min with float or int.");
}
}
}
}
Don't do using UnityEngine.PostProcessing;
Also you know you could've asked q uestion isntead of just posting an error
Oh wiat
It's not even a custom editor
Fully qualify the type instead
how would you make the custom editor window remember where it was docked in the Unity editor?
It does by default
one more, Navi, how'd we know where our custom editor docked at? e.g inspector area, gameview area etc
I forgot but look at the parent classes of EditorWindow
IIRC one of them has something
There's no predefined areas though
So you need to look at which windows are docked in the same area
noted, thanks! looking into it now 👍
iirc EditorWindow has a internal parent field which is a HostView, and from that you can get the parent, and find other windows that are docked.
aight, thanks Mr.Mecha! I'll be back with tons of questions once I hit a brick wall 😂
Hi, is there a way to detect when a user changes "pro skin"? or should I check every frame 🤔
IIRC it recreates the windows when you change skin and it should work automatically if you check on creation?
Perhaps what you can do is create a scriptableobject that contains the properties you want to apply, and then put an instance of that scriptableobject in the folder in which you are importing the assets. Then, in your asset postprocessor, read the SO instance in the folder and apply its settings if it's present.
Basically, would make your settings apply per-folder
I bet there's a way to make that work using a custom scripted importer as well but not sure without playing with it myself
it works 😎 🥳 .. thank you Mecha, and @waxen sandal 👍
Greetings, I am writing a PropertyDrawer for a generic class, so something like this.
[Serializable]
public class Foo<T> {}
[CustomPropertyDrawer(typeof(Foo<>))]
public class FooDrawer : PropertyDrawer {}
In FooDrawer, I need to get the generic argument T of Foo. This is easily done with
fieldInfo.FieldType.GetGenericArguments()[0];
However, this does not work, when there is an array of Foos, as fieldInfo will point to the array itself. Currently I have the following solution.
type = (fieldInfo.FieldType.IsArray ? fieldInfo.FieldType.GetElementType() : fieldInfo.FieldType).GetGenericArguments()[0];
I did however notice that there is an extension method to SerializedProperty in Unity.VisualScripting, GetUnderlyingType, which seems to get directly to Foo, even if it's in an array. So the following would work.
type = property.GetUnderlyingType().GetGenericArguments()[0];
So my questions are:
- Is either of these two approaches better, or is there an even better solution?
- I've never interacted with VisualScripting, but why is there a namespace for it in C#? Is there a reason to not use it?
Thanks!
Both seem fine to me
I'm guessing visualscripting might be in an optional package so it might not be available in other projects
And for why it's there, well I guess they need some C# side of things for the editor and stuff
Alright, thanks.
Can anyone help with the syntax here? I'm trying to get the Asset name of a file from a SerializableObject. I can see the property I need is m_Name, but when I use find property and string value the string is empty.
Try "name"
"name" just returned the name of the property in the class. In this case, 'Node Graph'. However, I've fixed the issue with serializedProperty.objectReferenceValue.name
👍
Hi guys, does EditorGUI.GetPropertyHeight() ignore HeaderAttribute? consider the code in this image
Produces the following result (notice the 4 keyword fields, yea it should be 4 lol)
Oh and this is the class BTW
Or does it treats the HeaderAttribute as distinct property..? IDTS... 🤔 because the overall height is also wrong
Not sure but I think your addition of height is wrong
Doesn't it set rect.height to height before adding it to y?
Hence you're taking the new property's height instead of the one you just drew
Pretty sure somethin else in your math is also wrong
Look at keywords for example
It's supposed to draw 4 fields
That's how it works, isn't it? you define a rect and then draw it
But there's only 3 properly layouted and 1 drawn behind
Yes it got swallowed lol
Oh I'll add this now and see!
It won't fix the issue but it'll look nicer
I think like 26 is wrong
Set height to EditorGUIUtility.SingleLineHeight
It looks the same.. weird EditorGUIUtility.standardVerticalSpacing is actually = 2
Line 26 is fine tho.. it's just the height of the foldout
It's the height of the foldout plus all it's children
The last bool parameter (include children) doesn't changes anything
This is how it looks without my PropertyDrawer
I only need it to detect if something has changed lol 🤦♂️
Detect whether anything has changed?
Or detect whether a specific thing has changed
Anything.. ColorScheme is a serializable class that I'm using in a ScriptableObject. two instances for dark and light..
I'd just make a custom editor for your ScriptableObject then that just calls EditorGUILayout.PropertyField
Way easier
I draw that SO (called Theme) in a settings provider but I want to detect if any color has changed (not the foldout lol) regardless of where it shows up (settings or inspector)
GUI.changed is true even if the foldout toggle is changed.. so it isn't good
Ah
Yea I tried that but it doesn't detect changes within ColorScheme..
With that PropertyDrawer workaround looks like only the properties that have a HeaderAttribute are pushed down
I mean you can try to see if it has the wrong height for that property
But I doubt it
Because it shouldn't be any different from how Unity draws it
Do me a favor and replace line 37 with
rect.y += rect.height;
rect.height = height;
oh I just did that lol
Yea it was it
🤦♂️
I suddenly understood what you said earlier.. I feel stupid now 😅 thanks! looks awesome now
Thanks, will do!
Final code. we work so hard to make it looks like we didn't do anything lol
does onscenegui work as an update
apparently it does
I want the function of Handles.PositionHandle but with a different visual indicator than this
the green red and blue lines are too noisy
anyone know what I should do, or at least what I should look up
I don't think Handles.color affects it. So you would need to recreate it using the Handles.ArrowHandleCap (I think that is what it was called at least), and use Handles.color to set the color.
oh, sorry, i didn't clarify that I want to get rid of the arrows and just use like a dot to drag a point in the editor like how cinemachine has those dragable dots in the track
@gloomy chasm
Oh, that is is a Handles.FreeMove iirc
Cool i'll try it out
@gloomy chasm Awesome it's perfect
sucks that this https://docs.unity3d.com/ScriptReference/EventType.Repaint.html
has no documentation tho
What do you need to know about it?
i wanna just draw like a circle sprite, instead of using the sphere handle cap
which would require a custom handlecap function
and theres no documentation on how to do that
I'll just ignore it tho and use the ugly spheres lol
Basically all the handle cap functions are, are GL calls
is there any callback for when we're in the middle of dragging scene objects in hierarchy?
Aight, testing it.. I'll be back 🫡
how do I make these unfoldable lists respect EditorGUI.indentLevel? it doesn't work on them (e.g. fields on the above are indentLevel 1)🤔
actually ok I'm dumb there, I use this code:
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.indentLevel = ((IndentAttribute)attribute).indent;
EditorGUI.PropertyField(position, property, label);
EditorGUI.indentLevel = 0;
}
but lists/arrays are obviously not properties🙃 (yes?...)
is there any simple and possible free extension that convert ContextMenu(..) to Button in the editor? or even use a different attribute so you can specify other things? 😅
Hey. I'm writing a PropertyDrawer. It works for the case that the type is not used as an array. But when the type is used as an array, the drawer renders outside of the assigned array space
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUILayout.LabelField(label);
}
When I use EditorGui.LabelField(position, label) it works, but I need other components of EditorGuiLayout
You cannot use Layout methods inside of a PropertyDrawer
Nice, looks like they added the last of the things that were missing to make it fully customizable! 😄
So I can only use EditorGui?
Only EditorGUI and GUI
God damn, Unity UI is such a mess...
Thank you
Sure, what were you needing from the layout method?
Need the DropdownButton, but there is also one in EditorGUI as I just noticed. Would just be nice to not calculate all the positions manually.
Ahh, yeah it is a bit annoying. But makes sense once you understand how it all works
Thank you anyway
In a PropertyDrawer I want to display a HelpBox under certain conditions. That means that my Property draws in different heights.
How would I properly do that? As I need to feed the height with float GetPropertyHeight(SerializedProperty property, GUIContent label) which seems to get called before OnGui. And the HelpBox has different size depending on the content and the width of the Inspector window. Thus I would need to get the height of the TextBox before I know what is needed.
I would create a elements I need beforehand in float GetPropertyHeight(...) but I'm not allowed to store them as member of the Drawer.
In Addition, how would I get the size of EditorGUI.HelpBox(...)? That function just draws the element, I don't event get a Handle to the Element to do something with it
GetPropertyHeight is called before OnGUI, but they both get called 'every' frame.
You can use EditorStyles.helpBox to get the style, and you can calculate the height from that. Sadly the only real way to get the width is to use EditorGUIUtility.currentViewWidth.
This isn't really something that was considered (or was and ignored) when they designed the PropertyDrawer system. It is what it is.
At least UIToolkit is much better with this sort of thing.
What other Options would i have to the PropertyDrawer? I only want to change the rendering for that single Type, I don't want to write an Editor for the entire outer class, which would also mean that the Type would not work when used somewhere else.
EditorGuiLayout was working properly with the dynamic height, until I failed with the array stuff. Now I wrote a Wrapper for Rect to easier align the elements for EditorGUI and now it fails at the dynamic height...
I have a basic question..
Is it a good practice to let serializable classes to inherit from UnityEngine.Object? just to deal with it as a serialized property..
For example, let's say we have a mono behavior class called "MyClass", within it we have serializable inner class called "Data" and within MyClass we have a few "Data" fields
I would say you should only inherit from UnityEngine.Object if you intend to store that object either in the scene or as an asset, since it now has a lifetime dependent on those
so if the data is solely the responsibility of your monobehavior, then you should definitely not have fields that are UnityEngine.Object, unless you want those to be assigned assets from your assets folder, or similar
I tend to have several nested serialized C# types (non-UnityEngine.Objects) in my scripts
uh ping @shell beacon, just in case 
I don't think you can inherit directly from UnityEngine.Object even.
If memory serves it requires a C++ counterpart.
oh, in my case I'm assuming by "inherit from UnityEngine.Object" to mean "inherit from any type inheriting from UnityEngine.Object", which usually means ScriptableObject
Oh, yeah I wasn't quite sure which way it was intended.
Oh I meant directly from UnityEngine.Object lol
So we can't? I assumed we can
But yeah, just have plain old C# class and structs that are Serializable unless you have a benefit for using ScriptableObjects.
No can do. ScriptableObject would fill that role. But you really only use that if you are using it as an asset. Or in editor, need the data to be standalone and persist between domain reloads.
you can inherit from ScriptableObject, but I'm not sure why you would want to right now since it sounds like you haven't done it before haha
regular ol C# types serialize just fine as long as you mark the type as [Serializable] and use serializable types within the fields, and mark them with [SerializeField] in case they're not public but should be serialized
What was your thinking/reasoning @shell beacon for wanting to inherit from UnityEngine.Object instead?
But you need to create a serialized object for them to let the editor "do stuff" for you.. no?
now I'm not sure what you mean. you don't need a serialized object in order to do things in the editor
but I guess it depends on what you mean by "do stuff"
When I'm dealing with serialized properties I often get stuck when I need a field that isn't derived from UnityEngine.Object so I thought why not make it inherit from that lol
serializedProperty.FindRelativeProperty()?
yes
oh is this specifically for drawing the GUI of a serialized field?
I don't think I am following 😅
Can you give an example?
Yes 🙂
Yes I have something open..
then usually if you want to do something fancy you would make a PropertyDrawer for your type
I need that object value lol
Oh I wanna skip drawers lol I'm a bit lazy 🤣
This... doesn't really clear much up for me sorry haha
Well.. there isn't any issue there but lets assume isDefaultProperty is not a boolean but a serializable class
generally you probably shouldn't use that directly, but instead use FindPropertyRelative(), but you could also use .boxedValue https://docs.unity3d.com/2022.2/Documentation/ScriptReference/SerializedProperty-boxedValue.html
Then you do isDefaultProperty.FindRelativeProperty("myBool")
But also, you shouldn't use .boxedValue unless you actually know what you are doing.
yeah, like I said you probably shouldn't use it directly
I'm not familiar with that! I'll take a look
yeah, just making sure it is clear. Great API and so glad they added it! So easy to abuse though, especially for new people haha
Hint, your use is not the correct use for it (at least I am like 98% sure) 😛
how do I make custom icons/gizmos for scripts not look like trashgarbage? and yes I have bilinear mip filtering on, as you can see the scene view version looks fine
do I have to set up like a custom icon drawer script to retreive the correct version based on DPI and and and and 
You're probably right 😅
two things, iirc the icons used are either 16x16 or 32x32 . The other thing is that if you are using vectors to create them and then export. The vectors need to be on the pixels if that makes sense.
Yeah it is 16x16 for the component icons
they're not 16x16 in the scene view though
so clearly there's some support for scaling that shouldn't use point filtering in Unity's own components
I think that is the @2x alternative that you are seeing
it's possible yeah, but, is there a way to implement that? I don't see any way to pick different icons for scene view vs component 1x vs component 2x
I know that's how the GUI icons work, but I don't know how to add it to my custom script components
I think it looks at the file path for the assigned icon and checks for an texture with the correct name. It has been a bit since I did custom icons for a component though, so...
hm, I can only find the name rules for, a general icon, not the scene view/gizmo or the 2x variants
I can experiment I suppose
I just don't understand why the component UI icon is point filtered 
Also if you are in 2021, looks like there is a [Icon] attribute you add to the MonoBehaviour.
hmm, project relative path sounds, scary
Packages
(it's for a plugin, so, users could theoretically put it anywhere)
me: oh Ill do something relaxing, like adding cute lil icons to my plugin 
unity:

Works on my machine
These are the settings that Unity's Spline package uses and seems to work for me
Not quite sure about the scene icon
that works for only the 16x16 case though
but then the scene view and the high-DPI monitor variants look bad
Not sure about the sceneview yet. But it should automatically use the high DPI variant if it is using the correct suffix
the high DPI variant is separate from the scene view icon
Yeah, seems so
I would take a look at the Splines package or the new Cinemachine 3.0 package and see if you can see how they handle the SceneView.
It really is sad how much of a undocumented pain it is to add icons to components. They make components so much nicer and polished
This sort of has some good info https://www.foundations.unity.com/fundamentals/iconography#Icon-Types-Sizes
hmmyeah, still not sure how to make unity use them for custom components though
You mean the gizmos?
yeah, well, the gizmos and the icons
fine if I was making a custom UI, but this is Unity's UI
I have implemented a DrawIf functionality using an attribute that disables a field in the inspector if a condition is false. My problem is that I would like to apply it to a class that already has a property drawer to display it nicely, but unfortunately it doesn't work as expected. The property drawer for DrawIf seems to override or interfere with the existing property drawer in a way that I don't understand.
public TypeReference<int> type;
[DrawIf(nameof(greatNumber), 6, DisablingType.ReadOnly, ComparisonOperator.GreaterThanOrEqual)]
public TypeReference<int> type;
For now i use
EditorGUI.PropertyField(position, property, label, true);
to draw the property field from DrawIf
how can I use serializedObject.FindProperty on a List?
for example if I want to find stuff at myList[i]
ah I see now.. we must contain it in SerializedObject first then iterate over it
yes, I made it to work already, thanks 👍
Hey people, I get the following errors when I try to install the "Netcode for GameObjects" package, anyone know what should I do about it ? is it a problem with my connection or is it something I need to do ?
[Package Manager Window] Cannot perform upm operation: Unable to add package [com.unity.netcode.gameobjects@1.4.0]: One or more dependencies could not be added to the local file system: com.unity.burst: aborted [NotFound]. UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
[Package Manager Window] Error adding package: com.unity.netcode.gameobjects@1.4.0. UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
the first error asks for the "Burst" compiler package as a dependency, when I tried to install that separately it gave me an error as well,
I deleted the "packages-lock.json" and "manifest" files and reseted my packages to default from the "help" tab and it didnt help.
any other suggestions would be helpful.
There is a SerializedObject how to I made that is pinned if you're ever stuck with them
well noted, thanks 👍
I have this specific case where I made a custom inspector then I also want to mirror/show it to custom Editor window via InspectorElement in uitk..
So how should i go about hiding the inspector one(not shown in the inspector) but I want to just display it in my custom editor window
This what I came up with, it works, but as you see it's ugly and can go south pretty easily
public override VisualElement CreateInspectorGUI()
{
rootHost = new VisualElement();
try
{
return rootHost;
}
finally
{
rootHost.schedule.Execute(()=>
{
if(rootHost.parent.name != "hostInput")
{
rootHost.RemoveFromHierarchy();
}
}).ExecuteLater(16);
}
}
note : "hostInput" is my custom editor container
oh wait, it removes whats shown in my custom editor too.. lmao.. I mean, its via inspectorelement so that's kinda expected lol
oh! hideflags did the job!
it's hidden in inspector but shown in my inspectorElement ✨ 🤘
How can I put a drop-down selection menu in an EditorWindow? (Similar to an enum selector in the inspector)
can't find anything like it in the UI Builder
Interesting, that's not there on my version (2020)
I'm currently in the process of porting to 2022 so that might fix it
I have a small problem where Undo/Redo operaions in my custom tool takes some time to execute. Whenever something changes in my data I use Undo.RegisterCompleteObjectUndo, because there is quite a lot of things that can change at once.
Now, I need some clarification on how Undo.RecordObject works couse im not sure. As I understand it records only a single change, right? So I assume it is the first change made to the object after invoking this method, correct?
and this undo operation then stores only info about a single property change and not about whole object? or not?
because I wonder if instead of doing this:
private void OnChangesMade(){
Undo.RegisterCompleteObjectUndo(myObject, "change")
//Apply all the changes
}
making it like so:
private void OnChangesMade(){
Undo.CreateGroup() //dont remember proper invokation, but its not important
foreach(var change in changes)
{
Undo.RecordObject()
//Apply Single Change
}
Undo.CollapseUndo()
}
will result in faster Undo/Redo
obv this operation would look different, but you get the point. I would like to know if this will work faster before trying to implement it, couse in reality It will be much more coding :/
Make sure that the UXML document is set to be for editor authering
Sorry for necroing.. 'm also interested in this whole undo/redo thingy... whats the difference tho between RecoordObject vs RegisterCompleteObject?
simply saying RecordObject stores info only about a single change, and RegisterComplete will create a copy of full object to compare the changes made
but I dont know how the real nooks and crannies of it work
@glad cliff @peak bloom so (per the docs) RecordObject creates a copy of the object, and at the end of the frame does a diff to see what properties changed. RegisterCompleteObjectUndo stores a complete copy of the object that it restores.
thus I wonder if doing multiple RecordObject will result in faster Undo operations than REgisterComplete
If you can help it, using SerializedObject is far better for modifying properties in the editor than Undo
putting it in these words it seems the same XD both create copy of entire object XD
The difference is that for RecordObject the diff is stored, but for RegisterCompleteObjectUndo, a full object copy is stored.
ah I see
ohh so you mean it does not create AND SAVE the copy, but rather create copy and the only thing that is remembered is a difference? (with RecordObject)
Yup
right roght!