#↕️┃editor-extensions
1 messages · Page 107 of 1
if I consume the event then any of the Position, Rotation, Scale fields don't get it either
public void DoGUI()
{
ConsumeEvent(); // Consume the event when Red's rect is clicked with event.Use().
DrawRedArea(); --->I want this to NOT receive the click event
RestoreEvent(); // Restore the event to the original state (type, button, etc).
DrawPosRotScale(); ---> I want this to receive the click event
}
i've tried this and every other possible order on the event handling, nothing seems to work
it's either consumed for all or click for all
any idea on how I could approach this?
It has to do with the rect passed to EditorGUI.BeingProperty
the rect I pass to draw the actual object field is just the green rect
oh wait, let me test one thing, I think you may be right
Should do, it is called in EndProperty
i see i see
my original design is to have a PropertyDrawerBase class that encapsules all of its derived classes GUI stuff in a property scope
public abstract void DoGUI(Rect position, SerializedProperty property, GUIContent label);
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
using (new EditorGUI.PropertyScope(position, label, property))
{
DoGUI(position, property, label);
}
}
i did this to automatically handle multi-object editing and stuff like that
but now I guess I'll have to change it
to avoid the issue with the context menus
DrawRedArea - does this part actually deal with any events or is it just the "drawing"? The reason why I wonder is because you might be able to do something like:
public void DoGUI(Rect rect)
{
DrawRedArea();
DrawPosRotScale();
ConsumeEventIfContextClickInRect(rect);
}
well in my particular case the problem wasn't the events it was the Begin/EndProperty that internally handles them differently
that's why I was so confused
doing something like this works properly
GUILayout.Button()
Event.current.Use()
GUILayout.Button()
the second button won't receive the event because i use it halfway
but the Begin/EndProperty was messing me up with the context menu
because what I was doing was essentially this:
BeginProperty
some GUI control
Event.current.Use()
some GUI control
EndProperty
I might have misunderstood then. It's getting late here, but I got the impression the issue was that EndProperty triggers the context menu which you didn't want 🙂
yeah the issue was the Begin/EndProperty was using a big rect that was overlapping with the rects of othe controls
so I had to instead handle the begin/end differently
i was wrapping my entire thing in a begin/end to handle everything by default
so I just refactored my code to only use it where it's actually needed
triggers the context menu which you didn't want
yeah pretty much
the right click was triggering an ObjectField's context menu for the entire property because the original field is an object reference
I just ended up not using BeginPropert/EndProperty in this particular case
because i am manually drawing an object field, it gets the same context menu when the click actually happens in the rect
Ah! ok I see then 🙂
Need to go to sleep here, but glad you figured it out then 🙂
thank god for MechWarrior, this thing would have taken me hours to debug lol
I'm getting an annoying custom editor error ArgumentException: Getting control 1's position in a group with only 1 controls when doing repaint, that I think should be easy to fix, but I'm not super capable with editors.. 😛
Line 112 it says.. seeing anything wrong here?
There are multiple results on google for that specific error message - for instance:
https://answers.unity.com/questions/17718/argumentexception-getting-control-2s-position-in-a.html
You can read about IMGUI here:
https://blog.unity.com/technology/going-deep-with-imgui-and-editor-customization
You need to make sure that you don't change the order/amount of controls between events. If you need to do so, you should use:
https://docs.unity3d.com/ScriptReference/GUIUtility.ExitGUI.html
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
Thanks, I googled a bit but didn't find anything that solved it for me, or that i understood. But I'll have a closer look at the links you suggested! 🙂
You get this error a lot if you have lists that change or conditional UI code (show/hide button depending on some expression etc). Just make sure you use ExitGUI when you do something that will change the layout of your GUI code - and you should read up on how events work in IMGUI. It will save you a lot of headaches in the long run (I can tell you that from experience 😛 )
Oh ok, yeah the problem is someone else made the editor for me before, and he's unavailable now. 🙂 Let me know if you're available for (paid)consulting. 🙂
Oh wait iirc there's a style somewhere
Hmm, this post https://www.reddit.com/r/Unity3D/comments/8ys8d1/help_showing_a_texture_field_in_a_custom_inspector/ implies that if you give it enough vertical space it'll show the preview
2 votes and 2 comments so far on Reddit
EditorGUILayout.PropertyField(textureProp);
EditorGUILayout.ObjectField(textureProp, typeof(Texture2D));
textureProp.objectReferenceValue = EditorGUILayout.ObjectField(new GUIContent("Texture"), textureProp.objectReferenceValue, typeof(Texture2D), true);
Results in:
What is textureProp.objectReferenceValue meant to represent?
Maybe I should clarify: I'm making an inspector for a scriptable object
I want this field to set the SO's UITexture property
It's a SerializedProperty: var textureProp = serializedObject.FindProperty("_texture"); - just some quick code to show the difference between the default property field and using the ObjectField 🙂
Now I have this for the start of the script
I tried to replace things in your code with the equivalent
But it says it can't implicitly cast from Object to Texture2D
Should I just cast it?
I just did that, and the inspector looks like it should now
Remember that when you set the source.UITexture like that it won't mark the object as dirty/save properly and you won't have Undo/Redo. This is (mostly) all fixed by using SerializedObject and SerializedProperty.
Maybe I'm just overcomplicating this and a custom inspector isn't really necessary for this.
Because now I tried to add a button to save a prefab variant
The console says it doesn't work because a parameter "root" is null.
https://docs.unity3d.com/ScriptReference/Resources.Load.html
Only works with resources in the resource folder. You're trying to load an asset outside of the Resources folder.
If you want to load an asset, you might want to look into:
https://docs.unity3d.com/ScriptReference/AssetDatabase.LoadAssetAtPath.html
But.. it seems like you're only trying to clone the base prefab?
Yeah, but as a variant of the base prefab.
This made it successfully create the asset
But it also instantiated the base prefab in the active scene, which I don't want.
Do I just have to destroy the instantiated prefab afterwards?
just skip the instantiate I guess (since the AssetDatabase.LoadAssetAtPath gives you the object you want)
I see.
I was just following a forum post, but if that works...
Wait, it just gives "Can't save persistent object as a Prefab asset"
This is my current code
ah.. ok.. then you have to instantiate it with PrefabUtility. .wasn't sure about that one
And then destroy it?
Yup
Anyway - need to get back to work 🙂 - ttyl
Thanks
Remember to update the serialized object first
serializedObject.Update();
// <----- Custom editor code here
serializedObject.ApplyModifiedProperties();
i was trying to make a custom editor but i soon realized the changes get reset on play. any ideas how to fix this? custom editor : http://pastie.org/p/2es66U3MYHp7BxVBF4Xwjf
the code the custom editor is "trying" to affect : http://pastie.org/p/2eJCDiIJA13t8Qsqqqsd5g
You're just selecting [SerializeField] public NPC_Bodypart.bodyPartType selectedType; in the editor, and not writing it in the actual NPC_Bodypart
yes someone told me that just a moment ago, can you tell me how to change it?
@surreal kindle
var selectedTypeProp = serializedObject.FindProperty("currentselectedType");
EditorGUILayout.PropertyField(selectedTypeProp);
var selectedType = (NPC_Bodypart.bodyPartType)selectedTypeProp.intValue;
Those are basically the things you need to put it together.. you need to get the property from the object (currently you're getting it from the editor), and then check based on the value written.
gtg
thx
Is there a way to disable the component inspector dropdown like in the case of the Audio Listener? I haven't found any questions or documentation on it.
Right now, I just have my custom inspector render nothing at all, which gets the job done quite nicely, but I'd still like to remove the dropdown button on the left of the component header.
How would I refactor this to use SerializedObject and SerializedProperty?
Create a custom editor and override OnInspectorGUI() and have nothing there. I think that's all you gotta do.
No. That still leaves the dropdown button.
As I've said below, I already have an empty component inspector. I just want the dropdown button gone
Oh, sorry I didn't read that part.
I would suggest reading a tutorial to get the hang of it, and see if you can make it work on your own.
Something like this? It's for a PropertyDrawer, but the same principles apply.
https://catlikecoding.com/unity/tutorials/editor/custom-data/
Good idea.
yes, there's an IMGUI control for drawing inspector Titlebars that lets you select to have a foldout button or not
and there's an undocumented method on the Editor class to make your custom header
one sec, gonna look for the example, I have one somewhere in my test project
Thanks a lot! I've taken a look at OnHeaderGUI in the past, but it didn't seem to do it
You know what's interesting is it seems that AudioListener doesn't have a custom editor 🤔
never really looked into the default editors of Unity
I just recently started digging because I'm making a PropertyDrawer for nested components! 😅
haven't got to AudioListener yet, but that's a good note to keep in mind
Yeah, some things just seem to be obfuscated for no reason
I went to look for julcreutz to see how they did it internally, but I simply can't find one. Must be doing something on the C++ side or have a special case in the base inspector code to handle it
hmm maybe
It seems to be that way. I've seen very specific usages of type checks in the Unity source code.
I am trying to implement drag and drop functionality for an array of custom classes, the same way you can with normal arrays. I found some code for it that would og inside of a property drawer, but it only detects mouseover on the individual array items. Is there somewhere else I should be putting this?
Custom inspector title bar
Are you wanting to draw an array like the built-in list/array is drawn? If so you can use ReorderableList to do it
Ok, I will look into that
how can I perform a key press through code?
in an editorwindow I need to perform a Tab press twice when something happens
is there a way of doing this?
Ehh, I question why you need to send specifically two Tab presses, but you want window.SendEvent(..)
just experimenting heh 😅
ah right! i had forgotten about SendEvent
thx! 🙏
Still suspicious... 🤨
Tab, shift, alt, all those modifiers are special events
I don't think tab is
Depending on what you want exactly, I wouldn't be surprise if it doesn't do what you are expecting
i have some tools that relied on setting hotControl and keyboardControl through code based on the last controlID and stuff like that and it resulted in some weird behaviours
just exploring what possible solutions there's to that
so I'm gonna try manually sending duplicated Tab and Shift+Tab events for getting the "correct" navigation through controls
Sending Tab manually bypasses the global tab where the focus is given to the next element in queue (a control, a window)
if it is good for you, good good
if it is not, there is the OS input that you can trigger (Windows only)
hmmm I see, i'll keep that in mind
I'm stumped as to how to use serialized object/property for this inspector
This is what I have now, but there's all these errors
All of the "cannot convert" kind
You probably just want propertyfield instead of Objectfield
Also, that cannot convert error is because the parameters you're passing are in the wrong order/type
i.e. texture is a serializedproperty and not a Texture2D/Object
I see
You don't have to create your own serializedobject from the target. The Editor base class already does that for you 🙂
Here's a quick and dirty example. The reason for the object field is to automagically get the "texture preview box". This example shows three different ways of doing the same thing, and the result of doing it in those three different ways.
ResourceType: https://pastebin.com/ZUDsXP6x
ResourceTypeEditor: https://pastebin.com/tNQDaSjq
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
No worries - glad to help 🙂
..aand now back to updating the localization sheet for our project 😴
Does anyone know if it's possible to sign into your Unity ID via an editor script? Is there an API for Unity Services like that?
IIRC you can download a license file and import that through the commandline
where are the Unity preferences stored?
for example these colors
are they stored somewhere in a folder like the Project Settings?
i'm learning how to use SettingsProviders and I want to follow Unit's scheme for storing settings and preferences
Preferences are not stored in the project. https://docs.unity3d.com/ScriptReference/EditorPrefs.html
for example
hmmmm
i can find some of the preferences in the EditorPrefs
but the naming is so all over the place
and I can't find any of the colors for example
My screenshot contains some colours
ah right
i was trying to find them under "Colors/"
but they are each under "Animation/", "Scene/" etc
damn, I really wish they had put all of these settings in files like they did with the ProjectSettings
it's a nightmare to deal with EditorPrefs
Yeah, I don't know why they choose to use the registry over files in appdata
How long have constructors of ScriptableObjects been called for...?
I could have sworn that they weren't called...
I guess it is just one of those things that I 'learned' when starting out since you don't use constructors for creating them, and thus can't have parameters, maybe I 'learned' that you simply can't have constructors at all
is it safe to create folders under my project?
I refuse to follow Unity's convention of storing "Preferences" settings in EditorPrefs
can I just make a Preferences folder in my project? next to the Library, ProjectSettings, etc folders?
i'm scared of Unity suddenly exploding and corrupting my entire project or something... 💀
Sure can, however it will be included in your version control system. So I think you use the UserSettings folder. Also don't forget about the FilePath attribute for the ScriptableSingleton for saving prefs
If they're in your project they're not preferences, they're project settings
ah right i'm dumb
Windows: C:/Users/[username]/AppData/Roaming/Unity/Editor-5.x/Preferences/
@visual stag can you sanity check me here. It is fine to create folders in the root project folder right?
Of course
it's weird that they have the UserSettings folder anyways... they store QuickSearch settings there, which are supposed to be per-user...
they also store some ShaderGraph settings in there
Well I am glad they do because I think I am going to start using it for my asset
found this in the forum
Yeah we moved Library/EditorUserSettings.asset into this new folder.
The reason being, that Library should contain only imported/cached data that can be completely reconstructed from the project. People delete their Library folders all the time, etc.
But, parts of editor settings were in Library/EditorUserSettings.asset file (things like user's perforce connection settings etc.). So now it's in that new location. The folder should not be put into version control, since it's per-user things there.
See "Editor: Unity projects now have "UserSettings" top-level folder, EditorUserSettings.asset moved from Library there" in release notes, and mentions of the folder in
weird decision...
offloading the responsibility to the user, instead of just putting that into AppData or whatever folder the OS uses
i wish they were more consistent with this sort of thing
it's such a nightmare
like I was just trying to get the TimeLine settings from the EditorPrefs, but guess what
they store them in the AppData folder, all neat and tidy in their own .asset file 🙃
and now I'm trying to find this one
but god knows where it's at
🤷 look at the C# source
the Enable Deprecated Nodes is in Editor Prefs, but the Shader Variant Limit isn't
yeah I guess that's gonna be more reliable than going fishing for the settings in random places
sigh
how do i make unity automatically randomize tile variants
lets say i have grassa- plain grass
grassb- grass with small blades
how can i get unity to leave a couple of those grassb's among grassa's
with 2d extras
or would i have to manually code it to do so
Wrong channel probably
whats a better channel?
Maybe #🖼️┃2d-tools or #💻┃code-beginner idk
Does anyone know what this error is? It won't let me Build.
Nevermind, figured it out 
is there any way to make serialized interface assignable through inspector?
[SerializeReference] private ISystem[] systems;
where systems are Monos
I want to be able to simply reference them through inspector
No, this is explicitly not supported
I'm curious, what do editor scripting magicians here do when it comes to coloring IMGUI controls?
it has been always painful to apply the intended colors because they always get multiplied by whatever transparency the background texture has
and some controls are just straight up grayscale only (i assume due to some internal stuff in their rendering)
i have always kinda tweaked the color back and forth by some multiplier value to get a "good" result
but it's just annoying
Oh, you mean like GUI.contentColor?
yeye
for example to get a pure red color on the "Box" style i need to multiply by a value of around 3.8
i know the "correct" solution is to probably make my own versions of those styles with the actual texture modified externally in Photoshop or whatever
but... ouch
there's hundreds of default styles
I rarely do tbh. But when I do I never multiply it or anything.
In this case, just do EditorGUI.DrawRect(..)
I feel there are very few situations where you should be changing the color tbh
DrawRect works fine for some basic usage
but sometimes I want to make use of the nice round and cool textures the default styles use
just doing squares and rectangles looks kinda rough sometimes
i do a lot of color changes for custom IMGUI stuff
but it's just annoying designing everything to look neat and then spending 20 minutes tweaking some multiplier in code to get the actual IMGUI color to match my design
I would say it depends. If you are doing 'backgrounds' then you most likely should create the textures for it (please don't do colored backgrounds though, it ever looks good imo)
UITK is perfect for this stuff btw 😉
i keep backgrounds mostly grayscale, i mostly colorize borders and text
this is probably just me swimming against the tide of IMGUI
i'm halfway into making a tool to "bruteforce" every style's texture
iterating through every possible multiplier value and reading screen pixels to get the closest color match and then storing that in a file so I can use it later
it's not ideal, since the color is gonna be mostly dependent on the color of what's behind (usually an EditorWindow's main background color)
@gloomy chasm does IMGUI UITK handle coloring with "actual colors"?
or does it do a similar thing to IMGUI where the textures feel more like they are "tinted" rather than colorized?
You mean UITK?
whoops, yes, typo 😅
It doesn't use textures for basically anything besides icons (though it can)
You can do something like button.style.backgroundColor = Color.red to make the background of a button red, and it would be the color you set, not a tint
Just do it, bite the bullet
I have been bugging you for months! You can use a uss file to change the style. That means change the background color, padding, margin , border width and color, layout direction, flex type, etc. etc. all 'instantly' without any need to recompile scripts.
It makes doing styling iteration insanely fast (compared to IMGUI)
@gloomy chasm i'm slowly dipping my toes into the UITK waters from time to time
but for now I can't just migrate all of my in-progress tools to UITK
Sure you can!
100% seems like it's way better for the actual design workflow
i'll get there slowly
If ya got any questions feel free to @ me! 😄
sure thing! 💙 🙏
well for now i'm back to sticks and stones with IMGUI
scurries away into the darkness
Unrelated, but I feel clever since I figured out how to get separate undo performed and redo performed events
https://gist.github.com/MechWarrior99/47a361fbc04653646874bba8ce2a7868
oh that's pretty nice
i usually just read a global key event and got the key modifers from there
with the
UnityEditor.EditorApplication.globalEventHandler
I also figured out how to get what object(s) were undone/redone, though it isn't there
Just curios, is it possible to force the Package Manager to do stuff by a custom editor script? Im wondering if I can cause it to basically "queue" installing/removing several packages at once
this can be useful
@gloomy chasm take this https://gist.github.com/pointcache/70cfa9af62030d1b6296980514023d13
Nice and clean!
we have an issue with editor generated stuff spazzing out on undo, going to use your solution to solve it
Oh? What sort of editor generated stuff and what sort of spazzing out? Also glad to hear that it will be able to help!
meshes with hideflags dont update properly
ignored it until now since its not a deal breaker
Ah
When I call DeleteAsset the reference becomes null. How can I delete the serialized file and retain the C# representation (in the same way you can create an SO and then create an asset)?
I don't think you can, creating a copy is the easiest
Thank you for this! In other engined I've used have back (and forward) buttons. I've really missed this functionality in unity. Hoping this will give me some similar functionality (or at least a good point to go from)
@waxen sandal oh no it doesn't work because it changes the UUID!
God damn it
It breaks all the references
I wonder if there's a way to cheekily set the instance ID
static void SetInstanceId(Object o, int id) {
var field = typeof(Object).GetField("m_InstanceID", BindingFlags.NonPublic | BindingFlags.Instance);
field.SetValue(o, id);
}
Is there a way to draw IMGUI stuff outside of an EditorWindow?
can't find anything online that works. I've seen people doing stuff with GUI.BeginClip and Matrices but doesn't work for me
any way to for example, draw a rectangle on the position of the mouse?
You make an editor window at the position of the mouse
is there a way of making the background of the EditorWindow transparent?
I think someone here did it before but I don't remember how
There's always the, create a screenshot and align it properly method
I haven't tried it, but there is a SetAlpha(float alpha) on ContainerWindow
But that is more for the whole window I guess
@gloomy chasm thanks for the pointer, I'll look that one up
if I can make the whole window transparent and still render the IMGUI stuff inside of it that'll work fine
I think it will make the whole think transparent. But let me know what it does!
sure thing, will report back later with my findings 👍
right now i'm having dinner and watching Jurassic Park 🦖
Yes, I did on Windows
But the big drawback is that you can draw only once
The window freezes after that, never been able to work around that issue
@onyx harness oh, what approach did you use for that?
user32.dll
2 components have custom gizmo icons, can i display them both at once, with a hack of some sort?
ah lol theres Gizmos.DrawIcon
I tried to make an editor window with a setter for one of the variables. It made Unity crash
Either your project is corrupted or the thing you were setting is resulting in a loop or something.
Share the code?
I was dumb and deleted it, but was something like:
private string find
{
get => return find;
set
{
find = value;
Search();
}
}
(Search was a method in the same class. I tried having only debug stuff and I tried having it empty, but same result. Unity closed as soon as I opened the window)
Where you perhaps setting/getting itself?
That is what that code does
yeah stack overflow
What do you mean?
private string find
{
get => return find;
}
==
private string find(){
return find();
}
which results in stack overflow
What point said. Also, mentally walk through the code, what happens when get => return find; runs?
Wait, you’re right
It calls the get function, which just calls the get function
That’s probably the issue
same with set in your code
Unrelated, but I have learned today that the Undo system counts selection changes differently than object changes.
The main way it is different is that changing selection doesn't clear the redo list.
I was following this video
https://youtu.be/FObIXskxLWk (3:05)
Learning C# can be daunting, as with any new skill, But I'm here to help.
It's okay to be a noob. We were all noobs at one stage. In these mini installments I'll be going over some very basic concepts and code practices to help you on your way.
❤️ Become a Tarobro on Patreon: https://www.patreon.com/tarodev
=========
🔔 SUBSCRIBE: https://bi...
I see now that I wrote the getter wrong
And the setter
Walk through the code, the setter is calling the setter
That makes sense. I knew that was the problem somehow, but I overlooked the difference from the video
most of the time a property is a public interface for a field
If I’ve got this right, a property is basically the public-facing variable that hides the one used within the class?
yes, 99.9% of the time
Alright, thanks
I'm looking to replace Unity's ColorPicker, and I was wondering if I could generally replace the property drawer for Colors or something in that vein. Does anybody have an idea for that?
probably not achievable without code injection
if the relevant code is on managed side
I'm fine with code injection if it gets me there
Actually, the ColorPicker class does something interesting, and uses Resources.FindObjectsOfTypeAll(typeof(ColorPicker))
probably because its an editor window
But I'm not sure how is that useful, given that ColorPicker is internal
Try creating a custom property drawer for Color and find out. If not you can use the EditorApplication.beingProperty and do a check if it is a color property
Yeah color picker is just an editor window. It is like 98% C# side of stuff
Ah, so that beginProperty hijacks al of the editors or something?
I made a PropertyDrawer to replace the default ObjectPicker
I assume it's doable too with the ColorPicker
i didn't replace the default one in all instances of Object tho, i use a PropertyAttribute to manually do it
It is just called before any serialized property is drawn. But it has a rect of the field and GUI code will be draw
Yeah, I actually want to replace all of them, because most happen in places I cannot modify
That's actually an interesting idea
Yeah then you just create a rect where the little color picker button is and do a check for mouse down and use the event before the property gets it
Ok, so I can either do that or code injection, I assume
Any other potential ways to take into account?
lol legit
lol I know right, I saw something like that in some Unity code once and have used it several times since haha
some poor guy debugging editor code 10 years later
LOL
wow, i spend all the effort making a legit re-implementation of the picker field and everything
and you guys just hijack the button and draw over it
lmao
if it works, it works (tm)
Well you can't draw over it because the event is run first.
btw unity's imgui events still propagate bottom up?
i do this for mine ```cs
private void DrawControls(Rect position, GUIContent label)
{
GUIContent fieldContent = EditorGUIUtility.ObjectContent(_property.objectReferenceValue, _objectType);
EditorGUI.ObjectField(position, label, _property.objectReferenceValue, _objectType, false);
EditorGUIUtility.SetIconSize(new Vector2(12, 12));
_objectFieldID = (int)EditorGUIUtilityProxy.s_LastControlID;
if (e.type == EventType.Repaint)
{
if (_isDragging)
{
EditorStyles.objectField.Draw(_fieldRect, fieldContent, _hover, false, _on, false);
}
}
EditorGUIUtility.SetIconSize(Vector2.zero);
GUI.Button(_pickerButtonRect, "", GUI.skin.GetStyle("ObjectFieldButton"));
}
still needs polish, but for now works fine
Uhh, bottom up?
yeah if you have 3 buttons on top of each other, the one on the bottom will be the first to catch mouse event
at least on runtime
Uhh yes because its code is run first
that is not really an inherent problem of the imgui
its the problem with unity's shoddy impl
Is that not how it is supposed to be?
ofc not, the things drawn last have to be the first to test for events
like its done proper in dearimgui
people who use imgui for runtime have to struggle with those things
it can be great, like they can rewrite it, its not a big deal to refactor it for runtime, optimize, remove overhead of it just existing and so on
they most likely just used the same gtk they used for editor and cut on maintenance for standalone runtime version
@gloomy chasm by the way I tried the ContainerWindow's SetAlpha,SetBackgroundColor and they don't appear to work 😓
tried the SetInvisible method and it actually makes the window invisible, but it also does it for the contents... which may be useful in some cases
but yeah... seems like making tweaking an EditorWindow's background color/alpha is not possible
saw this in a comment in the source code
// We currently only support this on macOS
m_Window.SetAlpha(m_TargetAlpha);
so maybe transparency on EditorWindows only works in Mac? 🤷♀️
Do yall ever run in to a bug and think "Oh I need to fix this, but shouldn't take more than an hour or two" and then you are still working on it almost 2 days later...
Unity's Undo API is so lack luster...
lts build 22 - 15 known issues, build 28 - 30 known issues
@gloomy chasm I've tried looking for EditorApplication.beginProperty but there are no docs for it?
Umm, it might be internal
Right
Ok, it's way too late to start disassembling stuff, so I'll give it a go tomorrow, many thanks to everybody anyway 🙂
There is the C# source code on github btw (link in pinned messages)
Cool, will check that out, although I normally just use Rider's decompiler, it works a treat
is there any way to somehow mark object for usage with scripted importer apart from adding stuff to the path/source assets?
What do you mean "mark object for usage"?
so that its processed by custom importer
i.e. right click in unity editor -> import with ...
or maybe i could use asset labels?
2011
"should use", aha yes, thanks i "sure" will
genius, it works
anybody knows why my visualstudio doesn't highlights some unity classes?
#854851968446365696 has the configuration instructions
Is there a way to change the fbx exporter settings in code?
Cant find anything in the documentation
I need to export models as binary fbx but it does ASCII by default
https://docs.unity3d.com/Packages/com.unity.formats.fbx@2.0/manual/devguide.html?q=fbx
Using this plugin
https://gist.github.com/Dostac/e867e2fd921fab6bf373648b81ad192b
This is my code
Is there a reason you need binary? Just curious
I'm not sure if this is the right channel to ask but has anyone recently updated to 2020.3.29f1 and are using Newtonsoft.Json? How did you get the latest version installed in this new editor version if you did?
One of my assets does not recognize it as an import anymore after the update, so I thought to drag over my Newtonsoft.Json.dll file from my older editor version, but decided it might be available in the package manager but can't seem to find a valid place to import it to stay up on the latest versions of it.
I've also tried installing from my package manager the github location for Newtonsoft.Json but I get an error that no package manifest was found.
Nm, I found a section in the README that mentions to use a different URL to import into the package manager. All good.
This is a wonderful thing... back/forward buttons for the asset browser
Tested on 2020.3.23f and still does the trick 👍
hello fellow gamers...
I made this search script for the editor about a year ago..
At the end.. when I open the prefab you can see the Asterisk (save indicator) flickering
after some research my buddy pointed out:
In the SpawnSearchEditor.cs script which is in charge of setting the variables on the main SpawnSearch.cs gameObject
The Layer.. is a layermask I have on the actual SpawnSearch.cs but everything below that.. the Tags and the search buttons and verification messages are handled in the SpawnSearchEditor.cs
Now.. im trying to rack my brain to figure out why I had to use .SetDirty
any help or if u got questions or wanna see more of the scripting, @ me and let me know.. thanks for any help
How i do for download "Visual Studio Editor Package version 2.0.14 is available" in all new Projects? Without " windown - package manager" in every new project
sorry for my english and i so sorry if this canal dont its done for my problem
any ideas how to make custom editor script for terrain shader ?
Isn't it just the same as the shader/material editor?
that would be the top one
"Mat Terrain Adaptive"
its collapsed in the first image above
its using this thing from the looks of it
was wondering if there is a way to override it somehow
Oh, you mean for a terrain layer?
yes
Oh, you said terrain shader originally
sorry didn't mean that
Np, was just confused. I think you can just create a custom editor for it and it will override the other one?
so just a custom editor for the material as usual ?
You want it to show something different than the Diffuse/normal/mask maps etc?
How are you showing them right now?
Looks like you create a MaterialEditor like normal and implement ITerrainLayerCustomUI interface
awesome , thanks mate
Nice! And I learned something new too!
🙂
here is an implementation example :
public bool OnTerrainLayerGUI(TerrainLayer terrainLayer, Terrain terrain)
{
GUILayout.BeginVertical( EditorStyles.helpBox );
var terrainLayers = terrain.terrainData.terrainLayers;
var i = terrainLayers.ToList().IndexOf( terrainLayer );
var Dist2MinMax = terrain.materialTemplate.GetVector($"Layer{i}_Dist2MinMax");
EditorGUI.BeginChangeCheck();
Dist2MinMax = EditorGUILayout.Vector2Field( "Distance", Dist2MinMax );
if( EditorGUI.EndChangeCheck() )
{
terrain.materialTemplate.SetVector($"Layer{i}_Dist2MinMax" , Dist2MinMax );
}
GUILayout.EndVertical();
return true;
}
any ideas how to draw a texture using gui layout without serialized properties ?
draw the texture? or just do the ObjectField for a Texture2D type?
nvm i figured it out
_Splat = EditorGUILayout.ObjectField( "Texture" , _Splat, typeof(Texture2D), false) as Texture2D;
yeah you need to cast it to the type
was using a [deprecated] method
There's no need to use the safe cast over a normal (Texture2D) cast btw, as the field is already constrained so that you shouldn't be able to assign an incorrect type to it
Is there a way to create a GUIStyle not in OnGUI?
create or grab from an existing one?
I just use properties
I am using reflection to change a style in a Unity thing. So I need it to work on initialize
(Just messing around)
This sort of thing is always my setup
That is what I do too. But I want to basically change that with reflection 😛
i've never had any luck with that, I usually just do a flag on the first OnGUI loop and grab the style there
you could also create an asset with whatever GUIStyle you need
and use that instead
I'm not exactly sure where reflection is coming into it, I'm probably missing something
I am trying to change the HostView.Styles.background style
@gloomy chasm your problem is that whatever style you want to use is null at initialization time, right?
It says you can't use a named style without a skin set and to call it in onGUI instead
hm, never ran into that particular error before, but I do get all the time the "style is null" when I try to get them on constructors
There's probably a way to set the style before calling it, but I have honestly never had the need to try
Ehh, too much work anyway. I was just wanting to mess about with editor styling for fun haha
Wanted to see if I could get the editor to look more like those mockups
@gloomy chasm you can save the style you want to use to a ScriptableObject asset with a GUIStyle field and use that style instead of trying to get it from EditorStyles or whatever
at least I think I've done that in a couple of situations
can't remember exactly
They're trying to modify editor styles, not use a style
which is why it's complicated because they would like to not run their own GUI to do that
right but can't they just assign an entirely new style to Hostview background style? instead of just modifying it?
i might be misunderstanding
You can't even do new GUIStyle()
Idk, it is getting late for me and I don't care that much about it. I appreciate the help though!
Maybe, I suppose it depends how those resources are being recalled. Sometimes it can be very painful or impossible to inject that sort of change
yeah I guess it depends exactly on what the situation is
@gloomy chasm i tried changing the HostView.Styles.background style and the DockArea.Styles.background style
it seems to have no effect on how windows draw
Changing the HostView.Styles.paneOptions however does affect it
you can essentially disable the options button, it doesn't even get input if you change the style
so i guess the GUI for the background is handled different, maybe cached internally somewhere or something
maybe other steps are required such as manually triggering a reconstruction of the HostView, or ContainerWindow or something
but I don't know how safe that sort of stuff is, haven't dug that deep into the topic
and changing a static GUIStyle that is used internally in all visible windows doesn't sound like a great idea 😅
@patent pebble are you trying to draw gui into the window? Can you do what you need with OnGUI?
Hey all, I'm creating a custom editor which will allow me to quickly make xml configs for waves of enemies. What I'm currently attempting to do is get all the properties from the Wave struct and serialize it for the editor window to allow the user to input values for each section. Here's an image of what i've got so far but I'm not sure how I could then create an appropriate field of the correct type in which to pull the information back out of the editor window. I could hardcode it but ideally would love to be able to create something that will dynamically update as I inevitably add more into the Wave struct.
You should use SerializedObject and SerializedProperty
I see! if I'm understanding correctly this would look similar to the normal inspector? Similar to this attached image?
Yeah you can do that if you want
You could add an editor tool to import SOs from xml. Might be easier?
What do you need the XML for?
Trying to make my game as modular as possible, basically everything will be loaded from the xml's so it'll be super easy to customise externally.
Ended up using a SerializedObject to just expose the struct I needed to populate with information in custom editor window.
Hi everyone!
I have an error Internal build system error. Backend exited with code 2.. I don't know what to do...
nah we were messing around trying to change the default backgrounds of EditorWindows
I was trying specifically to make an EditorWindow transparent
Like see thru the editor window?
I was also trying to draw a texture outside of an EditorWindow
Yeah
That sound sticky if so. You have to find a way to hook indo the os's window rendering I should think 🤔
Though you could maybe try autohotkey for something like that. They have window transparency stuff but I can't say how robust it is
I dont think so, the engine itself is in charge of how EditorWindows are rendered to the screen, not the OS
Ah, kk nvm then. :) this might be of interest though for a simple hack https://www.autohotkey.com/board/topic/92855-window-transparency/
Window Transparency - posted in Scripts and Functions: Hey,
Heres a simple user friendly window transparency tool Ive made.
Press Win + T to activate.
Simply click on the Window you would like to change transparency of and then move the slider.
Ahk_L code:
#t::
WinGetActiveTitle, Title
Gui 10: +LastFound +AlwaysOnTop
GuiID:= WinE...
Totally untested for this situation though😜
Hi people, is there a way of doing something like [Header("")] in a custom editor ?
here's how my editor is currently, i wan't to make some kind of header to organize things better
[CustomEditor(typeof(HierarchySeparator))]
[CanEditMultipleObjects]
public class HierarchySeparatorEditor : Editor
{
[Header("Outline Settings")]
private SerializedProperty _outlineSize;
private SerializedProperty _outlineColor;
[Header("Bar Settings")]
private SerializedProperty _barColor;
private SerializedProperty _textColor;
public void OnEnable()
{
_outlineSize = serializedObject.FindProperty("m_OutlineSize");
_outlineColor = serializedObject.FindProperty("m_OutlineColor");
_barColor = serializedObject.FindProperty("m_BarColor");
_textColor = serializedObject.FindProperty("m_TextColor");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(_outlineSize);
EditorGUILayout.PropertyField(_outlineColor);
EditorGUILayout.PropertyField(_barColor);
EditorGUILayout.PropertyField(_textColor);
serializedObject.ApplyModifiedProperties();
}
}
GUILayout.Space(10);
GUILayout.Label("Some Header", EditorStyles.boldLabel);
ty
Can anyone point me to an example of an inspector array where each element contains it's own buttons & properties ... or how to add buttons to each array object.
write a custom inspector
Duh! I'm asking for any examples of a custom inspector what has an array, and each array item has it's own buttons and properties.
google is your friend
Again, not an answer. If I would have found an example on Google I would NOT BE ASKING HERE.
you can find how to create buttons, you can find how to access elements. it's your job then to put that knowledge to use and combine these elements
So , I guess this Discord is just a waste of my time. Ask for support because you can't find any reference to the codgin I'm trying to do and you get told to research it yourself ... Good job 😉
we did point you in the right direction and gave you a starting point
Really, I'm obviously writing a custome inspector and you tell me to "write a custom inspector" and then you tell me to Google what I'm looking for. You should get a job with Microsoft documenttation ... Technically accurate yet totally useless. Great Job!
Either provide some reference to this very specific type of inspector or say nothing at all as you obvilusly don't have any useful answers.
microsoft's documentation is really good and straight to the point. you can easily figure out what to do if you already know how to start.
i agree that providing those kind of answers isn't really helpful
it's better to do a follow up question asking the person to provide more context
@tulip mantle i'd also suggest you ask questions here in a more comprehensive manner
your question is a little bit generic and doesn't give too much to go on
+1 to that
telling someone who is stuck on a problem to "just google" isn't really helping 🤷♂️
and that is not what i did. i told them what to google and then to connect the findings
i'd try to at least provide them with useful terms or related searches so they have a little nudge in the right direction
I ask in a generic way in order to get a generic answer ... custim inspector with an arrar of items each with the same properties and buttons. I know how to do this without arrays ... don't know how to do it with a class array.
specially in the context of doing editor extensions for unity the terms are very generic and if you don't know what to google you are most likely gonna get results related to actual runtime and gameplay engine stuff
googling "inspector array elements" usually yields stuff unrelated to editor extensions
of course. but you can tell that they're unrelated by merely looking at the answers
Tried being 'custom inspector specific' ... coundn't find anything, which is why I'm here.
@tulip mantle well if you are making a custom Editor class (commonly referred to as "custom inspectors") you could get the array property, and get each array element serializedproperty and use them on your GUI/GUILayout
google "SerializedProperty array" and you'll probably get some examples
exactly
don't know what your level of knowledge is in terms of custom Editors so it's hard to tell
if you have further questions or don't understand something feel free to ask here, people will help
I'd have to say beginner ro intermediate ... know enough to know I don't know enough about custom inspectors 😉 But you have given me some Google Threads to pull. Thank you!
no problem
literally the same help
https://help.vertx.xyz/programming/editor-issues/serialisation/serializedobject-how-to
Vertx has some useful resources on the topic
In your dreams perhaps ... don't recommend you take up a job in tech support.
*Really, I'm obviously writing a custome inspector and you tell me to "write a custom inspector" and then you tell me to Google what I'm looking for.
i think somewhere in there there's something about SerializedProperty arrays
Already on it ...
it takes less than 3 minutes of thinking, if you're slow, to get from 'google for this specific thing' to 'ok, i have to google for serialized property array' or equivalent
Enough already
Why is it that every conversation you're apart of, turns into a debate.
because people don't think
That must be it
Move on, they're already getting enough help from MadLed. You don't need to be the dude in the corner trying to get the last word in.
also this is biased. i've had plenty of conversations in other channels, especially #archived-dots where it never turned into anything alike
just saying
Yes, yes, you've been muted multiple times for having a cheery attitude to other community members.
Keep it up. 👍
what's that supposed to mean?
that's still untrue
@patent pebble ... Found what I wsa looking for! Thanks for the 'KICK' in the right Google dirction 😉
i do happily provide help. but i hold up some standards. 1 -thinking required 2 -style required 3 -no trivial questions you could've googled yourself in 5 minutes 4 -be willing to put some effort in yourself. no bite sized feeding @trail dawn
getting started in making unity editor extensions is a pretty daunting task
custom Inspectors and EditorWindows are usually the gateway into this world
so i expect people to struggle and get stuck on those 2 specific topics
i somewhat agree that some people get "lazy" with their questions, probably out of frustration
but we have to give people some leeway, we are all on the same boat
at least that's my approach 🤷♀️
of course
@slim zinc ... 1. I was thinking in the incorrect terms, MadLed helped. 2. Not sure what that means. 3. Google is useless if you are not searching for the correct terms (see 1 above). 4. You have NO idea how much effeort anybody is willing to put forth. I asked for a reference, a nudge in the right dorection, not for someone to write it for me and MadLed helped whereasy you were utterly useless. Good luck with your standards 😉
this was not directed at you
instead of being confrontational we should aim to "train" people on how to ask better questions 🫂
there are plenty of online courses for that already out there
Personally I would make a property drawer for the type contained by the array which draws all the buttons and stuff you care about
Making custom inspectors is only really desired when you intend to restyle or restructure content that exists across many serialized types
If that button does something in that object external to the type you're serializing in the array then you're going to need the custom inspector though (unless you want to get very overcomplicated)
each array item has it's own buttons and properties.
maybe they're asking about each element having different stuff in them?
not sure
@visual stag ... And therein lies the trick, Custom Inspectors are suppsoed to make development easier ... so how much time do you want to invest in one Custom Inspector vs. gettin on with the rest of your developmet.
@patent pebble ... each elememt will be identical 😉
yeah then I would probably do a PropertyDrawer instead of a custom Editor
tool development easily takes at least 1 / 3 of the time you need for the project itself. they have reusability though
doing a PropertyDrawer will take you more time if you've never used them
a custom Editor is a little bit more manageable if you are still a beginner
but in the end both approaches are very similar tho, it's not like it's gonna take you too long to learn
Does this look like beginner code?cs // Section header GUILayout.Label("Logging & Timer...", LabelStyle); // Log Failures tContents = new GUIContent(" Log Fails?", "Check if you want to log failed placement attempt inforamtion."); mtp.TreeSetup.LogErrors = EditorGUILayout.Toggle(tContents, mtp.TreeSetup.LogErrors); // Ignore Timer EditorGUILayout.BeginHorizontal(); tContents = new GUIContent(" Use Timer?", "Check if you want set the maximum 'Time allowed' for Tree planting."); mtp.TreeSetup.UseTimer = EditorGUILayout.Toggle(tContents, mtp.TreeSetup.UseTimer); if (mtp.TreeSetup.UseTimer) { tContents = new GUIContent("» Time Allowed", "The maximum time allowed (in seconds) for Tree placement. The process is exited if time allowed is exceeded."); mtp.TreeSetup.ProcessTime = EditorGUILayout.IntField(tContents, mtp.TreeSetup.ProcessTime); } EditorGUILayout.EndHorizontal();
I'm really asking! ... No other devs to bounce my work off so I could be doing things the hard way :S
looks ok
PropertyDrawers is often what you need, and I think the only things that makes them difficult is having to use SerializedProperty, and having to do your own layout.
What you gain from that though is that they're very self contained, even more reusable, and you don't need to write editors 😄
Peer review is a GOOD thing 😉
Have done a few custom editors ... no drawers yet so I guess it's time to get cracking 😦
yeah when I was learning at the beginning i was scared of PropertyDrawers because I wasn't very confident in my SerializedProperty/SerializedObject knowledge
and having to manage Rects and heights manually seemed annoying
but I rarely use custom Editors now unless for one-off tools
Drawers are modular
and modular is cool 😎
@tulip mantle as a general guideline for IMGUI stuff
i'd use SerializedProperties instead of fields directly, to get undo support and automatic styling
it takes a smidge more time to set up, but it's a lot better
i only use UI Elements for both of these now. makes it much easier. unfortunately you, as of yet, have to write the whole inspector window from ground up since unity has not yet switched to UI Elements only
I tend to get a bit too aestetic in my custom editors 😉
i try to stick as much as I can to the default Unity style
my rule of thumb is to only use stuff that I can get from the engine itself (textures, icons, styles, etc)
and I rarely touch colors, mostly only borders and text colors
i don't think that's a necessity. especially for tools you want to reuse
you'll pack it into a package anyway
it's just my design philosophy 🤷♀️
if I can show a tool to someone, and they're not able to tell if it's a default Unity feature or something I've made myself, i count myself successful
maybe. makes it hard to distinguish features though and reduces recognizability
It helps people know how to use it without having to parse an entirely new style or format
UI, as much as it is based on having pleasing, and easy to use stuff
is also about being the less disruptive possible
It helps people know how to use it without having to parse an entirely new style or format
this 💯
i've dropped plenty of my own home brew "superior" implementations because they are not aligned with the default Unity functionality
adding sprites to buttons and colorcoding things imo helps people use your tool correctly
I don't know what any of these are, whether they're headers, buttons, toggles, etc without actually looking at their content and/or using them
that has nothing to do with how they are colored though nor the icons. the shading is the main thing that makes this design less intuitive
i was making a "better" version of IMGUI sliders, but i asked myself
"what's the point of making my own inspector slider, that has more features, if those features are at odds with the default Unity sliders?"
what's the benefit of having a small extra feature if I'm always gonna be confused wether the slider i'm interacting with is a default one or a custom one?
of course, some tools warrant that, because they offer great benefits to the editor workflow
but not all do
The point is that custom looks make things less intuitive to use. The point is not about avoiding colour or icons
if the slider is not visually distinct enough for the feature to be immediately apparent that still is bad ui design then. not because the feature is irrelevant or useless
but having a slider that looks different than the default one is also bad UI design
if I look at two sliders that look completely different but they work mostly the same...
that's gonna introduce a massive amount of confusion to the user
and it's gonna break visual consistency, which it's also a bad thing
you can't just slap more features on something that already exist and expect it to not be confusing because the existing things already serve their SPECIFIC feature
either they work the same or they do not. what is it.
i disagree
that makes no sense
Yes, I know what they mean ... but others will not without reading all of the tool-tips or documentation, my styalized aesthetics don't cut it. Good point!
If you're making something that is functionally different you should be communicating that function if possible, though it should appear cohesive with everything around it. Not knowing the details of the example doesn't help 😄
if they can both work the same or different, then you can easily add something like a lock icon or similar representing this
because they can't do both at once
GUIs are NOT as easy as they seem to be 😉
that's why UI designer is a real job
i was speaking in the context of adding small features
lets say slider A supports mouse scrolling
and slider B doesn't
that small change would not warrant a completely different slider style because it would introduce too much constrast and break cohesion
and having the same visual style for both sliders would also be confusing
so, in my opinion, the best outcome is to not introduce the feature at all
And just when you think it's good they throw in 508 compliance 😉
i mean mouse scrolling is a very minor thing to be representing. but if that is really needed, not adding the feature is not the solution. rather put a small mouse scroll icon next to the slider for example
i would add the feature if I was able to introduce it to the default Unity sliders
but since that's not the case, it's better to drop the feature
but the default sliders DONT NEED IT
that's relative
@patent pebble... I'd have to disagree. The average computer users know what a slider is/does ... so having them on ranged properties even though for totally different things is OK.
that's not what they are made for
they already serve a specific purpose
IF you could introduce the feature for the default sliders THAT would break all the crafted behaviour of sooo many things in unity. it would be a terriffic idea
not at all
We really do not need the ol' all-caps screaming about a slider.
sliders can be selected, or not
is not screaming. merely highlighting. all caps doesn't mean screaming since 2012
i think he was just joking 😅
sliders already accept keyboard input when they are selected, adding mousewheel input support can be a benefit for a lot of uses
I'M NOT SCREAMING I'M MERELY HIGHLIGHTING
+1
but not for tools unity has already
cause that was a design decision
the same in programming. DO NOT modify. ONLY extend -> open closed principle
I don't think scrapping a feature really feels warranted. Just adding a small icon like they say would be a fine way to indicate that change exists
+1
probably yeah
i just ended up dropping it mostly because i didn't want to add an unnecessary point of confusion
But all of this is pretty beside the point, the point was that that icon should just look cohesive. Making it the same scheme and not look like a bug on the screen
that is definitely the case. if you have ui that looks like a bug, that's just terrible design then
You don't need to redesign the wheel of how the slider looks to implement changes, and when you do for some reason need to make a whole new control, it can just use the same colour scheme and indicators
yeah pretty much
Colour scheme does not exclude new colours, just means that you're not drastically altering the general values in relation to other controls
i'd definitely implement scrolling on sliders in standalone editor tools for example
but not for regular inspector stuff
yeah i'd like to make my tools all pretty and colorful, but I like to stick to the color language that Unity already has
blue for selection, green for physics-related sfuff, etc
and I think Unity's UI design is pretty good anyways
i like it a lot better than Unreal's
definitely. but if you introduce completely new features, don't be afraid to give them distinct design
i like minimalistic design in general for UI stuff
a lot of grayscale, unsaturated colors, low contrast, etc
yeah
Can I use an attribute for a custom SO editor?
In the same way you can put an attribute on a property
I'm not sure what you want to accomplish
They want a propertyattribute for custom editors
I want an attribute I can put on an asset to force it to be drawn with a custom editor.
The same thing you'd do with a property attribute.
``[CustomEditor(typeof(LookAtPoint))]
[CanEditMultipleObjects]
public class LookAtPointEditor : Editor
{
SerializedProperty lookAtPoint;
void OnEnable()
{
lookAtPoint = serializedObject.FindProperty("lookAtPoint");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(lookAtPoint);
serializedObject.ApplyModifiedProperties();
}
}``
aren't you already always writing a custom editor for 1 specific kind of asset?
Hey how can I set a custom Icon for my scriptable object depending on an enum property?
In this example LookAtPoint would be a MonoBehaviour.
aren't you already always writing a custom editor for 1 specific kind of asset?
Yes. Hence the question.
I was already doing that, now I'm looking for a solution to write one for assets with a given attribute.
ah, so you want to write a custom editor for e.g. a json file or so?
can i get a Handles.Label to draw in front of unitys' default transform handles?
Nah, for any SO definition I put the attribute on. I think importing custom file types is a different thing.
I don't understand what the use-case for this would be.
What would you do? Like you couldn't edit any values because you wouldn't know the type
Yeah I'm at a loss too
all I can think of for a possible use case for that would be having a single Editor with selective logic instead of multiple inherited Editors
something like:
public class Parent : ScriptableObject{ }
public class Child1 : Parent { }
public class Child2 : Parent { }
[SomeAttribute]
public class Child3 : Parent { }
[CustomEditor(typeof(Parent), true)]
public class ParentEditor : Editor
{
public override void OnInspectorGUI()
{
// if target type has SomeAttribute: Draw some Button
// else: Don't draw button
}
}
but i don't know how robust that design would be
and it seems redundant anyways
@barren moat what's exactly your potential use case in this?
@onyx harness Kind of late, but... You were 100% right! The System.IO.Directory class takes relative paths! That is going to pretty my code up in several places, so thanks!
@patent pebble @slim zinc
There are ways of iterating the fields via reflection. You can create a serialized object for example, which exposes iteration helpers.
Or you can just do something custom and call "draw default inspector", which internally uses reflection to iterate the fields.
In my case I want to add a field to set the "name" of a scriptable object when it is nested beneath another, as the "rename" function doesn't work for nested assets.
I mean if it wasn't possible to dynamically create an inspector then how does the default inspector work?
What do you mean how does it work? Basically the InspectorWindow's OnGUI checks if there is a custom editor, and if not it simply iterates over the serialized properties and draws them.
Exactly
In this case I use the Editor.onHeaderGUI event
Ooh. Okay, that sounds great.
are you talking about this static event? Editor.finishedDefaultHeaderGUI
or is that a new one?
Uh, yeah that would be it I think. I can't remember the name exactly
Yeah that's it
@patent pebble I realized that code I posted the other day for separate undo/redo events doesn't work because selection is added to wherever you are and does not clear the redo... -_-
ouch 🙃
Thanks @gloomy chasm
I guess the other way to write a global inspector would be to create one on Object. I think that's how naughty attributes works
This is the 3rd solid day messing with the undo system trying to get it to work how I need. Would be really nice if they provided some of these things since they would be so trivial to do on their end
Yeah, that would be the way to do it
you are asking Unity to be reasonable 💀
Not sure if this is correct channel, but closest I can find.
Im making a custom package (here: https://github.com/DraconInteractive/Dracon.Packages.Core.git). This isnt my first package, but it is the first to utilise the 'samples' feature. I finally got my samples working after adding the 'files' section into my package.json, but now my scripts that were working before I got samples working, are now not detecting the namespace of my package scripts (Dracon.Core). I believe its something to do with that files area in the package.json, but I havent yet figured out what. I also cant find the documentation around that section in the unity docs, I had to find it from a forum post.
Its only one error, but if I were to comment it out on that script it just shows the error for the next file that references it.
Have you added the reference to your package in your samples asmdef?
Oh your samples are unity packages? They should just be raw files.
You can do one or the other. Either include unitypackages in the package for the user to import, or you can just have a samples folder.
(looking at current master of your project)
Riiiight gotcha. I actually hadnt caught this, but when im importing the samples right now, its auto-extracting the unity package
which is more interesting than anything else
ill change them back to files
Oh that's cool. Well maybe I'm wrong
I also hadnt considered having a separate asmdef for samples, I currently just have a single one at the root of the package
But it seems unnecessary.
I wouldn't usually include unity packages in version control, because they're binaries.
(unless you have a specific release branch where you bundle them up before you push to it)
Otherwise you won't get proper change history on them
The packaging thing was more that certain prefabs are going to be dependent on other packages, and with unity packages the end user could choose what to import from what unity package
I might actually just remove the samples all together and just have the packages
Samples handles that for you, just put each in its own sample
Not one per currently existing unitypackage?
My idea was to have a players sample folder filled with types of player unitypackages. VR players, mobile players etc. If each of those is its own sample it could get big quick
(using "unitypackage" to talk about .unitpackage files, and "package" to talk about UPM package)
You should have one sample per thing you would import individually
But you said something about depending on other packages, were you talking about other UPM packages?
Because there is a tool for that too that might interest you.
yeh I have a few packages that work together in a fun modular way to expand on functionality. So if you want VR methods, you import vr, and in another package like my stats package, you can reference the VR package for certain vr-friendly stats.
Right right. Yeah I think that's a bit fiddly, but I don't see an issue with putting each in its own sample
The other temptation is to put each in a separate asmdef that can be included individually as required
But I think the assembly still gets included in the build
If you're concerned about optional dependencies you can use this feature
(screenshot from UniTask)
My main issue is that its only 2 right now, but if i have 7 player types, 10 template scenes, etc, thats a bucket of samples
Sounds fine.
It's like a la carte modules
It's either samples or separate packages
Eh, feels like a bad user experience, a wall of packages. Im going to experiment with just including the unity packages in the core package
instead of having them as samples
Isn't that the same?
Just means that you miss out on change history in git
Samples folders function in basically the same way as unitypackages
By including in the base package i can introduce file structures to help sorting etc. So instead of a wall of package names to choose from, you can navigate to Modules->Players->VRPlayer
Very subjective, its just what I would prefer if I were the end-user, and I generally am for these haha
hmm the unitypackages arent showing up...
Looks like the metas are getting extracted, but not the actual file
hmmm I'm getting strange results trying to get Local File IDs for subassets...
RED is GlobalObjectId.targetObjectId : https://docs.unity3d.com/ScriptReference/GlobalObjectId-targetObjectId.html
GREEN is ObjectIdentifier.localIdentifierInFile https://docs.unity3d.com/ScriptReference/Build.Content.ObjectIdentifier-localIdentifierInFile.html
the bottom result is always correct in accordance to the File ID in the actual .meta file
i don't even know how to interpret the result I get on the top one...
where the heck is that number coming from?
AssetDatabase.TryGetGUIDAndLocalFileIdentifier also yields the correct result
Try doing a text search for that string in your project
@barren moat think i solved both my initial problem and my new problem haha. The file declaration apparently needs you to specify file structure, not just filetypes. So im pretty sure samples will now work if I implement them.
Those are the same value, the second one is just displaying it as a signed value
While the first one is unsigned
long vs ulong
If you cast it to ulong it should be what you expect
(cc @patent pebble)
@zenith estuary ooooh damn, good catch!
i didn't think of that heheh, stupid me 💀
Easy to miss 😄
what a weird design decision in their part...
given that the .meta files have signed longs
I'm surprised the meta files don't store them in hex
so much for GlobalObjectId: Struct providing an API for stable, project-global object identifiers.
such a stable identifier that doesn't match the meta file 🙃
i wonder if this is a bug or just one of those weird design decisions they do sometimes to not break some of their internal things
gonna file a bug report anyways, just in case
Looking at the PDB files included with the engine, which reveal the internal data types
It appears to be signed in the C++
Yeah I can't find any instances of it being unsigned inside the engine
So it's probably just a mistake or weird decision to expose it as unsigned in GlobalObjectId
That said, it being unsigned does make more sense
yeah
maybe they wanted it to be more "readable"? not that such numbers are human-readable anyways lol
It's weird all around
that's the Unity life 🙃
What I'm more disappointed about is that GlobalObjectId is editor-only :(
lots of cool things they do that are editor-only
One of the most painful ones is SerializedObject & SerializedProperty
They're essentially a way to expose the internal TypeTree/TypeTreeIterator classes to C#, which still exist in builds, yet we can't use them
As a result, there's a lot of dumb API mistakes you can't work around like Font.lineHeight being read-only
You can create a Font at runtime, but not change its line height, so it's basically useless 🙃
If you want to take a dive into insanity, I wrote this article for a third party Unity wiki a while ago that shows how you can work around that one specific example: https://uninomicon.com/objectlayout
insanity
that's the Unity life 🙃
oh that's pretty neat, will give it a read for sure!
I have so much random obscure knowledge about engine internals I should put together somewhere
It's just that writing it all up takes so much time
yeah
i have a bunch of tutorials and stuff for editor tools on the backburner, but it's just like... "eh, got other things to fix first"
That's basically what happens every time I think I should write something lol
i feel like we are gonna lose a bunch of collective knowledge because of Discord
everything used to run through the forums
in 5 years, there's not gonna be anything useful on the forums because everything is just gonna be outdated
I feel that's already starting to take root
where are asset's LocalFileIDs stored?
i remember maybe they are somewhere in the Library folder? not sure
but can't remember exactly where
For scene objects, inside the .unity file
I don't think all assets have one, for those you have to rely on the guid
LocalFileID is only for assets that have multiple objects within them, after all
If you think of an asset like an array, the local file id is like an index into it (sort of)
@zenith estuary hmmm so for example i have an asset with this LocalFileID
-3064384677914267713
but I can't find it in the class ID reference
Those aren't local file IDs
Those are internal IDs referencing serialization info
They correspond to internal C++ classes
I'm actually surprised those are documented
i thought the LocalFileIDs were the same as those Class ID references but multiplied by 100000
Nope
There's no correlation
The class IDs are what you see after !u!
the class ID for RenderSettings is 104
a TextFile (TextAsset) gives me this LocalFileID
4900000
and the reference ID for a TextAsset is
49
hmmmm
That's likely coincidental
Or perhaps they use the class ID to generate the file ID sometimes
But as far as purpose goes, they're unrelated
it's consistent across many types: MonoScript, Text File, AnimationClip, etc
and every time I need to figure out what a FileID was, i've used that Class ID Reference list
Looking at disassembly of some of the engine functions, it looks like the local file ID is a hash of sorts, and the class ID is potentially one of the sources for that hash
but this LocalFileID is a custom file type (a text file that uses a custom Scripted Importer)
-3064384677914267713
so I guess I'm trying to understand how it's generated
A TextAsset only has one asset in it, so nothing else is merged with that value, so the hash ends up being equal to the class ID * 100000
Yep, it looks like it is indeed just a hash of class ID + offset
int64_t MakeLocalFileIDSequence(int typeID, int64_t offset)
There's also int64_t MakeLocalFileIDWithHash(Unity::Type const *type, int64_t offset)
So that solves that mystery
The latter appears to hash the type name with the offset, which would explain the large value you got earlier
So a file ID is generated by hashing either the type name or ID with an offset value
@zenith estuary ah, so it's just probably generated from the name of my custom asset type?
the name is "Example"
Most likely
is there an exposed API to generate the same hash manually?
this is a little bit out of my knowledge
Here, I reconstructed the function from the assembly:
public static long MakeLocalFileID(int classId, long offset)
{
offset *= 2;
if (classId >= 0x800)
return offset + 0xC7282226 * classId + 0x1C6BEEECF2EED000;
if (offset >= 100000)
return offset + 1000000000000000 * classId + 9999900000;
return offset + 100000 * classId;
}
I really don't want to reconstruct the one that uses a name lol
As far as I know there's no function for this exposed publicly
Also I'm not 100% confident in my assembly transcribing skills, so try verifying that against some examples
@zenith estuary alright! i understand a lot better what's going on behind the scenes
unity IDs stuff has always been a bit of a confusion-inducing topic for me
thx a lot! 💙
It's a bit of a black box yeah
I guess I can add this to the long list of random obscure knowledge I have lol
hehehe yeah
Not that I'm ever going to remember that algorithm
One has to wonder though
Why does this concept even exist
Why don't they just store the offset?
The class id is already known in the file, so what purpose is there in this being a hash?
It exists, it's just internal
So I guess I didn't need to translate it after all lol
Yup everything is fine with my code... no problems here xD
hahah yeah i was digging on the source i think this has a lot of related stuff
https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/TypeSystem/UnityType.cs
Yep, I'm intimately familiar with that source file
persistentTypeID is another name that class IDs are referred to by
UnityType is basically the C#-side version of the RTTI class in the engine code
Or rather, Unity::Type, which is just a wrapper for RTTI
ah right maybe they do the offset thingie to get a long
because the UnityType uses an int for the identifier
public int persistentTypeID { get; private set; }
there's an obsolete method for LocalFieldIDs that used ints before, but now they use longs
It's an int since it's just an enum internally representing what C++ class it is
The class IDs page is basically just a list of values from that enum
I'm really not sure why they even need longs here tbh
they have this warning in the docs
Warning: Avoid the obsolete versions of this function, which use int for the localId parameter instead of long. Local Ids can be longer than 32 bits in some cases, such as for Prefabs. When Unity serializes an asset reference it points to two things: the GUID and file ID. GUID is a unique hash, and file ID is a value relative to the asset. Both of these values are used when a serialized asset references another asset.
so I suspect it's related to the reason why
if an asset has over 4 billion objects inside it, I think you'd have other problems lmao
probably
I don't know enough about this specific corner of the engine's depths to say for sure
hmmmm, seems like ScriptedImporters don't register their types as UnityTypes
can't find mine on the static list of all types....
so i'm still at a loss as to where the LocalFileID is generated from 💀
in fact, calling this to try to get the Class ID crashes the editor lol
[FreeFunction("AssetImporterBindings::LocalFileIDToClassID")]
extern internal static int LocalFileIDToClassID(long fileId);
That list is only comprised of types native to the engine, custom scripts will be assigned the MonoBehaviour type
There's similar behaviour for ScriptableObjects
right, but for example some of my ScriptableObjects were part of those IDs along with the Native types, that's why iwas expecting my custom asset types to be assigned IDs in a similar fashion
didn't dig far enough to see what was different about those specific ScriptableObjects
eh, i give up for now, i was just curious to see if there was a unified way of getting those IDs
I guess it's yet another one of those unpredictable Unity quirks 🤷♀️
Does anyone know how to rename a nested asset and have it update in the project window?
None of this seems to do the job:
using UnityEditor;
using UnityEngine;
namespace EffortStar.Editor {
[CustomEditor(typeof(AttackActionConfig))]
public class AttackActionConfigEditor : UnityEditor.Editor {
public override void OnInspectorGUI () {
var prev = target.name;
var next = EditorGUILayout.TextField("Name", prev);
if (prev != next) {
target.name = next;
EditorUtility.SetDirty(target);
AssetDatabase.SaveAssetIfDirty(target);
AssetDatabase.ForceReserializeAssets(new [] { AssetDatabase.GetAssetPath(target) });
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
AssetDatabase.Refresh();
EditorApplication.RepaintProjectWindow();
}
base.OnInspectorGUI();
}
}
}
But if I close and reopen the project window it will update.
This is me basically throwing every conceivable operation at it, to no avail.
"error files"?
If you want to revert a commit you can do git revert <sha>
I don't know what program that is
conflicted
Usually you can right click on the commit and choose "revert"
github desktop
You'll need to resolve the conflicts
what does that mean?
It means that there is no automatic way for git to revert the file, probably because you've modified the same line since.
So it doesn't know what line to revert it to
@barren moat iirc i have a utility class thaf rebuilds the project view to refresh its state, i think i used it for dealing with sub-assets too
not at my PC right now, about to hit the bed
I can dig it out tomorrow for you
Thanks, that could be useful!
what is sha?
The commit hash
It sounds like they've already worked out how to revert it.
In GitHub Desktop you can switch to the history tab and right click the commit to revert it
Just that there are conflicts
I've learned that dealing with stuff like that often requires to "rebuild" things
i have to do it for a bunch of Inspector tools
and for the Hierarchy and Project, because it's often not enough to change an Object's data, you need to force the engine to reflect those changes in the internal data structures (TreeView, etc)
there's probably ways of refreshing the data without forcing a rebuild, but it's just way easier to do the rebuild
I haven't
the revert feature is sometimes a bit strange. just fork the snapshot and clean the repo afterwards
I simply do not encounter conflicts 
Well I haven't the faintest idea of how to do that, so if you could share when it suits you that would be very helpful, thanks. It's not really a blocker that the names aren't updated immediately.
If you're getting conflicts then you must have pressed "revert".
yep, tomorrow when im back at the office for sure 👌
yes but it doesn't revert
Not until you've resolve the conflicts, no.
You'll need to do that in your text editor.
Or a conflict resolution tool
I don't know if GitHub Desktop has one, but I use p4merge
(kind of annoying to download, but it's very good)
github desktop let's you choose any tool
That's what I'd expect. Does it come with one?
I think most IDEs should have built in conflict resolution.
i think so. i always use vs code though
I can do it via VSCode.
it deletes my files when i revert
and creates conflicted stuff
@barren moat
You're probably reverting a commit that added files
Hi! i'm having some struggles with GUIStyle.CalcSize, i think.
Here's a bit of my code:
labStyle.fixedHeight = labStyle.CalcSize(lab).y;
labStyle.normal.textColor = Color.white;
Rect labelRect = new Rect(rect) {
};
labelRect.height = labStyle.CalcSize(lab).y;
EditorGUI.LabelField(labelRect,lab,labStyle);
Rect buttonRect = new Rect(labelRect) {
};```
so i've got a label, which may or may not be on several lines. My question might be simple: does CalcSize take wordwrapping into account?
because rn, my button is set to have the exact same size as the label, and in reality, here it is:
oh well
this is... Peculiar.
(even more peculiar is the fact that this might juste have been patched? Cuz it's not working for me now, on unity 2021.2.8; here's my new code:)
GUIContent lab = new GUIContent(actionsStr);
GUIStyle labStyle = new GUIStyle() {
wordWrap = false,
alignment = TextAnchor.UpperLeft,
};
labStyle.fixedHeight = labStyle.CalcSize(lab).y;
labStyle.normal.textColor = Color.white;
Rect labelRect = new Rect(rect) {
};
labelRect.height = labStyle.CalcSize(lab).y;
labStyle.wordWrap = true;
EditorGUI.LabelField(labelRect,lab,labStyle);
Rect buttonRect = new Rect(labelRect) {
};```
so i've created a custom editor and i want the Preview Material to remain the same after closing and opening Unity again
is there a way where i can ensure the material assigned persist?
well, only thing i see is maybe saving it in a file on your computer. Or maybe just saving the reference to the material
damn....
Hehehe
@barren moat
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
public class ProjectBrowserAccessor
{
private object _instance;
public static Type AccessedType = typeof(Editor).Assembly.GetType("UnityEditor.ProjectBrowser");
private static MethodInfo MI_GetAllProjectBrowsers = AccessedType.Method("GetAllProjectBrowsers");
private static MethodInfo MI_ResetViews = AccessedType.Method("ResetViews");
public ProjectBrowserAccessor(object instance)
{
_instance = instance;
}
public static List<EditorWindow> GetAllProjectBrowsers()
{
object obj = MI_GetAllProjectBrowsers.Invoke(null, null);
return ((IEnumerable<object>)obj).Cast<EditorWindow>().ToList();
}
public void ResetViews()
{
MI_ResetViews.Invoke(_instance, null);
}
}
using System.Collections.Generic;
using UnityEditor;
public static class ProjectBrowserUtility
{
public static void ResetViews()
{
List<EditorWindow> allProjectBrowsers = ProjectBrowserAccessor.GetAllProjectBrowsers();
foreach (EditorWindow projectBrowser in allProjectBrowsers)
{
ProjectBrowserAccessor accessor = new ProjectBrowserAccessor(projectBrowser);
accessor.ResetViews();
}
}
}
this should do it
just call ResetViews after you've changed the names of your sub-assets
you may need to save and reimport the assets before ResetViews
@patent pebble I am so sad, I now realize what the problem is with my Undo code, and that is that if you undo 2, register a new undo, and then undo again it will think it is a redo because I am only storing the count when an undo/redo operation happens. I some how need to get a event every time a new undoable operation is added 😭
damn, sounds like pain
It isn't even one of those things that I can go "ehh oh well" because I need it, idk what to do, this is my forth solid day working on this thing
undocked editor windows remaining on top of the main window when losing focus - any way to fix this?
only occurs on PC, no issues with the same release (2020.3.25f1) on OSX
You legend
What are you trying to achieve?
I have certain events that are triggered when an SO is changed in a certain way, but of course currently the events do not get triggered when an Undo/Redo happen. I also need to save the SO when it changes, but I think I have figured out how to do that.
So basically I need to know when a undo happens and when a redo happens so that I can invoke the events appropriately
There is Undo.undoRedoPerformed, and I can get the number of undos and redos
Hm. I see. I had a system that did something similar but it was just for tuning values in editor at runtime.
Yeah but how do you poll in editor?
Undo.undoRedoPerformed is an event that is invoked when a undo or redo is performed
I need to know specifically if it was an undo or if it was a redo
What does the code do?
What does what code do?
Ah, so my events have info that is passed with them (like what was changed, how many items added etc.), so I store those in a stack, and what I want to do is to pop them from that stack on undo and 'reinvoke' the event with that data. When the data is popped, I push it to a 'redo' stack so that on redo I can again pop that data and 'reinvoke' my event.
Oh I see. Yeah it's really hard to get deltas in the editor. It's annoying.
What do you need that for though?
So that my events are triggered any time the SO changes.
A. for reliability, and B. so my editor window can update properly.
Is it for runtime tuning?
Nah, all in editor
I mean playmode sorry
What if you had a global undo/redo counter and then stored each change event in a stack along with an ID
I'm assuming that's the kind of thing you're thinking of
Do you mean my change or a change to the unity undo stack?