#↕️┃editor-extensions
1 messages · Page 80 of 1
Clearly
Was not clear, it broke on version update with no code changes ;p
importer is not null and successfully casts to MonoImporter.
importer.GetScript() is returning null which makes it impossible to figure out what class is being compiled (perhaps because it hasn't compiled yet 🤔 )
Can a Generic Menu be used with the MenuItem attribute?
I'm trying to show a context menu when clicking on a menu item on the top bar of Unity
But it doesn't seem to show anything
[MenuItem("Details/test")]
public static void Menu()
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("TestName"), true, ToggleMenuFunction);
menu.AddSeparator("");
menu.AddItem(new GUIContent("All"), false, ShowAllDetails);
menu.AddItem(new GUIContent("None"), false, HideAllDetails);
menu.ShowAsContext();
}
maybe Generic Menus can only be used inside the OnGUI loop?
the documentation doesn't say anything about only using it in OnGUI exclusively, but shows the example using them in OnGUI() 🤔
oh nevermind, the source uses an event in ShowAsContext(), so I guess not
Another question, can I somehow control the order of the Menu Items on the main Unity bar?
public MenuItem(string itemName, bool isValidateFunction, int priority);
you intrested in priority?
priority only works for setting the orders of MenuItems that are submenus within another MenuItem
it doesn't seem to affect the main Unity topbar
well. my best guess is they are ordered in same order unity validates and loads scripts. checked couple times that in same file MenuItem remain in same order they presented in script. so probably easiest way to control it is placing MenuItems in one big script and order it there :D
or use that bizzare menu to control order of loading scripts.
also i think unity will place user menus anyway before "Window"
that's why I'm asking
since they are all handled internally, maybe someone knows a way of manipulating that with reflection or maybe with a publicly available utility class
I'm checking on InternalEditorUtility but it doesn't seem to have anything
well. i dont know. also unity guidelines telling me "dont create new MenuItem categories and use existed one" so i never looked for this.
where do they advice to not create new categories?
oh where it is. it is in "Submission Guidelines" for asset store.
4.3.1
oh, I see
4.3.1.a Editor extension file menus must be placed under an existing entry. If no existing menus are a good fit, you can place it under a custom menu titled "Tools". This keeps the editor clean and organized.
I thought it could cause some internal conflict or something, but it seems to be mainly for keeping the top bar clean
This guideline is for public stuff.
For your own use, you do whatever you want
though they make sense when you do it in your own stuff. couple times i looked up to toolbar and saw junkyard.
It's all up to you to not mess with yourself
@wispy delta sorry a little late, I don't know if it'll help but maybe you can use [RuntimeInitialization] or whatever it's called and make sure the function runs after the assemblies are loaded?
Can Presets be setup to not include certain fields?
What would be the best way to have multiple editor UI buttons for a class on the same line? Or rather, what would be a user friendly way to handle lists better than the default editor?
currently using GUILayout.Button
multiple things on the same line? use a HorizontalScope
or Begin/End Horizontal
want to draw a better list?
make a ReorderableList. They're kinda annoying to set up (and they're basically default in 2020+ now), but they're the way to do it
is there a way to add my own prefab to the create button like how cinemachine adds its own camera can I add my own game object?
Just make a menu item that's in there then just instantiate a gameobject
About this - what's determining that now? Are they just giving us ReorderableLists for any List<T> variable?
and the old array thing for T[] arrays?
I got a reorderable list for a proprety that I simply am drawing with EditorGUILayout.PropertyField(inputs);
actually now that I'm looking, that field is an array
so maybe everything is just a ReorderableList now?
Anyone know how to make it so that a reorderable list works with drag and drop?
I have the class called light controller, which I can drag in the normal list in the editor, but drag and drop doesn't do anything in the reorderable list.
Kinda have a hunch that there's something not right in the drawelementcallback
LightControllersList.drawElementCallback =
(Rect rect, int index, bool isActive, bool isFocused) =>
{
var element = LightControllersList.serializedProperty.GetArrayElementAtIndex(index);
var elementRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
element.objectReferenceValue =EditorGUI.ObjectField(elementRect, element.objectReferenceValue, element.GetType(),true);
};```
It works by default but only when you click outside the element iirc
doesn't seem to work like that either
Drag and drop in what way? Like a field reference?
like, drag from the hierarchy to the list, an object with a component of that type
it works if I drag into the normal list view, but not in the reorderable one
Hey all, quick (hopefully easy) question: Im new to UIElements, making an extension using the GraphView API. Im adding some new elements to the mainContainer of a Node, and they are all stacking vertically (screenshot for example).
I would like the enum and the integer field to be on the same line (as they are a single skill check). Any advice?
Code for reference:
public void DrawSkillCheck (DialogueNode nodeCache, SkillCheck _check)
{
var ve = new VisualElement();
var skillEnum = new EnumField(_check.Type);
skillEnum.RegisterValueChangedCallback((A) =>
{
var newType = (Stat.Types)A.newValue;
});
var skillTarget = new IntegerField();
ve.Add(skillEnum);
ve.Add(skillTarget);
nodeCache.mainContainer.Add(ve);
}
Put them both in a VisualElement and set the style flex direction to row. That easy
And ... you're an instant legend!
Never thought my horrible css skills would be needed in Unity 😛
Haha, glad I could help. I don't mind if you @ me if you have any more questions 🙂
Thank you!
If you dont mind an instant followup @gloomy chasm , how would you go about stretching those two elements to fill that line? Currently they're huddled at the left hand side.
Looking at options, im seeing flex basis (but that only changed height??), and flex grow/shrink which im unsure about
if you use the UIElements debugger (right click on the inspector tab and it should be in there) you can have a play with it very quickly
flex grow should be the one
oh, didnt even know that existed haha. Thanks 🙂
I always get confused so messing about with it until it works generally helps 😄
What value IS flex-grow though? Pixels? Percent? Doesnt say in any of the docs
Because no matter what I do to it nothing changes haha
I usually just set it to 1
I think (this is off the top of my head) it's a normalized value that describes how much of the remaining space in the container that the item will use
0, it won't expand to take that space, 1 it will take all of it
Ha! Got it. Yep, you're right 🙂 I, however, am a numpty, and was applying flex-grow to the container. Applying it to the individual field made it work
Is UIElements the new way to build Editor tools? Or at least display them
It's what Unity wants you to
The way you say that makes me think I should avoid it a little longer
Apparently it's not that bad in 2019.4 and 2020.1 but last time I used it, it was still kind of cumbersome with shitty docs
Some people here do like it though
I do a 2/3 IMGUI, 1/3 UIToolkit, but I try to do as much UIToolkit when it comes to building tools for release just because I'd rather they be maintainable in that way. For stuff internal for projects, IMGUI rules, it requires minimal setup, and most of what is 'normal' is both easy and fast to create.
For anything that's a lot of complex nested/scrolling content like node graphs I would never do IMGUI 😛
Got any good tutorials on that stuff Vert? I've been reallyyy loving editor scripting but so much is just undocumented
Speaking of poorly documented Editor stuff. Anyone has a good source to learn to use TreeView? The examples Unity gives seem pretty convoluted
Ugh, I hate Unity not returning the right property height for fields that collapse unto multiple lines (e.g. vectors)
Do they even do fix to MGUI anymore ?
They might
Docs are still just as shitty but UITK itself is quite good
I find UITK to be so much better than IMGUI to work with that I make a point to make it work well enough in 2018
Quick question.
Is there a way to pass data into a property drawer within a editor script?
For example I want a popup inside my property drawer to be populated based on the field from a different serialized property.
You can always acquire the SerializedObject from a SerializedProperty via its serializedObject field.
At which point you can find the other serialized property on that object.
However since its a property drawer, there is no guarantee that the serializedObject is the type you expect
So this isn't exactly a robust design since the property drawer should stand on its own
This may be ok depending on your projext, and if you're using a Property Attribute to trigger the PropertyDrawer it means it will only come up when intentionally used
OK I sort of understand what you are saying but how would that allow me to populate data into the popup field that my property drawer is trying to draw?
OK I have gotten the data out of the serialized property that I need now I just have to figure out how to pass it to the property drawer 🤔
Use a custom event
Ah I was thinking of doing that since I can get the serialized property type. I wish Unity had better documentation when it came to using this stuff.
I don't think you both are talking about the same thing
@fiery canopy Your PropertyDrawer is generated based on a specific field (Which might have a custom attribute?)
Use this custom attribute to target another field to be populated with
Oh I didn't realize that could be done
Oh OK I think I misinterpreted what you were saying @onyx harness
The field that I am trying to use doesn't have custom attribute it is just an int value.
What I am trying to do is have the property drawer draw a popup field instead of the int field it would draw without it.
And populate the popup with string data from an array.
you need a custom property attribute
Wait so I have to put the Property Attribute on my int variable to make that work?
I thought that was only for MonoBehaviors?
yep
Hum no
Attribute can be marked on almost anything C# thing
You need a CustomPropertyAttribute on your int field
then write your own PropertyDrawer
Is it possible to override unity's default CSS styles using an inherited style? It seems like if I supply anything other than an inline style unity's defaults will take precedence
For example, here despite me supplying my own CSS selector unity's defaults still take precedence:
@onyx harness I kind of got it working but the thing is for the Attribute it is expecting a constant value. So if I want to for example change said value I can only do it through the Custom Property Attribute
Oh nevermind I didn't realize you could use Attributes without having to set parameters
@civic river You should be able to override the defaults. You just have to make sure you use the correct names in your CSS file
It has the style their loaded in the SS, but you can see it's priority 4 and being overriden by all of the unity styles
Mine is the BaseNode style and unity's are the others
I'm not really a css guy but I'd think unity styles would have the lowest priority
but it seems to be the inverse
It should have the lowest priority...
Is this a bug then?
For ex:
.port.typeString {
--port-color: rgba(200, 200, 200, 0.5);
}
You can see unity has a higher priority than me]
I'm having the same issues with many of the property field CSS as well
I don't know I have never encountered Unity overriding custom CSS
But it could also be the values you are using for your color
Try
--port-color: rgba(0.2,0.2,0.2,0.5);
unfortunately no styles are overrideable from this css class
I can only create new style options that are not provided by unity's port.output and port.typeString
I can apply this same color to other css elements and it applies fine,
.unity-toolbar {
background-color: rgba(30, 30, 30, 0);
}
.unity-button {
background-color: rgba(0, 173, 181, .5);
}
.unity-button:hover {
background-color: rgba(0, 173, 181, .88);
}
these all apply
I'm unsure what the difference maker is
That is weird
looking at those numbers those shouldn't even show up because in the first case the alpha is 0 and the others it is close to 0 so you should barely see any color
the alpha is 0..1 but the rgb is fine as 0-255 or 0..1
I am guessing it's how it is in regular CSS but unsure
🤔
Well I'm not sure then
hold on let me check something
Quick question is what you are trying to do have to deal with graph view by any chance?
This port example is graph view, but almost all of the UITK property fields have similar problems
Oh OK
once my project loads I can see what is going on
Ah I thought I used rgba for my colors but I used hex values like this
background-color: #006600;
Also I think I don't even bother changing the alpha when using hex but I don't see why you wouldn't be able to
weirdly it doesnt seem allowed to supply alpha
with hex
but css seems consistent with that /shrug
OK yeah changing the unity generated properties works for me when I change the color of the graphview nodes background color
let me see if changing the port color works
So it seems when I change the background color for the port in the graphview it doesn't change
I also tried changing the port color in the ui debugger and it doesn't change which is odd 🤔
yeah, I can only apply that as well using an inline style.
anything else unity overrides
it is the same problem as the port color
I looked at unity's css files
and there's no indicator that they have different priority
it certainly makes it very inconvenient, maybe this is not the intended behaviour
or maybe there's some obvious CSS solution that I'm just not aware of
xP
So I did some digging and it seems you have to go even further down the hierarchy if you want to change the color of what the connection port is.
Does that change the edge color correctly?
I think the edge relies on the --port-color
No that chances the actual port connection graphics color
let me see what changes the edge color
Oh lord their actually is a CSS solution for this... Lets see if unity implements this https://css-tricks.com/when-using-important-is-the-right-choice/
looks like no
So changing the edges background color is possible but not the line graphic for it seems like
Wait what did you change to get it to work?
inline style
no I mean which style?
--port-color
Ah ok
--port-color: rgba(200, 200, 200, 0.5);
^
it's just a matter of having high enough priority to override unity's style
I will have to ask about this !important on the forum
maybe not implemented.
Ah OK that is something I will have to look into because when I tried changing the port color inline style in the UI Debugger it wouldn't even let me
yeah I had to make my own port class to change the inline style
;p
this is why I ask
because it's incredibly inconvenient
I don't want to have to also make my own property drawer classes >.<
Yeah that is a pain most of the time.
But in most cases if you look at the UI Debugger and look for what you need to change if it can be changed in the debugger then you can just add the relevant tags to your CSS file
yeah, it seems like 50% of the time it works but other times the style does not seem setup correctly maybe
having access to this !important thing seems like... uhh.. a solution
Indeed it does
I would like to know why it wasn't implemented
To be honest I think they are waiting because we still don't have animations for UI Toolkit
I am very new to all this CSS stuff, but I like UITK enough to deal with these problems because the many edge cases I have to solve are still less painful than the old editor-gui solution for me xD
Lol yeah
Is it expected that CompilationPipeline.RequestScriptCompilation(); does not make the Unity Editor recompile scripts when EditorSettings.enterPlayModeOptionsEnabled is true?
Compiling would result in reloading the domain... but whether or not that's expected is debatable yeah.
I could maybe see why there's a safeguard against it
Yes, I would also expect the domain to reload, which would still maintain the EditorSettings.enterPlayModeOptionsEnabled purpose. I am curious to know if there is an actual reason for this not working, or maybe if it is just a case that was overlooked by the Unity devs
Might be an overlooked case, probably worth filing a bug report either way as it's a pretty specific case
I'd at least expect CompilationPipeline.RequestScriptCompilation(); to give a warning if it did nothing because of the play options
Any ideas as to why this would show up white, and not its actual color? Can change using debug toolkit to correct value (which is what is there).
sl_v.style.backgroundColor = new StyleColor(new Color(43, 43, 43, 1));
Background is see through on auto, so its definitely making a change, just not to the correct color
What is 43, what is 1? The scale.
Color is 0->1
ahhh wrong rgb, thanks all
it's amazing how things just work when you read the docs 😛
I am trawling the docs rn
Ah, yep, definitely should have looked there. Was looking at https://docs.unity3d.com/ScriptReference/UIElements.IStyle-backgroundColor.html
Got thrown off by IStyle and StyleColor tbg
*tbh
Yes I will! thanks
Hi there! I'm using ScriptedImporters to import our own file format. I have some importer settings and try both with the default editor and a custom made ScriptedImporterEditor but the inspector ignore entirely Custom Property Drawer for the fields. It's quite a big issue as they are necessary for us in this case. Any idea why? Tried with 2020.1 and 2020.2, similar issue
Show code
What part? It's quite straightforward. There is a ScriptedImporter, with serialized fields in it (so like public int m_Something for instance) with an attribute on it to use a custom property drawer (for instance, I have one which instead of the int, will display a dropdown box showing all elements from a database to pick one, but only its unique ID (int) is stored).
Then when I select the asset , the inspector does display my fields, but not using the custom property drawer (that drawer works perfectly fine in the usual inspector on scripts, or in Editor Windows, etc..)
Amusingly, builtin properties, like [Range(x, y)] work fine
Your editor needs to inherit from ScriptedImporterEditor and need to apply to the importer class
Yes, like I said, it works fine for simple things, the only issue is some custom property drawers not working
What property drawers
Custom ones, which work fine in a usual inspector
You mean your imported object has fields that have propertydrawers for it?
Or your importer has fields that has custom propertydrawers?
What does your scriptedimportereditor look like
My importer, funny enough if the imported objects has fields like that, it works fine ! It's only in the importer that it doesn't
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.
It's really basic, nothing fancy
What's m_IDReferences
A List<IDReference>, which is a struct containing multiple int
and these ints have a PropertyAttribute on top of them to use CustomProperty drawers
Seems all correct
I'd debug what Unity is trying to select for the drawer
Aka, step into whatever propertyfield is doing
Where does that happen? I would expect it to be in EditorGUI.PropertyField, don't have the symbols for that though
Rider and VS should be able to debug into it using decompilation debugging
I'll give it a try with VS, thanks
Is your propertydrawer UITK?
No, just old school editor
Yeah you should be all good then
Hey guys, i am trying to make a patcher in a editor tool for my fbx files/maps etc i am just wondering is there anything in unity that records the import time? so i can cross reference and patch up for my other devs if needed
Think it's in the logs
when u say logs u mena?
The editor logs
Quick question When you call Repaint() on an custom inspector does that reinitialize the entire inspector? Or does it just redraw it only?
is it possible to have fields that serialize in the editor but dont' serialize for builds?
I have these references that I want to exist only in the editor
Wrap them in #if UNITY_EDITOR #endif
That appears to cause problems in builds unfortunately
Well if you reference those fields in other parts of your code yes it will
that directive makes the compiler completely ignore that code when building for a target that is not the unity editor
It doesn't end up excluding the referenced assets from the build is the issue
@severe python
I've had luck wrapping a partial class in #if UNITY_EDITOR but I'd check if it works for your purpose in build, I have a sneaky suspicion that removing fields in some cases will causes deserialization problems at runtime.
https://hatebin.com/gawueffbjs
In terms of references, maybe unity doesn't care if the field is compiled out and is doing static analysis on the existing codebase, not the compiled codebase, if that's the case you probably need to look towards addressables or something similar.
it does cause some issues, I would avoid it as I've seen posts by Unity employees saying it's not good. Unity complains a little during the build process (though it doesn't actually seem to affect anything) - and also I've seen IL2CPP stack traces get screwed up, unsure if that's related to the same issue though
^
is there a way built-in way to import MeshColliders from a model or do i need to implement an AssetPostProcessor?
Probably not
ok
Anyway to replicate the drag/drop that Unity does for game objects for fields?
Id like to assign a field by being able to drag an asset on it, and then it does what it needs to get said value (like unity dragging the object pulls the component)
Right now I have an object field and a string field overlapping each other
oh so it was the event stuff thought that'd be for scene view 
thanks, got that running
Yeah I just need to strip references to assets I dont want in the build pre build and need to figure out how to handle that in a generic fashion
Does anyone know how to fold/unfold a transform in the hierarchy through code?
I want to be able to do this but in code 🤔 Please @ me if you know how.
@fiery oasis There are several answers here : https://answers.unity.com/questions/656869/foldunfold-gameobject-from-code.html
And here is a utility that does it that is linked in one of those answers: https://github.com/sandolkakos/unity-utilities/blob/main/Scripts/Editor/SceneHierarchyUtility.cs
And here is another implementation: https://gist.github.com/yasirkula/0b541b0865eba11b55518ead45fba8fc
oh wow nice! I should of thought to search for "collapse" as well 🤦♂️ Thank you, this is exactly what I was looking for 🙂
I made something that puts the prefab variant icon in the bottom right to make it more clear it's a variant
is this built in Unity or does it have to be custom
If i start using bolt in 2020 or 2019 (asset store version), will upgrading to the package manager version in the future cause class name change issues or something?
gots the big problem bois, I downloaded this project from github and updated the project, but when I open the project im getting tons of library errors. I also just added it to unity collaborate. Here are a few:
Library\PackageCache\com.unity.collab-proxy@1.3.9\Editor\UserInterface\Bootstrap.cs(23,20): error CS0117: 'Collab' does not contain a definition for 'ShowChangesWindow'
Library\PackageCache\com.unity.collab-proxy@1.3.9\Editor\Models\Providers\Collab.cs(110,22): error CS1061: 'Collab' does not contain a definition for 'RevisionUpdated_V2' and no accessible extension method 'RevisionUpdated_V2' accepting a first argument of type 'Collab' could be found (are you missing a using directive or an assembly reference?)
Library\PackageCache\com.unity.collab-proxy@1.3.9\Editor\Models\Providers\Collab.cs(114,22): error CS1061: 'Collab' does not contain a definition for 'ErrorOccurred_V2' and no accessible extension method 'ErrorOccurred_V2' accepting a first argument of type 'Collab' could be found (are you missing a using directive or an assembly reference?)
If you can help me that would be epic
I don't think so, but #763499475641172029 would be a good channel to ask it (well there is a discord server linked that would be good)
Not sure if this is the right channel, but couldn't seem to find one that fits my question except maybe this one. I'm getting a console error when installing 2D SpriteShape from the Package Manager. I have uninstalled and reinstalled the package from the manager, the console errors go away when it is uninstalled; but come back when it is installed. Not sure what the exact problem is, but it does not appear to be on my end. My playtests work fine and everything seems to be working. Could this just be a problem with 2D SpriteShape? I do see where the error is coming from in the script, but I don't want to mess with it.
Is it possible to draw an editor within a reorderable list? The only draw functions I'm finding are for within a layout, not a rect
I've got a list of serialized objects and think it would be slick to draw the inspector for the selected element within the list. looks like unity doesn't recalculate element height after clicking so I can't dynamically change the height of an element to add space for an editor, making my previous q moot 😦
Yeah, I don't see why it wouldn't be possible! What issue are you having?
So I've created the editor and it draws nicely outside the list but my understanding is that the layout for a reorderable list is precalculated, so I can't draw anything that uses GUILayout or EditorGUILayout within the drawElementCallback since the layout will be placed below the list
THere's a callback I think for getElementSize or something
that you can use in addition to drawElementCallback - IIRC
I've used it before but I forget the name
you can override the height per element of a reorderable list- but the problem is that drawing the editor, layout is unknown as far as I know
because it's just a call to OnInspectorGUI or whatever, and that just goes straight to user code, right?
which is going to use Layout to draw
yes, I tried using that to dynamically change the height of the selected element, but the callback is not invoked after selecting an element, so a newly selected element in a list does not get resized
so unless you manage to get the layout to properly allocate/calculate there, (mikilo might know) it won't work
but that's one of two problems, the latter is that I can't find a way to draw an editor without it being done via layout which puts it at the end of the list gui
(sorry @visual stag reading your messages now, just wanted to clarify some stuff)
yes as far as I know, you're right. gotta find workaround for layouts and elements not getting resized at the right time
obviously i should just make my own take on a ReorderableList class. i'm sure that's not beyond my skill level 🤡
Can anyone point me to directions on adding an item to an EditorWindow context menu? I understand I can add a GenericMenu to an item, but trying to add to the actual windows menu instead of an element
Implement UnityEditor.IHasCustomMenu on your window
ah thanks!
Hey guys how do i validate when player press this maximize button in code?
Anyone have any feedback on how stable Editor Coroutines is rn? I know its in preview, just interested as to its usability. Project isnt commercial so I can deal with some screwiness
How do I force an editor to draw with a specific width?
Have you try to wrap it?
Wdym wrap it?
I just put in a group to position it but it's trying to render wider than my group is wide
Around BeginArea Horizontal/Vertical layout
If I'm not spreading shit, Clip/Group are culling/clipping the drawing area.
While Area really starts a new layout pipe/stack
You can see that when you ungroup an EditorWindow at the very beginning and start drawing in neighbor windows 🙂
Ah makes sense
Anyone know of a way to change a nodes title text color? Changing the label color attribute in the debugger works, but inline code like:
node.titleContainer.style.color = newColor;
Doesnt do anything. Ideas?
UITK?
... I do not know what that is sorry. A tool kit?
That being said, I think I was actually referencing the wrong VE. I think I should be modifying a Label thats a child of the container
Oh, UIElements? Im new to it sorry, havent fully absorbed various terms
UIE got renamed to UITK
... well that is information that is going to make my googling a lot better
how the hell did i miss that
It's only going to make it worse most likely
At least you'll only find recent things
Yeh doubly interesting, because I normally restrict to "The past year" anyway
Hello guys, I have one quick question when I create a custom VisualElement where should I create sub elements ? If I do it in the constructor nothing happen
Doesn't matter, you just have to make sure to add them with myVisualElement.Add(newChildElement);
public class TestElement : VisualElement
{
public TestElement()
{
Label testLabel = new Label();
Add(testLabel);
}
}``` I'm actually doing this and I can't find my label, even in the debugger I don't have anything under my Element
and i'm generating a mesh inside and I can see the mesh but no label even when I add text to them csharp private void GenerateVisualContent(MeshGenerationContext obj) {}
Make sure you add it to the container too.
So standard workflow for me atm is
VisualElement myElement = new VisualElement();
Label l = new Label("Test");
myElement.Add(l);
rootVisualContainer.Add(myElement);
I don't have anything else than this.Add(); because it derive from a visual element, I'm not trying to do an EditorWindow
I think in order to help you, we are going to need to see all the code for what you are doing. Make it as simple as possible example.
Well, I managed to do it but I had to create my elements inside the init function of this csharp public new class UxmlTraits : VisualElement.UxmlTraits {} to ba able to generate some elements
https://gyazo.com/df8e7abc2a65ef98ca86e5e9ca234ae3
Any idea why this is happening?
label= new GUIContent(label.text + "\tVector2: " + property.vector2Value);
EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
``` (I think this is the relevant code)
In the inspector
The vector2 thing is getting cut off. Just curious if there's something obvious I'm missing :P
oh wait
PrefixLabel will provide you a rect that is an editor label, which is relying on the labelWidth
You can see that it cropped like X & Y
You can trick it by increasing the width manually
https://gyazo.com/eb77d81f36b5ba03929f6e93065fd113 I am happy that I got this to work. Idk if I'll ever actually use it, but I am still happy :P
Is it safe to commit changes for the repository while the Unity project is still open?
I've gotten into the habit of closing Unity and then committing the stuff to GitHub...
Yes
But having you asking this question requires a more appropriate explanation
I'm not very experience with repositories, I just have a basic understanding of them to be able to use them on a surface level
This question is not about repository, but Unity Editor understanding
true
The Assets folder is not suppose to change unless you apply modifications.
Like almost all other folders, except Library, which is used to build your project
When you commit, just make sure to save the project and it should suffice 99% of the time.
Save Project/Saving scenes might change some assets which Unity asks you to do when you close
The last percent is for plugin/script/hook that execute some work when closing.
Which is, in my knowledge, extremely rare.
It should be extremely rare
Nobody does that.
Yeah I'm the type of people who compulsively does Save & Save Project every 10 minutes heh 😅
Every 10 minutes? amateur
@onyx harness thanks for the explanation 🙂
you've saved me precious minutes every time I want to commit changes
If you're using perforce then I suspect there might a bug when you switch streams and Unity does something while it's happening
Which makes your files go into a changelist you can't easily access
I just use GitHub
No worries then
There is a sad and I feel its kinda stupid from Unity.
Most of the time people will "Save" (Ctrl+S) thinking it will save the project, but it only saves the current Scene.
Just give it a try, next time, stage your changes, then exit Unity.
Go to your git and see if there is any new changes
Yeah and for some reason they haven't made a shortcut for the Save Project option
Yeah that's the point, there is no shortcut... -_-
I remember reading somewhere that the Project should auto-save whenever something is changed, but I don't know how accurate is that or if it's true at all
Unity claims that you should never need to use Save Project but that's bs
as you guys said time and time again "the key to Unity is to never trust Unity" 🙃
ah yeah, nothing extra seems to change when I close the Editor. As you said maybe some edge case with a plugin or something will happen, but I guess I'll notice it when it happens (if it ever happens)
Is there an editor dialog popup that has a toggle field for "remember decision" instead of this awfulness?
With EditorUtility.DisplayDialog you can only remember your decision if you select yes. You can't say "no, and remember my decision." I also can't pick the text displayed for the "Do not show this again" option. It's so long and ugly lmao
I'm not familiar with it, but you can always do this manually with EditorPrefs/SessionState
good to know, thanks 🙂
I guess it'd be important to have some way to show a toggle in a popup dialog, since without it I'd have to show two popups: the first which lets the user make a decision, and the second which lets the user say if they want their decision to be remembered.
I'm guessing there's not a way to define my own gui for one of these native dialog windows? I guess I could make my own PopupWindow, but it wouldn't be quite the same
I do not think you can
I don't know if it's the correct place for this question but I was wondering. With the classic UI (canvas, text, TMP, button, ...) we had to split our ui smartly to avoid having to re render everything each to something changed in the UI, is it still the case with the new UIToolkit ?
Nope, not the case with UITK. I don't think it even contains a way you could do something like that.
Anyone know why PropertyField doesn't work in UITK?
I tried using it and apparently it shows up in the debugger but when I look at the style value it is set to 0, and when I set it to anything other than 0 it still doesn't show up.
Also this is for a Custom Editor Window
I have tried for a Custom Inspector and everything works fine
Oh I figured it out I wasn't binding the field to a object
thx
im using unity on linux and i cant use file, rendering, edit, window. ect.
Hey guys it is possible to make own search window for EditorGUI.ObjectField? I use generic typed scriptableobject and it shows everything in the list. However I managed with own code to filter out what types I want to see (in this example int types). I did it with popup but would like to replace the search window.
Hey peeps, how can I access the animation clips in an animator controller via editor code? The Animation Clips field is always empty
I want to access this motion and change a state motion via code
How do I do a bulk reimport of the asset database?
Do you mean like AssetDatabase.Refresh() or AssetDatabase.Save()?
Oooo, maybe it's AssetDatabase.Save @gloomy chasm
Basically I'm editing a bunch of objects at once which I've loaded using AssetImporter.GetAtPath
will AssetDatabase.Save save these objects?
It doesn't matter how you get the objects. An object is an object.
Is there any situation where we would use
SerializedPropertyType.ArraySize
instead of just using directly
SerializedProperty.arraySize
The first one would require to access a sub-property of an array using SerializedProperty.FindPropertyRelative("Array.size")
Am I missing something? Why would someone ever use the size sub-property? 🤔
The second one even seems to account for multi-object editing, which is a plus
digging on the source code, they seem to mostly use SerializedProperty.arraySize.
and SerializedPropertyType.ArraySize only for PropertyFields, clipboard and prefab stuff
It's for when you iterate over a serializedproperty that contains an array, one of the elements will be the array size
ooooh, that makes sense
so i guess for example if I wanted, for some reason, to draw collections in a custom inspector but hiding the size field so the user can't change it manually
or things like that i guess
Yep, it makes it pretty easy to fake arrays by just iterating over the sp
ah yeyeye gotcha. Thanks for the info @waxen sandal 😊
There's some more fun things you can do
If you have a class that you want to draw with a custom foldout, you can skip the first element and draw your own foldout instead
takes notes 📝 👀
Is it possible to add categories to the Unity shortcut system from C#? I am adding shortcuts to a custom tool and it would make it easier to find them.
What are the implications of choosing between the Api Compatibility Level of .NET Standard 2.0 and .NET 4x ? (In the context of editor extensions)
Context:
I'm making extensions that use the Microsoft.Win32.Registry assembly and apparently that is only available on .NET 4x.
The original project I used to make the extensions had the .Net Standard 2.0 selected and I could for some reason still access the Registry assembly.
But after upgrading to the latest 2020.2 version of Unity I can only get that assembly by switching the API Compatibility to .NET 4x, otherwise i get errors
Concerns:
Unity says a bunch of things regarding this topic, while I understand them on the surface, I don't truly understand the potential implications of those things:
Only use the .NET 4.x when you require functionality that is not available in .NET Standard 2.0. The .NET 4.x profile includes a much larger API surface, including parts which may work on few or no platforms.
- .NET Standard 2.0 reduces the size of your final executable file. The .NET Standard 2.0 profile is about half the size of the .NET 4.x profile, so use the .NET Standard 2.0.
- .NET Standard 2.0 has better cross-platform support, so your code is more likely to work across all platforms.
- .NET Standard 2.0 is supported by all .NET runtimes, so your code works across more VM/runtime environments (e.g. .NET Framework. .NET Core, Xamarin, Unity).
- .NET Standard moves more errors to compile time. A number of APIs in .NET 4.7.1 are available at compile time, but have implementations on some platforms that throw an exception at runtime.```
A Unity employee said: ```The recommended solution when trying to use an API that is part of the .NET Framework, but not part of .NET Standard 2.0 is to change the Api Compatability .NET 4.x rather than adding assemblies such as Microsoft.Win32.Registry.```
Questions:
- Why did my original project had access to the Registry class on .Net Standard 2.0? (I had imported some external tools to that same Unity project, maybe one of them imported references to that assembly?
- Should I just switch to .NET 4x and forget about importing DLLs manually?
- If I only use the .NET 4x API features for editor extensions, how will that affect my runtime code and builds?
*sorry for the very long post, I have near zero experience in dealing with this .NET stuff 😓
.NET Standard will have better compatibility if you are building for systems other than Windows.
Or if you switch to .NET 4.x you may use an object or method that isn't supported on another system.
If you're building a normal Unity game, you can get away with .NET Standard 2.0
You only really need .NET 4.x if you need more advanced reflection / domain loading and modification features. And you should only need those if you're building more of an app or something that integrates with certain kinds of desktop features.
Or if you want a pleasant coding experience with modern language features
- some external dlls that aren't unity specific or built against newer versions of .NET (Core or Standard) tend to included more windows-specific things like Registry. You may be able to find an alternative if you just need a key/value store
- If you have the dll that has the Registry somewhere under Assets/, you should be able to access it and include it in your project without needing to manually import it in code.
- if you have a .NET 4x API featureset for editor extentions, but don't want to force a project to use .NET 4.x, you should be able to include specific DLLs with your editor tooling directories and keep the rest of the project .NET 2.0.
It's been a while since I messed with this stuff in a project so Your Mileage May Very
hmmm, I see
however I'm still conflicted with them recommending to switch to .NET 4x instead of just importing new DLLs by ourselves
and for example I just tried importing the Registry dll on an empty project and i get this conflict:
Library\PackageCache\com.unity.ide.visualstudio@2.0.5\Editor\VisualStudioInstallation.cs(57,38): error CS0433: The type 'RegistryKey' exists in both 'Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
I followed this guide from their docs https://docs.unity3d.com/Manual/dotnetProfileAssemblies.html
I don't know why it's not letting me just use my imported Registry dll when using the .Net Standard 2.0 API compatibility level
mscorlib.dll is only used for the .NET 4x API compatibility level
with other external libraries there's no issue, but it's weird that they force use to switch from .NET Standard 2.0 to .NET 4x instead of letting us override assemblies 😓
I tried building an empty project using both compatibility levels and with .NET 4.x the build size is actually smaller (48.7 MB) than with .NET Standard 2.0 (50.8 MB)
which seems to contradict what the Unity docs say... (though the executable files are exactly the same size)
.NET Standard 2.0 reduces the size of your final executable file. The .NET Standard 2.0 profile is about half the size of the .NET 4.x profile, so use the .NET Standard 2.0.
well, I guess I'll just do as they recommend and switch my projects to the .NET 4x profile,
I've seen workarounds online such as modifying the csproj files, but that's pointless since Unity rebuilds those files anyways.
And some other shenanigans like setting some parameters to override references in assembly definitions and whatnot, but those may also cause conflicts with Unity's API compatibility levels...
I've also seen people had similar issues in the past couple years and Unity employees deeming them as bugs, reporting them as bugs , getting fixed and then the "bugs" getting reintroduced in newer versions of Unity 😅
Whenever I try to open a script from Unity to Visual Studio, the following error pops up. I'm not entirely sure what it means.
could anyone help me create an editor for scriptable objects?
My idea is having a scriptable object called Ingredient and have all ingredients in that windows
Have you installed support for Unity for Visual Studio?
Yes, the one on the left should install what you need.
It will optionally install Unity Hub so uncheck that.
making Custom Editors for ScriptableObjects is the same as doing it for MonoBehaviours
My idea is having a scriptable object called Ingredient and have all ingredients in that windows
could you elaborate more?
I was just giving details of what I think
I will send a little sketch if that is fine
Probably what I would aim for is having a list of all ingredients that were created and a button to create a new one
then this could be sorted or by rarity or by name
@tepid yew What do I do after that?
I think that's all it takes. You might restart Unity and VS. Open a project in Unity and the either open a script or create a new one. Then double-click it to open VS and edit it.
Let Unity launch VS. Edit your files there, save them, and when you switch back to Unity it will compile your changes.
@dusty comet if you've never made a custom editor, check the docs for the example https://docs.unity3d.com/Manual/editor-CustomEditors.html
I got the same error message.
I made a very little editor but this is more advanced at least for me, I want to get better at this since this is a very powerful tool
it all depends on the complexity of your tool and the intended use
I'm getting close to just uninstalling VS and reinstalling it at this point. 
Is that the latest version? (2019)
I guess a reinstall won't hurt. I'm not sure what the problem might be.
.NET is installed, right?
There are other places to find tutors, this is not one of them
ok
I can't remember.
I'm pretty sure that all you need are .NET and the Unity package (which basically just installs a particular version of .NET framework.)
Before I go on, what boxes should I check off? @tepid yew
game dev with unity and .net package I assume
@patent pebble sorry for bothering but have you seen a video of someone that did a custom editor for a character?
a custom editor for a character that is very vague. You wouldn't usually make a single custom editor for an entire "character", unless you have a very simple character. You'd make custom editors for components or scriptable objects
unless by "editor" you mean a tool for handling and editing whatever data relevant to your character
I remembering that I saw a video and maybe you had seen it, I wanted to see how they did it and try to see how I could have done mine
I have looked for it but I can't find it
no idea, good luck with your search 👍
Oh found it, it is from unity
i made lot of search but i couldn't find the right information about that part, what i'm trying to find is what is the right type for RuntimeAnimatorController, do you know how or where to find the right information about it?
it's for an objectfield with the help of ui builder
Can you clarify
i mean: when i click the objectfield in my script, i get a list of everything, what i want is to find the specific type like RunAnimatorController when i select one of these objectfield
i want to see only these:
when i tried, i got this
even when i put only AnimatorController
it's really frustrating when there is only vague information about how to do it
especially in the documentations
I'm not sure what format that string is supposed to be in but assuming it's using type.GetType then your input is saying UnityEngine.Object in the UnityEngine.AnimatorController assembly
that unityengine.object was found from the documentation about binding path
which i was able to figured it out
however, i had no idea what is the right information related to animatorcontroller
hum
i noticed that it only select animatorcontroller instead of runtimeanimatorcontroller...
because in my list, there is also OverrideController as files
Try UnityEngine.RuntimeanimatorController and nothing else in teh type field
Typo
Try UnityEngine.RuntimeAnimatorController, UnityEngine
@idle anvil No reaction gifs/off topic embeds.
ok
Anyone know how can we create this kind of editor windows?
IMGUI or UIToolkit
Which part are you having trouble with?
me?
Yes
Oh you mean built in EditorGUILayout
well I know about that but I couldn't manage to make that fancy elements in that UI. For example those toggles . How about those?
I suspect they must exist natively
That's a good idea too
Since I saw Services using it
That's what I have been trying to find cuz EditorGUILayout.Toggle only gives that check box kind of toggle
Yeah, pretty lame & basic one 🙂
True. Does that sliding toggle have a specific name of it?
I think services is not an editorwindow
It takes ages to load so I feel like it's some web view or something
Web page? Hum... Since they removed the Web container since UPM, how would they render it?
I haven't checked what it actually is but I'm skeptical it's a normal window
I agree, I remember something like that too
Yeah it could be rather data being fetched from web server
@onyx harness do right click and you'll see it's a browser
Perhaps I will go with gui skin option. Thank you for advice
U2020?
Yeah, drawing a simple image is by far the easiest wazy
One more question, how to enable disable a part of code based on toggle like I have seen this thing in some assets that when you turn on toggle of some feature, unity starts to compile and its probably compiling the code of feature you enabled. So how to achieve that?
That's what I am gonna do 👍
I guess it might change the defines
Scripting define symbols?
Yes
shit wrong answer
Thought so
Still stuck on 2018 😂
I see it as GUI
Ah they rewrote it then
Any example of its use? What I am trying to achieve is that I am making an asset that has an editor window that can provide an easy setup to multiple ad networks or a mediation network. User can turn on which ad network he wanna use. So I was thinking to let unity compile either admob or FBAN code only if toggle is turned on. Hope it makes it clear
Yeah, because the Web container is no more later
Oh that's harder, since you don't control the code
Toggle pure plain code, or toggle assemblies?
I am not sure that is why I asked. Perhaps, this feature exists in easy mobile pro asset too as I shown above
Well we can't tell without seeing it
Probably because they control the code
Turned on advertising, unity is compiling
And turned on an ad network and then again compiles
What code are you exactly talking about?
Ah nevermind, they support third party plugins
But it's likely that they're just removed and adding the code
Yeah I guess its like they remove/add or enable/disable code. I basically wanna achieve same thing
Then just delete some directories when it's disabled
for third party plugins we have to download on our own
Its just like they add code to show ads from that ad network
like if you turn on google ads, it will put the code that handles bringing an ad on the screen
Without knowing more about that plugin we can't really know what it's doing
Anyone know what the size range slider is for the Tree-Shape-Size is called?
https://gyazo.com/7d55a8ca24e4e23a6d352cabc7ffaf17 It's like a range in a range-
oh nvm
How do I make it so my external files can be defined as a custom asset type? I want them to recognized by Unity's features like searchbars and whatnot.
First time dealing with assets, I'm creating a text file to store some JSON but I just did it in a crude manner with File.WriteAllText and then just AssetDatabase.Refresh to make it appear on the project window.
I suspect this is not the most robust approach 😅
Right now Unity sees the file's asset type as a DefaultAsset, I'd like to have control over that
Scritpedimporters
thx! will check them out 😋
Yay https://gyazo.com/bcf746fe8cbdee53e0d637a692697ae5
Uses a custom struct and drawer. Default is an absolute max of 0 and 100. but can add an attrbute to allow for better percision, and wider/lower ranges
Hello was the debug label :P
oop wait-
[RangeFloat(-100, 200,0.01)]
public FloatRange Hello0;
[RangeFloat(-100, 200)]
public FloatRange Hello1;
public FloatRange Hello2;
first has an accuracy of .01, 2nd has an accuracy of the lowest log 10, divided by 1 (so 1) and last is .01 b/c default is 0-100, and 0 log10 is 100- (it's actually NaN, but it then treats it as if it's a 1)
I'm just rather happy, so sorry if I'm bein weird :P
For an editor tool are there any conventions are modifying files not managed as assets in the project, such as project settings, or the manifest.json file in the packages folder?
The manifest might not be considered as an asset, but any other yes
Hi, I am wondering if it is possible to implement my own custom directory in editor. e.g. view whats inside a 7z file without having to decompress it
I'm not sure what you mean by a "custom directory". As far the 7z thing, if it is possible in c# then you can do it in Unity (unless it is using a new language feature).
e.g. if there were a 7z file in the assets folder be able to access it as a directory like a normal folder.
Ah, no that would not be possible because Unity needs to be able to access the files in-order to make UnityEngine.Object counter parts for them in engine.
Haha well, never done that, but I might take the risk to say yes it is possible.
Unfortunately, it might work only one level
Yeah, I am looking into it now. I have found out how to edit the project window so its go well so far 😄
The other approach is just to write an Editor for compressed files
And do it in the Inspector, instead of Project
That is my fallback option. I am going to end up doing it for something like 20 different file types so it makes sense to do it in the project window(at least to me it does).
Sorry to break it down for ya, but the Inspector makes more sense :)
There's some APIs on AssetDatabase to add an extra dir (assuming similar to Packages) but no clue how that works in reality
Which one?
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void RegisterAssetFolder(string path, bool immutable, string guid);
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void UnregisterAssetFolder(string path);
Type : public sealed class UnityEditor.AssetDatabase
Unity Doc
Versions : 3.4.0f5 ⟩ 2021.1.0b6
Method : internal static RegisterAssetFolder()
Versions : 2018.2.0f2 ⟩ 2021.1.0b6
Nice embed
Oh from 2018! Never noticed
Nice catch
(I think I can genuinely say you are the very first user using the embed 😄 congrats!)
🥳
Thats a really cool embed, and frature, I have uses for that myself
@waxen sandal Well I'm sorry, apparently you are 2nd nonetheless! 😄
rip
Hey guys how do i validate when player press this maximize button in code?
There is no callback as you might hope
But you can check that by verifying the size of the main view with the resolution, and make some approximation
What's a good way of storing data for simple editor extensions?
I'm making a tool that needs to keep track of a couple of file names, and I need that data to be tied to the project.
I thought of using EditorPrefs since the tool is very small and simple... but EditorPrefs are global across every project
is it bad practice to use the EditorPrefs for project-specific data?
oke, thx 🙂
For project-specific data I believe a lot of editor tools use ScriptableObjects
Yeah, but I like the seamless aspect of the Editor Prefs
and while my data is mostly project-specific, it could benefit from sharing small pieces of it
I'm still designing it, but seems like that's the case
I don't know your tool - but you should consider what happens when a project is worked on by multiple people
and how EditorPrefs won't be shared between them
this tool is only for myself
but if it was for multiple seats, I'd like so each person could set up their own
👍
I'm making a tool that lets you specify custom text file templates for scripts, shaders and other text files
so I store keys for the names of the templates, those can be reused by multiple projects
and I store a key for a "project ID", which defines what templates a specific project uses
probably not the best design, but seems to be fine for what I need
If I keep extending this tool I will probably do a more robust design, probably with scriptable objects or json files
but for now EditorPrefs seem fine
what seems to fit well with the EditorPrefs is the fact that they are shared across every project, so I won't need to import new templates for every project whenever I create a new one
Fyi, editorprefs isn't saved per project
yeah, that's why I said EditorPrefs are global across every project
Ah I missed that 😛
Is there any Unity API that can give me a callback for when I edit a file outside of Unity?
For example if I edit a custom JSON text file outside of Unity on the notepad
Yeah it'll be imported
But no guarantees when it happens when Unity is closed
There's also one that happens on save asset
AssetModificationProcessor
static string[] OnWillSaveAssets(string[] paths)
hmmm
So you mean the callback will not be immediate after opening Unity?
I just have no idea whether Unity will call your code when importing changed assets upon opening
Nor do I rely on it in my code
hmmm I see. I can live with that. As long as it's consistent while Unity is open i'll be happy
Ehh, I just figured out that I'll have to check whether it works when opening Unity
Well, I guess I could away with not doing it but it would be better
He is talking about outside file, implying outside Unity project?
I'm not on my work station, otherwise i'd test its behaviour
really?
big sad 😓
I'm reading it as a file in the unity project but edited using a 3rd party tool rather than somethign in Unity
yes
It only react to stuff aftr your root
This is what I thought
but he just confirmed the opposite
I'm confused now
If the file (inside the project) has been modified, Unity will import it yes.
yeah it's a file that exists inside the unity project, but needs to be edited by external tools, eg: the Notepad
it's a non-native file though, can I get away with not implementing a scripted importer?
or do I need to do that in order to get Unity to recognize and do auto-reimports and all that?
Just use OnWillSaveAssets and do whatever you wanna do from there
Like Navi mentionned earlier
If the file is not recognized, it is suppose to act like a "default asset"
Still an asset
As a test, just create a file ending with .foobar
Look at the logs
Edit the file.
Look at the logs again
You should see Unity importing it
ok, not at work pc right now, but I'll do that to check when I get the chance
Just checked, it'll also call your importer when it's changed when Unity was closed
how to call slow updates for editor script ? i remember there was something that would get refreshed 10 times per second or something like that , any one knows ?
OnInspectorUpdate
found it OnInspectorUpdate
yea lol thanks
any ideas how to make it Editor accesible as well ?
seems to be used for Window
Nop
:< back to haxs
is the current version of ui builder broken?
i just freshly installed the package and im getting 276 errors
ah fuck I'm on 2019 lts
so editor code doesn't compile in the build right? As in there is no need to wrap it in #if UNITY_EDITOR
You should wrap it
Well
Unless it's entire files in the editor assembly
If you have parts of runtime files that are editor only, wrap it
Hey guys. I have a ScriptableObject that I want to use to persist my data.
I check if it exists using AssetDatabase.LoadAssetAtPath<AppData>(dataPath). If it doesn't, I AppData appData = CreateInstance<AppData>(); and then AssetDatabase.CreateAsset(appData, dataPath);
Now, when I use the data from there it works, when I change the data on the UI, it changes it to the SO. And even persists between play/edit sessions. However, when I exit the editor and load it back up...the data is reset to default. How can I get it to persist across editor sessions?
Oh i got it to persist between editor sessions. Before AssetDatabase.SaveAssets(); line I added EditorUtility.SetDirty(appDataAsset); And it works. But is that supposed to be like that? I mean convention?
@quaint zephyr
SetDirty: Unity uses the dirty flag internally to find changed assets that must be saved to disk.
SaveAssets: Writes all unsaved asset changes to disk.
my understanding is that if you don't mark objects as dirty, Unity doesn't know if it has to save them to disk
I'm aware of this in a CustomEditor environment. But to call this in my MB scripts or directly in the SO...is that right?
I'm of course wrapping them in UNITY_EDITOR directives.
I mean, that's just a design or architecture decision
as far as I know, you can mark objects as dirty from anywhere
Ok. Thanks.
whether that's a good practice or not, I can't say. I'm not the most experienced in this topic. Somebody else may be able to give you a better answer
Yeah I have two modes. Production mode saves all the SO to json format on the persistentPath. And Development mode saves all SO directly into my assets folder so I can view the entire structure live and change it on the go.
I mean personally I like to keep things decoupled as much as I can
if your MonoBehavior component should be responsible for handling the data persistence, that's fine
that depends on your particular situation
I would probably separate the concerns there, if your component doesn't care about how, why, or where the data is saved and stored, maybe you can just make the component send a notification so an external system can handle the data saving
it all depends, can't answer that question for you
I'm not a big fan of using UNITY_EDITOR and including Editor-only code in my runtime code, but I see a lot of people using it
^
is there a way for me to apply a certain set up that I want for an array, and then update it to where the array instances function like the setup? I can't really explain it well; im adding comments to my script so i can show what im talking about
im learning and testing, so please pardon the noobiness and tell me if i need to send anymore screenshots
Sounds like you want to make a propertydrawer for the type that is in your array
i believe so? is that a variable I can make or just what that's called?
A propertydrawer lets you define how to draw a field of a specific type (or the elements in an array)
You can make one by inheriting from https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
And you need an attribute on the propertydrawer class [CustomPropertyDrawer(typeof(targetType))]
Then you can draw your gui in public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) and you need to define the height of your drawer in public float GetPropertyHeight(SerializedProperty property, GUIContent label);
thanks for pointing me in the right direction! i literally spent hours both searching and trying random stuff
You can't use GUILayout in serializedproperties by the way
And it's recommended to use SerializedProperty for everything
@visual stag Can you take care of that?
@mortal hinge do not post off topic content - consider this a warning (the bot cannot DM you the warning formally)
Thanks
Wait, EditorGUILayout doesn't work but GUILayout does ??
Noted. I also found a video explaining it also
Next time I’m on unity, I’m gonna make some form of unholy abomination of a mixture of the editor and drawer inspector fun 😄
Does anyone know an API point that happens before default hotkeys are dealt with? I need to capture key presses and consume the events before editor hotkeys.
Its for an EditorTool so I tried EditorTool.OnToolGUI. I also tried duringSceneGUI. Both happen afterwards
Type : public sealed class UnityEditor.EditorApplication
Unity Doc
Versions : 3.4.0f5 ⟩ 2021.1.0b6
Field : internal static globalEventHandler
Versions : 3.4.0f5 ⟩ 2021.1.0b6
GitHub Source
But I'm not sure it can intercept the event before Unity executes
The doc link is fine, since it targets the Type. But yeah the github is wrong, I don't how why it points to the layout
I'd argue there shouldn't be a docs link if it's internal but 🤷♂️
It's because when both Type & Member are public, I provide 2 links
Type : public sealed class UnityEditor.EditorApplication
Unity Doc
Versions : 3.4.0f5 ⟩ 2021.1.0b6
Method : public static Beep()
Unity Doc
Versions : 3.4.0f5 ⟩ 2021.1.0b6
GitHub Source
Like this
and of course the 2nd does not link correctly XD
😂
I was talking about the page and not the embed though
Which in this case also points to editorapplication
Same for the page, it has a doc link for the Type, and a doc link for the member if public
Not the most intuitive, but consider the 2 things, 2 separated entitties
Ohh you can press on the name, I was just pressing on the icon
And the link issue is fixed. Now investigating why GitHub is so wrong
Good work as always
Thanks so much! Works great 😄
By curiosity, how did you implemented this globalEventHandler?
https://stackoverflow.com/questions/3229449/assign-method-to-delegate-through-reflection
Accepted answer here
However, I havent yet found out how to unassign it 😛
is this still true about JsonUtility?
Serializing/deserializing arrays and lists as top-level elements is not supported right now. It's on the to-do list...
Should I just give up on JsonUtility and get accustomed to JSON.NET or Newtonsoft to save me some pains?
The trick is to wrap the string with {}
@onyx harness so basically just instead of top level I need to wrap everything?
I wouldn't recommend trying to use json.net in unity
It works, but sometimes it doesn't, so you have to deal with quirks regardless
I assume i need to do the same with my objects? wrapping them into classes before serializing to JSON?
I had this discussion a year ago with the Unity engineer behind the serialization
My opinion? They will never implement X)
Yeah its a little annoying
No, just before you deserialize, to comply to Unity
I've been googling and there seems to be a gazillion different implementations of JSON.NET for Unity and every time I read someone saying that X implemenation has X quirk, this one doesn't support quaternions, the other one doesn't work with some things...
Exaclt, with jsonutility you have a rule set you're already used to
Or perhaps more importantly, is consistent across unity, where external libs won't be
You'll have this quirk, unity obviously deals with it too, just look at Packages/manifest.json
I'm a bigger fan of consistency, even at the expense of having to do some boilerplate stuff
I'd rather spend a small amount of time automating something to save me time from doing boilerplate, instead of having to face massive headaches and wastes of time figuring out if the library I imported is going to work or not, and digging through docs and forums to figure out what to do to make it work
specially in my situation, making indie games and simple tools for my own workflow
and im back
is it possible to display variables based on an enum selection in a PropertyDrawer? I know i can in an Editor
Has anyone tried to extend the package manager?
I want to setup some custom registry sources that require some special handling...
The more I say the less I think the idea is feasible, but I'm building my own manager and its basically the exact same thing except it loads data from an extensible set of sources which will handle everything except the actual management of package.json files and putting the files in the right locations.
It seems like it should be possible to actually extend the package manager itself, but the documentation isn't exactly helpful
there is a IPackageManagerExtension but what it doesn't isn't clear at all
There is also PackageManagerExtensions which has a ```cs
public static void RegisterExtension(IPackageManagerExtension extension)
method.
yeah, the issue Is I don't really get what the purpose of this extension class is
I suppose what I should really do is setup a scoped registry
Meaning like, host a scoped registry within unity that translates the registries I want to add
My guess would be you call it in a InitializeOnLoad method. Also, I found this github where someone uses the API https://github.com/mob-sakai/UpmGitExtension
oh this is almost exactly what I want to do
oh this is jsut showing me all kinds of cool stuff, like OpenUPM
Do you happen to know if there is any easy way to get a grid view with the ListView? I want a grid like in the project browser, but I want to be able to have the reusable items/performance like what the ListView has.
AFAIK grids are still a real problem
In the sense that Unity doesnt' create support to build a grid
I suppose making a Grid control might be considered design breaking though
I got a grid working pretty easy with just row and wrapping.
But that doesn't work with a listview of course
Are you trying to make a data table?
Not really, I am trying to make a 'asset library' window that sort of mimics the Project Browser, but it is just for making like collections of assets and stuff. Allow for organizing assets without changing their file location.
If you can evaluate how many items per row there can be then you can group the backing data into rows for a ListView
Honestly though this is a problem I've faced in WPF and it gets pretty hard
Yeah, I was thinking of that, but when resizing horizontally, all the items would need to be looped over again :/
I'm confident you could be smarter than looping over all the items, but yeah it's non-trivial in general
this is a place where Retained mode loses to imgui, virtualization is trivial with imgui
track the starting point, calculate the space available vs the size of the items, and render only that which fits in the screen looping from the tracked index forward
you can theoretically do the same in retained
if you accept that your reverse scroll might be somewhat invalid and have to figure out how to fudge the edges of the scroll
Yeah, I was just thinking that could be a way to do it.
This is how I do my virtualization in imgui for my tool, but thats a much simpler setup admittedly
its not effectively a virtualizing wrap panel
Also, don't feel bad, this is actually a fairly hard problem in general it seems
Hey @severe python do you know if there are any callbacks or anything for when the layout changes? Specifically I want the horizontal layout.
I don't know, but you can possibly find out by putting a custom VisualElement in your tree with ExecuteDefaultActionAtTarget implemented and then see what the events are.
I use something similar to handle unexposed events here:
https://github.com/PassivePicasso/VisualTemplates/blob/master/Editor/ContentPresenter.cs#L190
Alright, cool thanks!
Hello, not sure im in the good channel tell me if not i will change, i have this problem :
Someone now can i solve that ? i need to add a using no ?
Are you trying to use UnityEngine.Random or System.Random
You can't instantiate UnityEngine.Random (it's static), but you can with System.Random
@severe python I THINK I DID IT! Well at least the layout part of it!
https://streamable.com/8mi0pp
It was actually pretty easy to do. All that is is the ListView basically (thus the good performance)
But what I did was make a custom class that implements IList that that makes rows for the items and set that as the source for the ListView
public struct GridRow<T>
{
public List<T> items;
public int sourceIndex;
public GridRow(int sourceIndex, List<T> items)
{
this.sourceIndex = sourceIndex;
this.items = items;
}
}
public class GridCollection<T> : IList<GridRow<T>>, IList
{
[SerializeField] private List<T> _items = new List<T>();
[SerializeField] private int _perRowCount = 5;
public GridRow<T> this[int index]
{
get
{
int startIndex = index * _perRowCount;
return new GridRow<T>(startIndex, _items.GetRange(startIndex, Mathf.Min(_perRowCount, _items.Count - startIndex)));
}
set
{
for (int i = 0; i < value.items.Count; i++)
{
_items[value.sourceIndex + i] = value.items[i];
}
}
}
}
I'm going to be honest, I feel very clever and smart for coming up with this xD
Btw @severe python there is a GeometryChangedEvent which is sent after layout events. I use it to do a simple evt.newRect.Width / _itemWidth to get the number of items per row.
I just gotta see if I can override/disable some of the default behavior of the ListView to get it to actually function with selection, hover, arrow key etc.
I need to try using ListView again, I didn't like it before, but my templating control has problems
Does anyone know how I can assign a Converter for a key on a Dictionary<key, value>? I'm using Newtonsoft.Json
Has anyone run into issues with choosing a sorting layer from the dropdown? I'm trying to assign objects to different sorting layers and literally nothing happens when I select a different sorting layer. It just continues to say Default
do you have custom code drawing the dropdown?
This channel is about extending the editor, general editor stuff is still #💻┃unity-talk
Thank you
trying to make a custom editor window, i have this code but it comes out blank when i open it:
public class FourierEditor : EditorWindow
{
private WaveFieldSettings _waveFieldSettings;
[MenuItem("Window/Spectrum/Generator")]
static void Init()
{
var window = GetWindow<FourierEditor>("Spectrum Generator");
window.Show();
}
void OnGui()
{
EditorGUILayout.BeginHorizontal();
_waveFieldSettings = EditorGUILayout.ObjectField(_waveFieldSettings, typeof(WaveFieldSettings), false) as WaveFieldSettings;
EditorGUILayout.EndHorizontal();
}
}
What is going wrong here?
i was following this https://docs.unity3d.com/ScriptReference/EditorGUILayout.ObjectField.html
its pretty similar - their code worked but mine doesn't
OnGui 🤔
its what their docs has
no it isn't
ah god damn
OnGUI not OnGui
There is not
i'll just put the array in a scriptable object and have the editor execute a function for the SO to do the job instead
if it's serialized you can just use a PropertyField
hmm im a bit lost my editor creates a Texture2D and i try to assign it to my SO but it says type mismatch when the field is a texture2D
i don't know what means
seems custom editors can't generate data or images for SOs or something
When i press "Generate" gui button it calls this function:
private void GenerateInitSpectra(WaveSpectra waveSpectra)
{
Texture2D texture2D = new Texture2D(Resolution,Resolution,TextureFormat.RGBAFloat,false);
texture2D.filterMode = FilterMode.Point;
texture2D.wrapMode = TextureWrapMode.Clamp;
texture2D.anisoLevel = 0;
texture2D.name = waveSpectra.Label;
waveSpectra.SetTexture(texture2D);
}
waveSpectra is my scriptable object.
After pressing it, the SO inspector shows this:
is that a custom inspector for the SO?
thats the default inspector
its got the correct type too:
[SerializeField]
private Texture2D _initSpectrumTexture;
is SetTexture just an assignment?
yup
public void SetTexture(Texture2D texture2D)
{
_initSpectrumTexture = texture2D;
_isSet = true;
}
sets a flag so i don't do it twice but other than that its all it does
I wonder if it's just because you haven't written the texture to the asset database
im not familiar with asset database
you saying it needs to be a physical asset on my hard drive first?
Well, I don't know if SO's can straight up serialize assets which are not in the asset database
you can serialize stuff into the scene in some cases
but I don't know if SOs have that ability
oh so i have to save the texture as a file
thanks
using UnityEditor;
using UnityEngine;
[CreateAssetMenu]
public class Test : ScriptableObject
{
[SerializeField] private Texture2D texture2D;
[ContextMenu("Create Tex2D")]
public void Create()
{
Texture2D texture2D = new Texture2D(36, 36, TextureFormat.RGBAFloat, false)
{
filterMode = FilterMode.Point,
wrapMode = TextureWrapMode.Clamp,
anisoLevel = 0,
name = "Texture2D"
};
AssetDatabase.CreateAsset(texture2D, "Assets/Texture.asset");
Undo.RecordObject(this, "Assigned Texture");
this.texture2D = texture2D;
}
}```
This works. Without creating the asset it does not.
oh it has to be .asset format
i need to learn more about this asset database stuff
@visual stag does it have to be .asset or can i use any thing ?
I don't think it can be anything else
Unity won't recognise it needs to import it otherwise
I'm trying to display the text of a meta file for an asset in an Editor Window
but can't figure out a way to load the file
any tips?
SerializedObject
ehm... sorry but I don't get it
here's my code
_obj = EditorGUILayout.ObjectField("Select asset to inspect its Meta file", _obj, typeof(Object), false);
if (_obj != null)
{
string path = AssetDatabase.GetAssetPath(_obj);
EditorGUILayout.LabelField($"Path: {path}");
Object metaFile = AssetDatabase.LoadAssetAtPath(path + ".meta", typeof(Object));
// ...
}
I don't know how SerializedObject is supposed to help me 😅
From what I remember, loading a .meta wont give you anything
You have to load the real asset, and iterate internally using a SerO
oh, this seems to work
string metaString = File.ReadAllText(assetPath + ".meta");
EditorGUILayout.LabelField($"{metaString}", GUI.skin.textArea);
gonna try with SerializedObject
Is that serious?
I mean, do you want to properly display the content, or just display the content?
properly display the content sounds better
@onyx harness how can I load the external file so I can use it in a SerializedObject?
I'm very inexperienced in dealing with files and assets, and can't find much info online
because I don't know the proper words to search 😓
maybe File.OpenRead or .Open?
Load the asset using AssetDatabase.
Wrap it with new SerializedObject(asset)
Iterate over the SerializedProperty
And you might need to turn the SerO to internal mode to iterate over everything (including "hidden stuff")
oh i see
doesn't seem to work. i tried iterating over every property in the serialized object, but none seem to have anything to do with the meta files
unless I'm doing something wrong
As an example
Do you see the icon assigned to the asset?
You have no API (to my knowledge) to modify it
The only way I know is to go through the SerializedProperties and change it there
Even though you use the SerO, the SerializedProperty won't show everything (The icon is hidden)
You have to enable the internal mode
How do I enable the internal mode?
I tried searching online but "internal mode" gives me no results
nothing on the source code either
PropertyInfo inspectorModeProperty = typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);
inspectorModeProperty.SetValue(serializedObject, InspectorMode.Debug);
ah right, reflection
I still don't think that has anything to do with the actual meta file of the asset though
Certain information in the meta can only be accessed through this technique
like the icon
Otherwise, I dont know
I think all the meta file stuff is handled in the UnityEditor.VersionControl API
but I'm not sure, there's virtually zero documentation on meta files
Anyone know why a nested ListView wouldn't execute its MakeItem and BindItem methods?
this is the code I'm executing that has the issue
I discover 2 ListViews, once in the OnRootPresenterAttach, which sets up the ListView, the packageSourceList, which correctly invokes MakeSource and BindSource
however, MakeSource also adds an AttachToPanelEvent which executes the OnSourcePresenterAttach, which executes basically the same code except it discovers the itemSource differently
Okay, this is unexpected, after reviewing the UnityReferenceSource for unity 2018.4 (I don't know if its changed since) the problem was that the ListView didn't have a height that could support adding children, which was unexpected
In hindsight, I guess it makes sense since its a virtualizing control
I'm trying to make an editor script that does this. Does anyone know what this is called?
Definitely looks like a treeview, but I can't tell whether this dropdown/search structure is built into Unity of whether it's particular to the localization package. I'd like to avoid making my own if I can.
It's not
but it's pretty easy to do
Just show an editorwindow as popup iirc
So
ScriptableObject.CreateInstance<window>().ShowPopup();
I am making [MenuItem], I understand how to use them for the most part, validation, etc. But I don't know how to have them selected. Like a check mark next to the menu item.
I dont think we can
oh no!
@waxen sandal That's insightful - thanks!
Ok, is there a way to dynamically change the MenuItem's label then?
Nothing that I know
MenuItem is compile-time.
But you can try Menu, it provides some tools:
https://ngtools.tech/uv/UnityEditor.Menu/
Type : public sealed class UnityEditor.Menu
Unity Doc
Versions : 5.0.0f4 ⟩ 2021.2.0a5
Ok, maybe you can throw some ideas at me? I have a few states that the app can be in while it is open in Editor (for development purposes). Currently I am controlling which state is active via a prefab in the Resources folder. (This prefab bootstraps itself to any scene when you load and takes care of all the core features, input, resource pooling, data control, etc.
I want to create something that I can control globally, like a menu item in this case, where I can I just go to "App -> Mode -> WhateverModeINeed" and it will then update the prefab in the resource folder by itself without me having to navigate my way to it. Also I would like somewhere easily accessible I can see what mode it is in without having to navigate to the prefab.
But since I can't "check mark" the menu item or change the label dynamically. I was wondering if you might have an idea of where else I can implement this without too much coding 😛
You can have toggle menu items in a GenericMenu but you'll have to figure out how you want to invoke the GenericMenu
You could invoke it from a MenuItem and it would be similar to having a submenu
I'm afraid I'm not yet familiar with GenericMenu?
I just told you about the API Menu
What else do you want?
Look at the doc first, then come back
Thanks
Your embed doc link seems to be broken mikilo?
oh crap...
Hum, it's not not working, just there is no doc for API Menu (I don't check if every single link is functionnal)
But here is the API with some comments
I went ahead and just "disabled" the one that is selected for validation. 😛
Gut gut
Here is a more recent version of Menu (2019.2)
As you can see, you can Add/Remove MenuItem dynamically
And I tested it, it works, few bugs, making not 100% reliable, but it works
oh man, why can't that stuff be in 2018
March is coming, LTS 2018 dropping soon 🙂
Meaning they are not supporting it anymore? Doesn't really matter for me unfortunately, my efforts currently are around existing games
Making a package manager has been a fun project though
Stupid word wrapping
Well, just mean publishers will be pushed to support latest stuff
Meaning I will drop it as soon as I can
I can't blame you
What are those?
I wish I knew lol I haven't looked to figure it out yet
any one know how to get this to update the image preview every time the image data changes:
public override void OnInspectorGUI ()
{
Fourier myTarget = (Fourier)target;
DrawDefaultInspector();
var texture = AssetPreview.GetAssetPreview(myTarget.H0T);
GUILayout.Label(texture);
}
Currently its just showing a snapshot even tho the image is constantly changing every frame - i want a live preview
what does the aPI versioner do?
tells you what versions have an API present
Hello there, I am currently working on an editor script for the following class
public enum ActionType { ForegroundCleaning, CG, Sound, Null }
public enum Position { Left, Right }
public class DialogActionHolder : ScriptableObject
{
public DialogAction[] actions;
}
public class DialogAction : ScriptableObject
{
public virtual ActionType GetActionType => ActionType.Null;
public virtual void Run(DialogModuleUI dialogModuleUI) { }
public class CGAction : DialogAction
{
public bool shouldSet;
public Sprite sprite;
public CGAction(bool shouldSet, Sprite sprite)
{
this.shouldSet = shouldSet;
this.sprite = sprite;
}
public override ActionType GetActionType => ActionType.CG;
public override void Run(DialogModuleUI dialogModuleUI)
{
if (!shouldSet || sprite == null)
{
dialogModuleUI.CG = null;
}
else
{
dialogModuleUI.CG = sprite;
}
}
}
public class SoundAction : DialogAction
{
public AudioClip audio;
public SoundAction(AudioClip audio)
{
this.audio = audio;
}
public override ActionType GetActionType => ActionType.Sound;
public override void Run(DialogModuleUI dialogModuleUI)
{
dialogModuleUI.SoundFx = audio;
}
}
public class ForegroundCleaningAction : DialogAction
{
public Position[] foregroundCleaning;
public override ActionType GetActionType => ActionType.ForegroundCleaning;
public ForegroundCleaningAction(Position[] foregroundCleaning)
{
this.foregroundCleaning = foregroundCleaning;
}
public override void Run(DialogModuleUI dialogModuleUI)
{
foregroundCleaning.ForEachEnumerable(dialogModuleUI.CleanAtPosition);
}
}
public class DialogActionHolderEditor : Editor
{
public override OnInspectorGUI()
{
}
}
I am using an array to store all the different DialogActions by their base class
And I am having trouble on getting the fields of each child class
This **DialogAction ** scriptable object was originally an interface however I can't get unity serialize it correctly
Afterward I change the interface into a regular class, this time the unity can serialize the class however I am unable to either obtain the reference to base class nor determine the type of children class
That is because Unity can't serialize interfaces unless you use the [SerializeReference] attribute, there are some caveats to it though so read the docs on it if you want to use it.
That also goes for any sort of polymorphizium.
Bringing this one up again. I tried using EditorWindow.ShowPopup but it doesn't seem to work like this does. It just seems to present a window in a very normal fashion. I'd like the window to show up without a tab, maximize or exit buttons, just a little dropdown tab as is shown here. Is there something more like this, or am I just using the ShowPopup function incorrectly?
(Red box is sensitive info, disregard.)
You need to set the min/maxSize
Chances are you're doing show then showpopup
ShowPopup is not enough to display as a borderless window
@tardy sorrel Also, you must create the window using EditorWindow.CreateInstance<>(). Not using GetWindow<>().
I did switch to CreateInstance. If ShowPopup isn't sufficient, would something else work?
Can you show your code?
It is not enough alone
