#↕️┃editor-extensions
1 messages · Page 49 of 1
if you want a system to automatically load UXML for a window absed upon a naming shcme the solution is simple
Make a base class with the necessary data you need to automatically load stuff based upon whatever metric you want
using System;
using UnityEngine;
using UnityEngine.UIElements;
public abstract class AutoTemplate : VisualElement
{
public AutoTemplate()
{
RegisterCallback<AttachToPanelEvent>(LoadTemplate);
}
private void LoadTemplate(AttachToPanelEvent evt)
{
Resources.Load<VisualTreeAsset>($"{GetType().Name}.uxml").CloneTree(this);
}
}
just create a resources folder in an Editor path somewhere to store all your templates
this code may not specifically work
I suppose where the name is you also need the path
generally, hence why I mention using Resources
I like the idea of the base class, gonna look at addressable to avoid path or a common folder
heh, made this as an example for you, and I'm probably going to end up using it tonight
please let me know what you figure out with Addressables, if there is a way to make the pathing situation better, than that's awesome
If addressables can be used in the editor, then it seems like it will provide a huge amount of capability for this goal
IIRC it will
the WYSIWYG UI editor is coming out with the next major version right?
You can always use the UI Builder
the what? Do you mean the UI Elements Builder they just announced?
oh well heck, I didn't realize It was available
Can't seem to load a USS file for a given control however
Nevermind, you can if you follow their naming scheme
With that and an auto editor load, making editors could be really easy
Although i'm not a big fan of linking logic with buttons using their names
?
There is a distinct lack of Code behind support or connecting the UI to logic
right now that connection appears to be 100% driven by code
I'd prefer having a public UIElementReference or something like that
So you can bind whatever you need to it
Rather than having to use a Query to find anything
That's what at least i've seen
No idea if there is other way of doing it
Anyone figured out how to make TextMeshPro.Buttons react to anything other than the main button on a controller or like "right click"?
Do I have to build my own script completely or is it possible to use the built in features to add another interaction button?
Welp, I made a generator for VisualElements for all the Unity.Mathematics types...
lets see if they actually work
Okay, so this works pretty well, but there are some problems
First, I can't see how to instantiate a Template element and an Instance element from code, I'd guess its not possible and they expect you to use VisualTreeAssets, this makes things a ltitle wierd
the UIBuilder helps with this problem a bit, since all you really have to do is create a custom inspector class which loads a visual tree for the inspected type, and as long as the XML there is implemented correctly all the binding path stuff works
However, I don't see how you could render lists using this setup
Okay, so this works pretty well, it requires some annoying boiler plate, maybe there is a way around that.
All I have to do to setup a custom UXML driven inspect for a type, for example:
public class TestType : MonoBehaviour { public float3 Test3; public float3x3 Test3x3; }
Is instantiate this class
[CustomEditor(typeof(TestType))]
public class TestTypeEditor : AutoTemplate<TestType> { }
Create this UXML
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
<ui:Template name="Double3" src="Double/Double3.uxml" />
<ui:Template name="Double3x3" src="Double/Double3x3.uxml" />
<ui:VisualElement>
<Style src="TestType.uss" />
<ui:Instance template="Double3" binding-path="Test3" />
<ui:Instance template="Double3x3" binding-path="Test3x3" />
</ui:VisualElement>
</ui:UXML>
This is enabled by this class, plus generated fields/templates for the Unity.Mathematics types:
public abstract class AutoTemplate<T> : Editor
{
public override VisualElement CreateInspectorGUI() => Resources.Load<VisualTreeAsset>($"{typeof(T).Name}").Instantiate();
}
If anyone is interest in the generator code I'll toss it up on Github
The serialization bindings just work in this case
Using the UI Builder is really helpful for creating the inspector element UXML, because it handles the pathing to the template files
meh, for anyone interested in the templates, https://gist.github.com/PassivePicasso/40ec4db990ef9d106ad349b08e82f9e2
the generator deals with setting up the binding paths as well
that all creates this
We should really consider again creating a channel specifically for UI Element X)
@hearty cypress I'm not sure, I don't have time to investigate more, but look at the internal class PresetLibraryEditor<ColorPresetLibrary>
@onyx harness ok thanks for pointing me in the direction.
It seems you can find the presets in a file. I don't know where
I just found the source code on their github. It looks like I can recreate this menu and customize it from there.
which is great because I wanted to do a custom color palette
is there a way to run code in the editor whenever I place a specific prefab in my scene?
@brisk isle EditorApplication.hierarchyWindowChanged?
@onyx harness is that a poring 😮
I am working on Unity 2017.4...
2019.2
@hearty cypress Hell yeah X)
sammmee hahaaa!
EditorApplication.hierarchyChanged?
yeah that seems like one that could work thanks
just to make sure I'm not on an XY problem
what I'm trying to do is, whenever I place an object on the scene in the editor, i want to check if theres another object, exactly Vector3(1,0,0) away from it
It's a way to do it I guess
@onyx harness thanks
Am having problem
With buttoms
If i press one of them it will only press the first buttom i created
Any thoughts?
Any code?
@onyx harness i am only using Canves
I have an Invetor y
Inventory when i press lets say The armor place it will press On the helmet place
Same as everything else it will always press on helmet
i think its a layers thing?
Oh fixed it
its all good ❤
how do I set a white border around an ongui button?
@whole steppe you are on the wrong channel.
@hearty cypress you get the position of your button and you draw 4 lines around it.
@onyx harness could I use DrawTexture for this? Im thinking a black 2x2 pixel that is expanded via ScaleMode.StretchToFill. Or is there a Draw Line method I didnt see?
oh nevermind i found it DrawLine.DrawLine(pointA, pointB, color, width);
I'm not on my computer, but yeah there is utilities for that
They are not optimised, but they do the job
maybe a 2x2 white pixel texture stretch and put behind a button is more efficient than drawing 4 lines
Not sure why but the color doesnt change when I click a button:
Texture2D selectedColor = new Texture2D(2, 2);
changeSelectedColor(selectedColor, Color.white); // set to default color
if (GUI.Button(redButton, ""))
{
changeSelectedColor(selectedColor, Color.red);
}
if (GUI.Button(blueButton, ""))
{
changeSelectedColor(selectedColor, Color.blue);
}
my helper function looks like this:
private void changeSelectedColor(Texture2D selected, Color c)
{
for (int y = 0; y < selected.height; y++)
{
for (int x = 0; x < selected.width; x++)
{
selected.SetPixel(x, y, c);
}
}
selected.Apply();
}
this is OnInspectorGUI though.
What do I need to conclude with it?
Doesnt OnInspectorGUI draws on event changes for inspector like EndChangeCheck(). So i dont see how it is every frame.
Everytime you draw your buttons, just before you created a new texture white
When you click you modify the texture
But the next frame will have again a new texture created
It's always white, that's what I trying to say
yeah i guess im not understanding the order of render here. id assume if clicked once itll re-render just once.
like cache or store as a serializable or something?
Just a field
If null, you create it
Or in a OnEnable
Whatever suits you, as long as it is done once
Okay this is clear for me to resolve it, thanks.
got it. thanks @onyx harness. Heres my ghetto palette selector.
Haha gj
@onyx harness I apologize if my large comments were annoying or something
I did go an put a suggestion into the server feedback channel about creating a separate channel for ui elements, especially considering it will be getting runtime compatibility in the next year
@severe python oh no, don't worry, but it was a suggestion made a long time ago
with unite 2020 copenhagen showing that UIElements is going to be an important technology going forward, I think its more necessary than ever
having a good place on here where people can work out some issues with the technology so it can be improved I think would be helpful for both users and unity tech.
On that note, maybe you (or anyone else here) have some thoughts on an issue I'm running into with this stuff I'm setting up
I'm trying to implement a few basic controls that would really ease the usage of UXML by enabling binding-paths to be used more easily, thats what those big posts up above were about
now I'm trying to setup a ListView, I originally started by trying to implement listview, which successfully bound to the binding-path, but its implementation doesn't allow for elements of multiple types, so I'm trying to build a new list view from scratch
but even upon reviewing the binding system in Unity CS, I can't really tell how you'd utilize bindings in a custom VisualElement
it seems like maybe you can't
I am very far from being an expert on UI Element unfortunately
But I hope to become one, one day! 😁
I just know the theory, never practice yet
I may know more than most and thats kinda frustrating
I've combed over a fairly large portion of the Unity CS reference with regards to UIElements, multiple times since it was first introduced
So... Is it good?
If you look simply at the UI creation aspect, styling and structure are super easy
and very powerful, makes it really easy to make something well layed out and nice looking
comperable to HTML
In simpler situations for Serialized objects, where you don't have lots of nesting or arrays/lists of base types which contain multiple sub-types, the bindsing is very easy to setup and works really well
however, when you're trying to go just a little bit more advanced things get hairy
because they hide a bunch of the systems that, atleast at a glance, you need in order to work with bindings
which honestly, is probably just a lack of understanding on my part, but it shows a weakness in either the design or the documentation
😂
?
I'm worried if I asked too many questions about UIElements here... maybe it's really nice if there's a separate channel
Just shoot, there is almost no contraint about asking questions
how would you figure out if a binding is taking place...
The fact that it says inspectors call Bind itself is confusing
especially when you're not working with the scriptable object the inspector is operating on
I totally agree with the:
because they hide a bunch of the systems that, atleast at a glance, you need in order to work with bindings
which honestly, is probably just a lack of understanding on my part, but it shows a weakness in either the design or the documentation
which is completely my experience with it
oh man, the more i look into their binding system, the more disappointed I am...
I'm just going to pretend it has to do with the fact that its a game engine and all this spaghetti is necessary for performance...
yeah
it really makes me think I just should just do my own thing
buahahahhaa, I got this auto-binding auto templating inspector crap working I think
ArchetypeManager contains an array of EntityModel, which I showed up above a bit. The EntityModel contains IDataComponents which are populated with different IDataComponents, and then Ihave a class, ItemsControl which derives from Bindableelemetn which looks up a UXML file based upon the type name found in the array element
so now I can easily render complex arrays, and fill in missing elements by simply creating a UXML file
Would it be possible to create a slider where one end would gradually change to warmer colors and the other would change to colder colors on a game object? (Oddly specific yes but if anyone could lead me to a tutorial that’d be great)
@low crown Slider is just a value between 0 & 1
From that value, you do whatever you want
I gotta say, once you get something setup to do good automatic loading of UXML its pretty great
I've been just building views for the past couple hours
and haven't needed to touch code
Honestly, this is how it should work out of the box
exactly
That's a HUGE time saver
rapid iteration is huge for UI/UX
its the difference between a good ui and a bad one honestly
this has been a great workflow
Once I got that list control working, I've been able to just build UXML templates for various IComponentData implementations
and as you can see, they are quite simple
Hey, I want to do something that's probably a bit too ambitious
In order to add effects (aka functions) to a scriptable objects, I decided to do this: create a bunch of templates for functions with variables (deal damage, move something somewhere, heal, play, return to hand, etc...) that I could then drag n drop inside of a List or array and that would display input sapce where I would be able to enter the variables, like with a MonoBehaviour script component.
TL; DR If I could put a MonoBehaviour-extended class inside of a List in a way that allowed me to modify the variables just like in a component, that would solve my problem
If you know or have ideas on how to make this possible, please ping me. I'm quite new to modifying the Editor
I'm so not used to the new UI. Still working with U2017, I cant wait to switch ! 😄
Hum... what is UI Builder? native editor?
its an editor for building UIElements
its good with a little glue like I've built, but its still buggy
like, buggy to the point where, its important that I don't create UXML files before I open the UI Builder, the file needs to not exist and I have to start a new one INSIDE the UIBuilder in order for anything to save
and for data to actually flow into the UXML, I hae to add an element, then cut it, then paste it, and then the template will correctly start updating
{
foreach (GameObject obj in Selection.gameObjects)
{
obj.GetComponent<SpriteRenderer>();
scale = EditorGUILayout.Slider(scale, 0, 100);
}
}``` I'm trying to make my scale affect my gameobjects color, any tips
like one would be on the cool spectrum and the other on the warm
I think I have to make a color array
I think the error comes from the fact you aren't actually storing the sprite renderer anywhere
You are calling it, but it's not going anywhere, no variable
Try adding SpriteRenderer renderer = obj.GetComponent<SpriteRenderer>(); instead
Then you'll be able to modify the different values of it
Don't know if that's the issue you are encountering but that's the first thing I noticed '^^
@severe python would be great if you can report bugs about those. I had similar experiences but sounds like you might already have clear paths for reproduction
Is there a way to force a newly created VisualElement re-layout or get informed after VisualElement resized? I want to do some positioning according to Node sizes in a GraphView...
a GeometryChangedEvent could be one way of doing it
thanks!
is there a forum for the UI Builder somewhere?
I need to solve one more problem, which is how to deal with adding to and removing from arrays and allowing different controls to do that
Hmm, how would you find the current editor object from within a visual element that
Yes, I finally figured out the design for this templating setup, and I couldn't be happier
I swear I'm the only person who gets excited about good ui frameworks
you're not! following closely here ;)
Have you figured out a good way to draw a auto-resizing table? Unity themselves create it using vertical columns but it's super hacky to get the rows the same height then
@severe python
I have done nothing with tables
what do you mean auto-resizing?
you talking like an excel grid?
unfortunately I've seem to have come upon a bug in unity thats causing it to crash
looks like an issue with looking at an array element which doesn't have a value assigned to it maybe
Welp, I'm quite happy with where I've gotten to
the performance of generating the interface is a bit slow, which I'll have to investigate, but the interaction performance is great
There are some places where I'm collecting and iterating over every type in the current app domain, so that could be part of it
hmmm, how do you increase the size of an array of structs with SerializedProperty without duplicating the values from the previous element?
I don't see a way I can' assign a struct to a SerializedProperty
Popup stuff is a really weak thing in this system
unless you feel like adding a style to the root of your inspector...
popups are murder 😦
oh man, so it turns out an auto-suggest box of this nature is not possible
there doesn't appear to be a way to position a popup window in uielements without it being a imgui popup
@gloomy chasm Don't know if you were still wondering about making your UI scale with screen size but HandleUtility.GetHandleSize() might work.
Is it possible to allow dropping one or more items from the project or hierarchy into a ReorderableList like you can with the default array inspector?
Sure you gotta implement drag/drop yourself
Which you can do by making using of Unity's event system 🙂
Oh ok thanks
Cool that was pretty easy
is there something that can set textures to materials programmatically in editor? I have this mesh with like 100 child objects that I need to set textures for
@candid briar Thanks, I ended up realizing I was saying the opposite of what I meant. I wanted the handle to stay the same size. So when scrolling out it would be smaller, like gizmos. But don't think it is possible.
@patent seal yeah, though if they all just need the same texture you can just select them all and drag the same texture on to them.
For staying the same size:
Ye you can use sceneView.cameraDistance. Unless you mean something else?
@gloomy chasm they all need a different texture
the tex names are like 001, 002, 003
@patent seal yes you can
@patent seal the Mesh component has a submesh value, each face that needs a specific material needs to be a different submesh, once you have that then you can assign a number of materials to the MeshRenderer's Material array
the index of the material array corresponds to the submesh
yeah my question is how do I do that with a script
instead of manually dragging
I load the texture I want via AssetDatabase then assign it to my meshRenderer, how do I save it
Just to check, are you just working with GameObjects and MonoBehaviours?
yes. I found out I can create a menu button that creates materials via AssetDatabase.
I make a material per texture that I want.
Now I have a game object in my scene with 100 children. I need to assign each children the corresponding material taht I have in my asset folder
wiat, are the 100 children, all game objects? or are you talking about a mesh with abuncha different sub meshes?
so ignore what I said above, its not correct for your scenario
okay, so you'll need to iterate over each child game object, which you can do via Transform, and then get the MeshRenderer on each child, then assign the Material to its material property
if you want to save it in the editor, you'll have to write that into an editor script, but the same thing applies
if you want all the frills, then you'll do it via serialized properties
So iterate over the gameobjects children, get the MeshRenderer, then do a new SerializedObject(MeshRendererInstance), then
serializedObject.FindProperty("material")
then I think you'll assign the material to, materialProperty.objectReferenceValue
if you've not worked with editors before, then you'll want to read up on it, its a bit more than I can just describe quickly here without probably screwing something up
Interestly, might be a new thing, but I just changed the object via the editor script without having to explicitly save, and it worked
public void AssignMaterial()
{
MeshRenderer[] frames = rootMesh.GetComponentsInChildren<MeshRenderer>();
for(int i = 0; i < frames.Length; i++)
{
var name = destination + i + ".mat";
Material material = (Material)AssetDatabase.LoadAssetAtPath(name, typeof(Material));
frames[i].material = material;
Debug.Log("Assigned " + name + " to " + frames[i].name);
}
}
that will generally work, but you'll miss out on some things which I'm incapable of clarifying
Undo won't exist, so if that matters you'll want to setup support for it, its not too hard for a 1 off case
yeah that makes sense. Thanks for your help 🙂
no problem
I can't figure out how the heck to do a Singleton MonoBehaviour that works in editor. Any ideas?
Does it have to be a MonoBehaviour for some reason?
Because it can just be a static class at that point
I need it to save the data from designtime and use it in runtime.
You could save it in a ScriptableObject
True
If you really have to use a MonoBehaviour, you can force the editor to load a prefab into memory with PrefabUtility.InstantiatePrefab and work with it from there
But you'll need a static class to do at least that
I want to metnio, I've frequently run into problems when I've tried to use static initialization in unity
I do a lot of heavily dynamic reflection stuff though, so that could be related
No, a So should work better actually. Idk why I didn't think of it, I have been doing so much with SOs of late...
Can you use ISerializationCallbackReceiver with SOs? Or do you need to? I need dictionaries.
You can
sorry, I believe you can, whether or not you need to I'm unsure, dictionaries are dictionaries
You can use ISerializationCallbackReceiver with any class marked with the Serializable attribute
There are assets that bring dictionaries to the editor, a few of them free
Yeah, I only need the serialization. As long as they are saved, I'm good. And I can just put the keys and values in arrays for that
Shoot, now I gotta remember how to get things to show in the sceneview from a SO
I work a lot with statics, there are some stuff required to know, but beside that, it works like a charm in the Editor
Yeah, just gotta be aware that everything basically gets cleared out when there's a recompile
I created a custom editor that draws a handle in OnSceneGUI with Handles.PositionHandle, and I'm also using a Vector field in OnInspectrGUI.
However, when moving the position handle, the vector field doesn't update. how can I force refresh of it?
@severe python is that UI Builder something native? or your tool?
There's a new UI Builder in 2019.3? IIRC
I'm no expert on this matter, but is it possible to use UI Builder in 2019.3 then backport the result to an earlier version?
That would be great, but still asking, because... I don't expect it to work
can UI Elements be used to create UI in scene view?
should be right?
just not game view right now?
I don't know how different are the engines between versions
@lucid hedge You should be able to get the root object of the scene somehow not sure if it's officially exposed
cool thanks
It's a custom ui elelements, some ui buildera
honestly, UI builders part is fairly limited
oh, nevermind thats not what you were asking lol
@waxen sandal @lucid hedge UIElements for the scene/game are not available just yet, but soon
Well you can draw on top of the scene editor window
In hacky ways
But not for actual ingame use
Yeah that's what I want just scene editor. Just edit mode.
But overlayed on scene editor.
Scene view*
is probably possible, but I don't actually know
I think it should be, will give it a try
Is there a way to add class instances into propety via inspector? I have a component that can accept several "strategies", and I want to just select a type in inspector (inheritor of a specific abstract class), and have it instantiated in runtime. Also I want to set its properties in inspector. Same for an array of strategies. (may be kinda Volume Overrides, or something).
not without making a custom editor
and what you're trying to do isn't exactly clear
are these class instances derived from MonoBehaviour or ScriptableObject?
I don't need them to be even Object, but if it is required, I can make them anything or [Serializable]
It's more like a logic plugin, e.g. if I have an actor (gameobject with behavior), I'd like to plug in different decision making strategies, etc.
Like for AI, it could be "reaction to alert" and strategies like "attack", "flee", "defend"
this has always been a little difficult because unity serialization couldn't handle multiple types in a field or an array
You can populate a single field with a specific type, if you build a custom editor, but you'll lose the data type upon serialization
That being said SerializeReference is a new feature aimed to solve that problem
but you have to be on the 2019.3 beta to try it out, and its still buggy
thats what I'm using to do all that component stuff above, I have a struct with IComponentData and ISharedcomponentData in it, and I built a custom editor to allow me to populate them
basically I get a collection of all types that are assignable to IComponentData, and created a search box that lets me pick one, create an instance, and inject it into the array
Dang, too complex. I was hoping for something easier 🙂 For now I just have a number of empty GO with strategies as components on them, and I set a component property from there…
its not too bad tbh
if you're dealing with a single field, you're talking a few lines of code, maybe 20?
I have fields and arrays. Thanks, I will look into SerializeReference and *ComponentData stuff.
void OnInspectorGUI()
{
var types = AppDomain.Current.GetAssemblies().SelectMany(asm => asm.GetTypes()).Where(typeof(IComponentData).IsAssignableFrom).toArray();
var property = new SerializedObject(target).FindProperty("IComponentDataField");
//GUI stuff to present type options
//GUI stuff to select type option
property.managedReferenceValue = Activator.CreateInstance(selectedType);
//Importantly
property.serializedObject.ApplyModifiedProperties();
}
with an array you'd have to use the property.GetArrayElementAtIndex call to get the actual property element
that said nothing says you have to use serializedProperties, they just provide some additional functionaltiy over modifying target directly
Does reflection work in il2cpp targets? stupid me, it's editor
tbh, I donno, but yeah, doesn't matter
I think some reflection works
I believe its just System.Reflection.Emit that you can't use
Is it possible to add to the window context menus? such as when you right click on the inspector window, I want to put something in the add Tab section but I cant seem to find the right context for the MenuItem attribute.
I knjow you can fo rmany places, though I'm not sure about that one specifically
@fresh shell This is how they get the ui elements debugger in there I think?
public const string k_WindowPath = "Window/Analysis/UIElements Debugger";
Oh awesome okay. Thanks @severe python that should be a good place for me to dive more into it.
I just was looking aroun the unity reference
which I totally recommend keeping a copy of on hand, because its helpful for this kinda stuff
That's a good idea
I found that just by right clicking on the tab seciton you were talking about, thens earching for UIElements Debugger
@fresh shell have you looked at IHasMenuItem or something similar, I don't remember the exact name
in the source code, to see if I could figure out the path
@onyx harness I hadn't I'll take a look at that too. Thank you!
This one allows you to intercept the contextual menu when you right click the tab of a window
man, no one from unity responded to my popup positioning issue
Positioning issue? What is it?
as far as I can tell, with UIElements you can't get the screen space position of a control
Since UIElements are drawn in hierarchical order, you have to move a control up to the rootVisualElement as the last child in order for it to render above everything else, within the window panel
however, if the popup would show up at the edges of the panel, it would be cut off, or you have to have some code to have it move its positioning so it remains visible, which may not be preferrable
So the obvious choice would be to launch an EditorWindow with EditorWindow.ShowAsDropDown or Editor.ShowPopup
however in order to use either of those you need to be able to position them with screen space coordinates
and since you can't find the screenspace coordinates of a UI element you cant position them appropriately
And so the only way to actually accomplish this is to setup an IMGUI container and use the old REct layout system
and a classical imgui popup window, which means your popups cannot contain uielements
Interesting, if one day I stumble upon that, I will gladly investigate
there is a work around with using Win32
but I didn't want to solve it using a platform specific solution
even though it will never affect me, I may decide to release this code for others and in that case I'd like to not prevent it from being usable for linux or macosx users
welp, i guess we will be getting the ability to control z-index, eventually
it is not a "near term priority"
so 2021 maybe?
:/
buahahahaha, I stumbled upon a solution that should theoretically be portable
it does use reflection...
welp, I figured out how to handle positioning
but editor windows take focus when shown
What is the problem with reflection
I'm now in the process of hacking my way to success through reflection...
I'm accessing methods and properties marked internal in the Unity source
which means its not an API which means it subject to change without notice
The notice is the alpha ;)
so it could break at any time
fair enough, I could be ahead of everyone except other people like me who live on the bleeding edge
Trust me, this is no issue
also, what you talking about, just keep the focus?
I don't know a way to not give up focus?
certainly not in this context
Get the current window and focus it right after you opened your popup
Or create your pop-up manually
well, I did it, I can open the window as a popup and not lose focus
oh I tried that, it didn't work really
(I don't know your code, so I don't know which technique you used)
I tried a bunch of different things with not giving up focus by refocusing the textbox, none of it actually worked sadly
but now I'm not even losing focus in the first place, which is honestly preferable
I'm making progress here, but god damn, its just a slog
every problem I solve leads immediately to a new problem
so it works, but I"m having all kinds of little issues
it seems the focus transfer to click on something is an issue
w00t
woa my gif capture has some uh, artifacts huh
styling is a work in progress
It's a little buggy, needs work but it's going well now that I sorted out the big problems
I have a scriptableobject in my project
and I'm trying to add a material asset as a sub asset
but I'm getting the error
'AddAssetToSameFile failed because the other asset Section 0 Material is not persistent'
any idea why that is happening?
Just make it persistent. Save it to disk, then delete it.
@lucid hedge
I tried doing that after you suggested but then I notice I was adding cycle to material when really I wanted to add material to cycle 😮
and that fixed it
@severe python is that thing with Add component to Entity Model your editor or something standard? I need exactly this!
Is it possible to show a tooltip like window when the user clicks a button?
Something that would say for example "Id copied"
https://docs.unity3d.com/ScriptReference/EditorWindow.ShowNotification.html might do if you're making an editor window
Custom Editor :/
You could find the inspector in question and send the event there
or implement it yourself, as I did for my preview inspector https://github.com/vertxxyz/NTexturePreview/blob/master/Editor/NTexturePreview.cs#L112
Oh fuck
I forgot, it's actually neither an EditorWindow or an CustomEditor
It's just a class that gets used in multiple different places
That has a draw method
It mostly gets used in a custom editor though so I'll just show it in there
Thanks!
its a custom control I built, its a type ahead search box (really just doing some contains checks on strings)
actually its a combination of htem I built for UI Elements
theres AutoTemplate which sets up the whole root of the inspector using a type lookup for the uxml template
and there is the ItemsControl which does the same thing against an array/collection, it looks up each items type and loads a uxml template by name
then there is finally the SearchSuggest control, which is what makes up the parts of the "Add component" ui, which justpresents a list of labels that you can click on in a poup window which populates the items control
an itemscontrol*
actually it can populate whatever you tell it to
Anyone know if there is a way to see if Unity is losing focus as a whole?
nah, i was hoping for something generic
a unity api or something, I can do a whole lot of neat stuff with win32, I just don't want to go down that road
not unless I know of, how to interface with, and target other platforms method of doing so
and I can't even test it
like, one time I put a wpf application inside an inspector for Unity, becuase I hate IMGUI
built a whole ipc mechanism to update the data between unity and the app
was totally more trouble than it was worth
hi! Does anybody know if there is a simple way to create a new handle every frame and keep the handle from the previous frame in it's position?
is that possible at all?
I'm drawing handle sphere like this:
Handles.SphereHandleCap(0, debugger.transform.position, Quaternion.identity, 0.5f, EventType.Repaint);
I would like to redraw that handle every frame but keeping the handle of the previous frame also drawn
You have to store the previous positions, and do a Handle for each of them.
that was my guess, storing positions in an array and drawing multiple handles. But I wanted to make sure if there was a simpler way
thanks anyways @cedar reef 🙂
I know I have learned this before but I have forgotten. Why would the selection for my freemove handle be like twice the size of the handle? And more importantly how do I prevent it?
zoom?
hi i'm really struggleing with the [SerializeReference] attribute in 2019.3. it does what it's supposed to but it refuses to apply changed fields to the asset if i use a custom inspector for the class that holds the [SerializeReference] field. property drawers don't show up at all and even a normal enum field shows up as an int. this can't be how it's intended to function right? how can i get around this? i need a [SerializeReference] tagged field to work with propertyDrawers and preferably also with custom inspectors...
Are you using UIElements?
If so, I guess PropertyDrawers don't work for UIElements yet
Did anyone ever serialized a field by its own? since unity doesnt support polymorphism- serialization before 2019.3 ?
What?
i mean save a inspector field with some other serialization lib and load it ?
@uncut snow I have a hierarchical class structure I serialized with Newtonsoft.Json because the design relied upon properties which where backed by an object graph and I needed to serialize the graphs behind the properties in addition to the structure
it was a pretty miserable experience overall, and I had constant problems when the data structure changed
however, if you use ISerializationCallbackReceiver https://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.html
you can do it
thx for the info^^
Cross platform buttons with OnLeave/OnHover etc, does this exist or will I have to build it all myself?
Problem I had is that I want to use a function at each event, not just change sprite for example
Does anyone experienced really long build time for AssetBundles ? I have like 300Mo of AssetBundles data and it takes 29hours on a decent machine (i9, 32GB of RAM, SSD).
I use the AssetBundle Browser, maybe this tool causes troubles ?
I know it's single threaded but come on...
Some of the newer Unity assets like ShaderGraphs are actually not serialzied with Unity
They use a custom serializer that they save in a normal .asset file
And are then trasnformed to the asset file using a scripted importer
guys i have variables inside of a class that i use in a list and i need the editor script to show a variable inside of the class instead of in the script in the inspector
You need to make serializable the class you are using, by adding [System.Serializable] on top of it.
Every public or marked with [SerializeField] attribute field inside of it will be serialized in the inspector in Unity
it does not work for Properties however, only Fields
public class dialouge
{
public string ElementName;
[TextArea]
public string Text;
public bool skip;
public float skipT;
}```
this is my class
i want the skipt to appear only when skip is true
and iam using this class in a list
Then you're going to need to make a custom property drawer
yeah, you'll want to write a custom PropertyDrawer for the dialogue class that checks the value of skip and then renders skipT based upon that
Unity manual has examples how to use it. https://docs.unity3d.com/ScriptReference/PropertyDrawer.html There are plenty of tutorial for it as well.
You have Google at your fingertips. Don't be afraid to use it.
Aye, I'm not one to do the "You need to google first" but when it comes to specific implementation things, following the manual or watching a well built tutorial is better than some chat conversation
i always do google first i just don't know what to specifically look for right now
No worries, the hardest part of development in my opinion is knowing what to look for
if i have class f inside of anthor mono class n do i have to say typeof(n.f)
and f is serializable
do you mean like
public class MyBehaviour: MonoBehavior {
[System.Serializable]
public class dialouge
{
public string ElementName;
[TextArea]
public string Text;
public bool skip;
public float skipT;
}
}
yes
yeah, the parent class becomes like (this is not TECHNICALLY accurate) a namespace
(FYI, it is called a nested class)
ok thanks
man, everytime I talk to someone who is doing procedural modeling, and I show them my project, after they asked
they never say anything
public class IntractionE : PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var container = new VisualElement();
var skip = new PropertyField(property.FindPropertyRelative("skip"));
}
}```
why is there an error in CreatePropertyGUI
@surreal bramble check the console for the error description, it is probably warning you that the method should return a VisualElement but you are never doing that
uh, that might not work, maybe its in specific versions, but I've been told that UIElements PropertyDrawer doesn't work
maybe thats incorrect
or maybe theres a caveat I'm not aware of that causes that situation
huh, there must be a more specific situation, or I was just misinfomred
is there something like DrawDefaultInspector (); for property drawers
Yup, that's how you draw a default inspector
If you mean draw the default one, not a custom property drawer, no there's not a method I'm aware of
Possibly something you could do through reflection
right now it's giving me this error how do i fix it
maybe thats what I was being told
Examine this and the response, it may be releavnt
my current script it's still giving me the same problem
public class IntractionE : PropertyDrawer
{
override public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
base.OnGUI(position, property, label);
bool Skip = property.FindPropertyRelative("skip").boolValue;
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
}
}```
no gui implemented
?
Unfortunately for you, I don't do a lot with imgui or property drawers, uhm
maybe don't call base.ongui?
I imagine that woudl draw the property twice
it's ok i fixed it
ok so how do i have every variable in it's own place and not overlapping
{
EditorGUI.BeginProperty(position, label, property);
var nameRect = new Rect(position.x, position.y + 18, position.width, 16);
var diaRect = new Rect(position.x, position.y + 36, position.width, 16);
EditorGUI.indentLevel++;
EditorGUI.PropertyField(nameRect, property.FindPropertyRelative("ElementName"));
EditorGUI.indentLevel--;
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
Rect rect = new Rect(position.x, position.y, position.width * 0.4f - 5, position.height);
EditorGUI.EndProperty();
}```
I'm just gonna drop this here for yall, the source code backing for my auto-templating system, I targetd 2020.1a8, so there may be issues if you're not on that version
https://github.com/PassivePicasso/VisualTemplates
I'll be making another repo with the test case I was setting up, but it requires a whole bunch of packages
lots of room for improvements in thie system, some of the code in ItemsControl can be extracted into its own code for just a template presenter
I should make this a package
and now its a valid package
@surreal bramble you need to override GetPropertyHeight()
And in your OnGUI, you are not required to call Begin/EndProperty.
Also, I don't understand the last Rect
Yeah i did that but thanks anyways
guy how do i do something like that arrow for each list
is this a serialized list?
look up PropertyDrawers
iam using property drawers i just don't know what this arrow is called
lookup "Foldouts" then, that's what it's called
You can also use the debugging tools to find out what things are
information about them is pinned to this channel
guys when i have my foldout unfolded i can't change anything```[CustomPropertyDrawer(typeof(Intraction.dialouge))]
public class IntractionE : PropertyDrawer
{
override public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
var nameRect = new Rect(position.x, position.y + 18, position.width, 16);
var diaRect = new Rect(position.x, position.y + 36, position.width, 64);
var skiRect = new Rect(position.x, position.y + 108, position.width, 16);
var skitRect = new Rect(position.x, position.y + 126, position.width, 16);
bool sk = property.FindPropertyRelative("skip").boolValue;
property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
EditorGUI.indentLevel++;
if (property.isExpanded)
{
EditorGUI.PropertyField(nameRect, property.FindPropertyRelative("ElementName"));
EditorGUI.PropertyField(diaRect, property.FindPropertyRelative("Text"));
EditorGUI.PropertyField(skiRect, property.FindPropertyRelative("skip"));
if (sk == true)
{
EditorGUI.PropertyField(skitRect, property.FindPropertyRelative("skipT"));
extraHeight = 16 * 8;
}
else
{
extraHeight = 16 * 7;
}
}
else
{
extraHeight = 0;
}
EditorGUI.indentLevel--;
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
Rect rect = new Rect(position.x, position.y, position.width * 0.4f - 5, position.height);
EditorGUI.EndProperty();
}```
Define can't change anything
i can't click on the text box and write in it
guys how do i fix this
[CustomPropertyDrawer(typeof(Intraction.dialouge))]
public class IntractionE : PropertyDrawer
{
override public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
var foldRect = new Rect(position.x, position.y, position.width, 16);
var nameRect = new Rect(position.x, position.y + 18, position.width, 16);
var diaRect = new Rect(position.x, position.y + 36, position.width, 64);
var skiRect = new Rect(position.x, position.y + 108, position.width, 16);
var skitRect = new Rect(position.x, position.y + 126, position.width, 16);
bool sk = property.FindPropertyRelative("skip").boolValue;
property.isExpanded = EditorGUI.Foldout(foldRect, property.isExpanded, label);
EditorGUI.indentLevel++;
if (property.isExpanded)
{
EditorGUI.PropertyField(nameRect, property.FindPropertyRelative("ElementName"));
if (sk == true)
{
EditorGUI.PropertyField(skitRect, property.FindPropertyRelative("skipT"));
extraHeight = 16 * 8;
}
else
{
extraHeight = 16 * 7;
}
}
else
{
extraHeight = 0;
}
EditorGUI.indentLevel--;
//position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
EditorGUI.EndProperty();
}
float extraHeight = 120;
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
// Use Unity's default height, which is a single line
// in the inspector
return base.GetPropertyHeight(property, label) + extraHeight;
}
}```
code
is there an alternative for GetPropertyHeight
because i have a list and every time i change the height it changes for all the elements not just the element that iam working with
and i know why i just don't know how to stop it
basically what i want is to assign each property it's own height instead of having a GetPropertyHeight
You could have a bool isControlled and change the height based on that?
guys iam using editor gui layout but now it's in the end how can i make it go up
What do you mean?
EditorGUILayout
it creates the field in the bottom of the script
i want to move it up
What ide?
ahh
But you'll also get autocompletion of CSS :/
In VSCode you can mark the file as CSS in the bottom right
The ini button
I use Notepad++ for it
it would be nice if they built a syntax engine for VS though
In vscode you can add these to your settings.json
ah without that line
just add uss and uxml, the css editor in vscode is really nice
I wonder if there is a way to do that for regular VS
das really neat
oh, I guess I could just build a USS text editor with UI elements
especially since I havbe a reliable type-ahead search
in regular VS you can click 'Open with...' on the file and select css/xml editor as default
oh, thats right, you totally can
I always forget that you can do that
not only that, but you can set it as default
o/ @crystal timber
but the vs css editor is not so cool like vscode, so I always open my project with both vs and vsc lol
yeah, but I ahve a color picker now
I don't have to just make educated guesses for my color hex values now
I'm generating mesh in Editor when user hits a button and assign the sharedMesh in MeshFilter component. When object is in scene it works perfectly. But when I make it a prefab, it generates mesh, everything is working, but when I open scene or another prefab in Editor, the generated mesh is lost… Any ideas?
Your mesh is 100% temporary
If you lose its host (a MeshRendrer I guess), you will lose the Mesh.
You need to save it to disk.
I have a MeshRenderer on the same object…
But I wonder why Scene persists the Mesh (even with Unity closing and reopening) but prefab doesn't
the issue is the mesh isn't an asset
the data isn't saved into the MeshRenderer
the meshrenderer saves a reference to an asset that is going to disappear
in a scene that asset reference can persist
but outside it has no where to peresist to
IIRC, you need to use AssetDatabase to create an asset for the mesh
Why is it so? Scene and prefab has more or less the same structure, and in scene Mesh is serialized, and in prefab it is not
I can't say specifically as I don't know
but they are not the same overall
You could view a scene as a prefab
but its not one, they are different
you can't override elements of a scene and store multiple versions of the same scene with overrides
When your generate a Mesh and assign it on a MeshRenderer that lives in a scene, the scene persist it after restarting Unity? O_O
I need to check that
Yes, the mesh data is in the YAML file
Interesting...
Well I guess it is auto-embedded
While a prefab needs a viable link to the Mesh.
the important part that matters is that it doesn't happen for prefabs
Why that is, ask Unity Technologies
Yeah, I understand that it doesn't happen 🙂 I was thinking I'm missing something
But technically, I would like to add, a scene is a prefab.
There have no difference but the extension at the end.
Which will be handled differently due to it
Can I may be create an empty persistent mesh, link it to prefab, and when generating code would update the original mesh?
May be I'm blind, but I can't see how to create an empty mesh asset…
UnityException: Creating asset at path Prefabs/Small Stone Mesh.asset failed.
No much information in the exception…
Yes, thanks. 🤦
I saw that SerializedObject.ApplyModifiedProperties returns a bool. The documentation doesn't saying anything about it tho. Does it only return true if properties were modified?
After testing it appears so. neato
Im just starting out in Unity, what VS Extensions would you reccomend?
I'm trying to install a couple of extensions but Visual Studio seems to dislike that. VS prompts that extensions will be installed once all VS windows are closed but closing all windows and reopening has no effect at all (I've tried this about 5 times now)
Going to try restarting now
Restarting was useless
OH
Nope, still not installing
OH GOD FINALLY VSIX MAGICALLY OPENS
All I did was click Stop Roaming for the extensions thing
I see some people have cloned my repository for visual templates, any thoughts?
I did some research and here is my variant of inspector extension to show and edit bounds for GO with Renderer or Collider components:
https://gist.github.com/orangy/8f5626fad791df28cf5cba8c4c5aa28d
I have an editor script that contains some variables, like objects, when in a session I drag the assets into the object fields (some in the scene, some in the project), is there a way to make those persistent after restarts of Unity, or do I need to make a scriptable object or something like that and serialize that? I have them set to [SerializeField], and the editor script set to Serializable, but I guess I am confused on the set dirty part, if that is what I am missing.
code code
Can you make custom editor windows which are based on the scene view?
I'd like to make a comprehensive level editor that's separate from the regular scene view, but still is based on it so I can make use of the built in tile brush features
@tidal cave Got any gifs?
@half marten last time I needed something like this I ended up making hidden/invisible objects in the scene, with a camera that renders them to a separate RT that's used in the editor window
Gives you full control but you have to do all raycasting etc yourself.
Not saying this is the best or only way :)
does that allow tile painting on the custom window though?
i imagine not, since it's just the visual element of the camera render
Hi, on Visual studio, intellisense works fine for terms like "GameObject", but not for functions like "Update(), Start().... " any idea please ?
Install Unity plugin
They have plenty of stuff to "easily" add those methods
(My favorite way) Or use snippet
ok thanks, going to try it now !
@onyx harness Do I install it on visual code ? or is it available on VS ?
@sharp siren It's pretty easy to find it, look for vstu
you need to install it
Usually, Unity installer offers it
I don't understand. I've go VS but not VC. Do I need absolutely VC ?
What is a font that y'all like at the moment? I'm using cascadia code
FiraCode
Ima check that out
With ligatures
are ligatures the curly ones?
Is there any way to get the unity conversion from string to a float with the operations?
Like placing (7+8)*2 sets a float in a field
I have found some third parties that does this like Flee but i wanted to know if unity has any solution built in
Found it in case anyone wants it
understandably editor only, but a little disapointing
Does anyone know how to use the "Context" with Editor Shortcuts?
Is a type but i have 0 idea of what type to set for playmode
anyone want to edit directly that visual element inside bulit-in element, use reflection
Unity won't present this class :/
use refelection to can access their properties, fields.
(thats only way I think by discovered)
https://github.com/lucascassiano/Unity-Arduino-Serial-Port-Finder
Guys, did anybody worked with this in previous. This is a project that works on setting up Arduino and Unity auto configuration. If yes please leave me a message. I've been sitting on make this thing work for one week
I has more discovered with reflection, and I confirmed Unity doesn't exposed UIElement bulit-in control's subclasses
no it doesn't but you don't need to use reflection to look at the unity code base
go grab the Unity CS REference source
I have more discovered, there's TextElement abstract class exists
PopupTextElement inherits it
So I actually now can access without reflection
@severe python and thanks to notice it to me! (but I found it before see it, my spended time...)


@severe python hey can I capture your advice?
Just posting on my devlog
oh god
PopupFieldTextElement

advice on?
@severe python so can I post your advice?
to grab the unity cs reference?
I mean, sure? but its not mine, thats all Unity-Technologies
^^^^^
all I did was point you at something they did
I'd prefer if you didn't put my profile pick/nick in there tbh
If I were writing a devblog, I may say "With the help of a user on Unity's official Discord I found the Unity CS Reference source, an invaluable tool for anyone working with Unity's newest technologies" or something like that, then link the github repository
You're welcome
@odd swan make your window really small then use that popup
does it still work right?
yes
Unity's default font is actually hard to read in HiDPI
with CJK text
:(
So I replaced that
CJK stands Chinese, Japanese, Korean
Unity's default font doesn't contain CJK range font, so they replace system default font
...and there's not exist font weight
;(
yes i does
defines root style
my problem was
by just this / thing
this separates popup and generic menu list
so I was discovered about this is UIElement, like web development. may can able to only swap it's display text?
Process of my discover
- change
valueproperty - failed, it's throws ArgumentException withNot present in list of possible values - get Label through querySelector(Q) to change it - failed but found it PopupTextElement is private subclass
So I first time search about it but as you know, I was search with wrong keyword lmao (
PopupFieldElement)
Then I check with debugger and inspect what it have fields, properties.
- using REFLECTION to force set it's value - ok, but hmm this is actually only way to able this?
So I post at here and...
- I found
PopupTextElementis inheritedTextElementabstract class! - And got a Unity source repo to check it's structure.
Even works well with it, yay!
After discover, I realize I was search with wrong keyword 
Anyway it's solved!
👏
I going to bed
gn
Hi i got strange results in the scene height values
viewing the numbers like so:
Debug.Log( SceneView.currentDrawingSceneView.position.height + " , " + Screen.height );
OnSceneGUI for a custom editor
1st and 2nd value don't match
more over the difference between the two is never static
also im using scaled DPI on windows10
any ideas ?
Huh ... i think i got it
var diff = Screen.height - SceneView.currentDrawingSceneView.position.height * EditorGUIUtility.pixelsPerPoint;
which will result in a semi constant value of 24.25 ~ 25 ( with a cyclical step size of 0.25 )
very strange
maybe it has to do with my current DPI scaling of 125% which results in the .25 step size
yep... changed to DPI scale size of 150% and now the value is 30 ~ 30.5 with a step size of 0.5 ...
so at scale of 100% the difference will always be equal to 20
maybe it has to do with the scene view header ( where the light, sound, skybox buttons are )
oh man, yeah Unity wouldn't be DPI aware would it...
old but gold
im trying to align a 2nd helper GUI box like the particle system
looks like magic numbers are the only solution to make it fit
why not use relative positioning instead of pixel positioning?
is that not a thing in the sceneview?
oh lol i think it is
let me try
huh...
seems to do the trick
but there is a catch
20 pixel bottom padding
although using the relative positioning ( i assume you meant to use the GUILayout and EditorGUILayout ) will take care of the DPI scaling automatically
.
.
Anyone know how can i set the title of the window on the left ?
the padding looks the same too me?
( bottom cutoff )
I presume thats IMGUI, if so I don't know, but anyone else would need more context
on the 1st screenshot the size of the box was always bigger then the scene
donno what you're doing to draw that "window"
but I'd suggest looking at the Unity Manual for the call you're using to create that "window"
using( new GUILayout.VerticalScope( GUI.skin.window ) ) { ... }```
vertical scope? I've never heard of this before
its the same as : GUILayout.BeginVerticalScope()
hmmm... seems like the folks at unity created a SceneViewOverlay internal class for the particle effects GUI
where they use: GUILayout.Window( ... )
yeah I was going to say, I think the first thing is that Scope doesn't take a GUIContent and so doesn't have a label, you're just applying a style which makes it seem like it should
GUILayout.Window likely does take a GUIContent for a label
yea but it wakes a screen Rect ...
which will require to do the manual calculation again
eh....
ha solved it
var rect = GUILayoutUtility.GetLastRect();
var titleContent = new GUIContent( titleStr );
rect.y += 2f;
rect.x += ( width - 7.25f * titleStr.Length ) / 2f;
GUI.Label( rect, titleContent );
GUILayout.Space( 20f + padding );
this ^ directly after closing the window vertical scope
seems like magic numbers will never go away
Not sure if this is the right place to ask but I am trying to get into Unity Editor scripting, are there any recommended reading materials/video channels/courses on picking it up + learning more in-depth about it?
I have an editor script and I want to run a function on the object after the editor app has stopped running. I tried adding an event to EditorApplication.quitting in onEnable ,but either the event isn't firing or onEnabled isn't the place. how can I solve this?
yeah sorry, you're right. I am using it OnEnable though
I'm also using OnEnable with the EditorApplication.update event btw, which is working. it's just the quitting event I'm not sure how to use
Whats the correct EditorGUILayout for the SerializedProperty of a quaternion?
alone it just shows a dropdown but the internals are not there
nvm looks like i have to make my own drawer
Is there a good getting started guide on editor extensions? I want to build a tool that lets me interact with meshes in the scene view in a similar way to probuilder.
For starters just want to click on the scene view, cast a ray to find what I clicked on, and then get the mesh that it intersects.
I know how to do all the raycasting and object detection, I just don't know how to have that happen through interaction in the scene view.
@karmic aurora
Never really found great tutorials on it. But some stuff to point you in the right direction:
You can just use the SceneView camera for raycasting https://docs.unity3d.com/ScriptReference/SceneView-camera.html
Input is a bit trickier in the scene view and generally you gotta do it with a key event like https://answers.unity.com/questions/130898/how-to-check-if-a-key-is-down-in-editor-script.html
If things aren't as snappy as you want using OnSceneGUI or whatever else they have built in, you can make a custom editor update with a bit of googling.
You can instantiate a GO to help you wherever you need in the editor and then just set it's hide and not save flags. You can also do this with additive scenes like the humanoid editor works.
Anyone know if it's possible to activate Animation mode from a script? (The mode when you have the Animation window open and the play and pause buttons become red)
I want to be able to apply a animation clip temporarily while I have a custom Editor window author time based metadata that shouldn't be encoded as animations
@gilded flame Unsure, but this is the place to look https://github.com/Unity-Technologies/UnityCsReference/tree/master/Editor/Mono/Animation/AnimationWindow
Thanks
if you DL the project and then use Visual Studio to find references to some promising things like OnStartLiveEdit you can probably find how they do it
It's a shame that it's all internal right now
@gilded flame ok its here https://github.com/Unity-Technologies/UnityCsReference/blob/f78f4093c8a2b45949a847cdc704cf209dcf2f36/Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs#L360
Excellent
One finall other question: does anyone know if the source code for Shader Graph/VFX graph is available?
I have a graph based editor extension that I think would be about 10x less code if rewritten in UIElements
And would definitely want to see if I could get the base code node based graphs off of those two packages
@gilded flame there have been a couple of attempts in the past to get a "basic node framework" based on what Unity has but they didn't exactly make it easy.
Problem is that they started the Graph API, deviated from it at all different times for ShaderGraph and vfx graph and now there's very little common ground between them with lots of redundant/duplicate functionality all built a bit differently. So right now there's at least 3 versions of a "Unity Graph Framework"
If someone knows about a project with a "clean" approach based on the current Graph api I would be super happy to see that :)
I'm trying to make a custom property drawer using ui elements and would like to put 3 floats in a row. With imgui I'd temporarily lower EditorGUIUtility.labelWidth so that they all fit but I'm not sure how to lower the label width in ui elements
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var root = new VisualElement();
var longitudeProperty = property.FindPropertyRelative("longitude");
var latitudeProperty = property.FindPropertyRelative("latitude");
var radiusProperty = property.FindPropertyRelative("radius");
var longitudeElement = new PropertyField(longitudeProperty, "Lo");
var latitudeElement = new PropertyField(latitudeProperty, "La");
var radiusElement = new PropertyField(latitudeProperty, "R");
var horizontalLayoutElement = new VisualElement() { style = { flexDirection = FlexDirection.Row } };
horizontalLayoutElement.Add(longitudeElement);
horizontalLayoutElement.Add(latitudeElement);
horizontalLayoutElement.Add(radiusElement);
root.Add(horizontalLayoutElement);
return root;
}
Setting the width of the property element doesn't work
Re Shader Graph / VFX, I've recently found this effort to abstract it for reusability: https://github.com/rygo6/GTLogicGraph
But didn't actually try it yet
@gilded flame ^^
@tidal cave yeah I saw, unfortunately I am looking for something closer to Meccanim in construction, I just want to author custom state machines
Been trying to use that as a reference
Might just have to fork the official GraphView and make one myself
Looking at the CsReference for GraphView and it seems to all be available
What do you mean?
Didn't have time to finish my thoughts
The source code for GraphView is entirely in C#
My only thought is if it is legal to fork it give the reference only license of the CsReference repository
GraphView ShaderGraph based on GraphView is a package, not in main Unity source code. So it might have a different license, but unlikely.
It's Unity Companion Package License v1.0
Unity hereby grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available with this License
(emphasis mine)
Sorry, I messed up 🙂 The above is about the ShaderGraph
That's not two versions. What you see in Shader Graph tool is half generic GraphView, half special code for Shader Graph. GTLogicGraph attempts to generalize on some Shader Graph features for use in different use cases.
Yes, what I want is direct node-node connections not port-port
And that'd require forking GraphView
GraphView is part of the Engine/Editor, so it is covered by Engine License, I suppose
Is there a better way to indent a visual element than hardcoding the styles left property?
The project context Asset Create menu has gotten way to large
and its root context menu for that matter
So, I've seen a lot of different hacks to extend inspector editor instead of replacing it. Why is it not a standard feature of Unity Editor? If there is already a custom editor for a component, and I want to extend it I have to go through a lot of hacks to get that working (e.g. http://www.li0rtal.com/extending-unity-inspectors/)
extending default editors is as easy as calling the base method
Lots are internal though
Yea, internal. And also there might be custom editors
Hello ! Does anyone here know a good (free would be great too) vegetation/grass placement system apart from vegetation studio and the default unity terrain vegetation placer (wich almost never works with 3D objects) ?
I'm working on my own, but that's because I want to learn procgen
But I think the question could better be answered in #⛰️┃terrain-3d
how can I display a UnityEvent using a custom editor?
I guess yes.
... what do you mean yes? how?
just to clarify, not using the default inspector
Maybe a EditorGUI.PropertyField
I don't have a property. Or rather, it's inside a class that is inside an array property.
If there's a way to get SerializedProperty from that, that would be a good solution too. I couldn't find that either though
that's just the array element it self. I need the property of an array element
That is an element in an array
if you want to find something inside of that element, then you use FindPropertyRelative
yes, element in an array = array element
mm I think I tried FindPropertyRelative and it didn't work, but I'll try again. Any special syntax for "children" ?
what do you mean by children? You can either walk down the chain of serialized properties using FindPropertyRelative
or you can provide the entire property path
😮 can I use array elements using the entire property path?
yes, I forget the syntax though
Also, you can display UnityEvents using UnityEditorInternal.UnityEventDrawer
😮 that's actually better! how do I actually use that drawer though?
They might get displayed fine with PropertyDrawer, but I have used that class to create a custom version once, or just display the default field
just instance it and call OnGUI
lol sounds hacky but I'll take it. I'll try it, and thanks again!
@tidal cave No, because I don’t want a terrain based placement method because I am using 3D models instead of terrains because terrains aren’t scalable and always too big.
Hi everyone, is there an editor extensions that allows you to draw with 3d objects basically? Like a tilemap for 3D? I have diffrent types of 3D cubes and i want to design levels with them without having to place one after one and arrange them in a grid but instead basically draw like in a tilemap. Thanks in advance!
Is there any way to set an emissive color to Text Mesh Pro text? I'm using a Screen Space - Camera UI and would like the text to be affected by bloom.
Did someone ever made or worked on a way to import SVGs (such as the ones Figma and Zeplin exports) to a generic prefab?
Or a custom import system for UI?
How do I use EditorGUILayout.DropDownButton
i've tried putting strings, textures, string arrays, texture arrays etc into this first argument (GUIContent) but it always has an error
nvm figured it out
had to create a new GUIContent
how do I use a dropdownbutton from this point on? Clicking it in the inspector does nothing
is it possible to remove the minimum size of an editor window?
@digital spoke Check the documentation, the button only returns a boolean, it should call on a custom GenericMenu https://docs.unity3d.com/ScriptReference/EditorGUILayout.DropdownButton.html
@meager chasm You could set the minimum size for your editor window to something tiny before opening it.
{
EditorWindow editorWindow = GetWindow<HelpWindow>(true, "Help", true);
editorWindow.minSize = new Vector2(10, 10);
editorWindow.Show();
}
oh, i tried that already, guess you have to close and re-open the window to get it to apply, whoops
@meager chasm put it in your OnEnable to ensure it is always set.
can someone help me out here? I've made a custom editor that's editing scriptable object files and all is great with the editor itself but for some reason the scriptable object files are throwing errors when unity loads them. they load just fine but unity still complains... so far i've tried: 1.deleteing the meta file, 2.tried reimporting the file, 3.googled about without success. here's the error for it: Unable to parse file Assets/Data/AI/BT/Test BT.asset: [Parser Failure at line 47: Expected closing '}']any help is greatly appreciated!
and heres the file:```yaml
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2032da47346b4904e9e65d2347498396, type: 3}
m_Name: Test BT
m_EditorClassIdentifier:
blackboard: {fileID: 11400000, guid: 0009731d10e36914393215e7b2396214, type: 2}
rootIndex: 0
nodeGroups:
- decorators: []
task:
json: "{\n "name": "Root"\n}"
type: StaterZ.Core.BehaviourTreeSystem.RootData, StaterZ.Core, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
services: []
isProtected: 1
childIndices: 02000000
pos: {x: 0, y: 0}
guid: 22686c7e-0e2d-471f-b3b6-2fa1d67936aa - decorators:
- json: "{\n "name": "LoopDecorator",\n "loops": 5\n}"
type: StaterZ.Core.BehaviourTreeSystem.Tasks.LoopDecoratorData, StaterZ.Core,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
task:
json: "{\n "name": "Wait",\n "time": 40.0,\n "randomDeviation":
0.0\n}"
type: StaterZ.Core.BehaviourTreeSystem.Tasks.WaitData, StaterZ.Core, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
services: []
isProtected: 0
childIndices:
pos: {x: 392, y: -199.5}
guid: be3950c6-f3dc-41c4-be46-10e066553d03
- json: "{\n "name": "LoopDecorator",\n "loops": 5\n}"
- decorators: []
task:
json: "{\n "name": "SubBehaviour",\n "behaviourTree": {\n
"instanceID": 28942\n }\n}"
type: StaterZ.Core.BehaviourTreeSystem.Tasks.SubBehaviourData, StaterZ.Core,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
services: []
isProtected: 0
childIndices:
pos: {x: -85.5, y: -207}
guid: 7a26449f-f40d-44fb-8002-413cf0921277
read your error
go to line 47 and then looka t the line above it, recognize that you're in YAML and that whitespace matters
That is of course assuming what you paste is accurate for what is in your files
How would I create a custom Project view icon depending on the content of a file there?
For example, I have a folder full of prefabs, and each has the default cube prefab icon. But I want to change the color of this cube depending on the contents of each prefab.
@tulip plank check project's gui callback
Project's GUI callback? Is project a class?
Okay, I will hunt for the details about what you're referring to, using the clues provided. Thank you.
@tulip plank You are asking for a custom Project view icon.
Look at this: UnityEditor.EditorApplication.projectWindowItemOnGUI
This callback provides you the instanceID of the drawn object.
From that, you can inspect it and display whatever suits you regarding the content.
@severe python i didn't know yaml was senitive to such... infact, don't know much about yaml at all 🙂 i think i've solved it now so thanks for the help!
no problem, and yeah, YAML is a white space language
so the number of spaces, carriage returns, tabs, w/e, they all matter
Thank you very much, @onyx harness !
Does anyone here know how to display arrays with property drawers
@timid cobalt I think you can do that by EditorGUILayout.PropertyField(serializedObject.FindProperty("x"), true);
Where x is the name of the array
and then serializedObject.ApplyModifiedProperties();
That doesn't work for arrays
I have already tried that
It works for everything else though
Ok
Hey, can someone help me with my editor method for converting Rotation Interpolation in animations to EulerAngles? When I use it it seems to be adding both rotations properties to the animation (I guess it's keeping the old CurveBindings and adding the new converted one) and when I add a line deleting the old one it deletes both. I don't know if it is because I'm editing dimension curves one by one (first I convert the x then y and z, instead of replacing the three CurveBindings together). I would really appreciate any help
@blissful sinew Bring some code to the table
{
if (curveBinding.propertyName == "m_LocalRotation." + dimensionLetter)
{
EditorCurveBinding newCurveBinging = new EditorCurveBinding();
newCurveBinging = curveBinding;
newCurveBinging.propertyName = "localEulerAnglesRaw." + dimensionLetter;
AnimationCurve curve = new AnimationCurve();
curve = AnimationUtility.GetEditorCurve(clip, curveBinding);
AnimationUtility.SetEditorCurve(clip, newCurveBinging, curve);
//This line deletes both
//AnimationUtility.SetEditorCurve(clip, curveBinding, null);
}
}```
Here's how I'm calling it
for (int i = 0; i < CurveBindings.Length; i++)
{
ConvertRotationInterpolationCurvesToEulerAngles(CurveBindings[i], animationClip, "x");
ConvertRotationInterpolationCurvesToEulerAngles(CurveBindings[i], animationClip, "y");
ConvertRotationInterpolationCurvesToEulerAngles(CurveBindings[i], animationClip, "z")
}```
After using it looks like this
Hey all, I had this issue before and forgot how it was fixed. I know it was in some settings... I just updated this project from a 2018 version, to 2019.2.0f1
Here are the errors in the log:
I posted here because most of it said extension 😅
nvm, Updating the package manually fixed it.
Window -> Package Manager -> MultiPlayer HLAPI
This clear the compiling error.
However, the extension errors still persist. Pretty sure the facebook build package didn't install properly
Is there a way to actually programmatically change the icon of an item in the project window (instead of just drawing over it) ?
Hah yes, all the solutions online are so very hacky, as I've become accustomed to with Unity solutions.
Use new SerializedObject({YourGameObject})
Find the path for the {icon} and set your texture in it.
These are project window items, so what would {YourGameObject} represent here?
Use this to easily get all the paths:
public static void OutputHierarchy(this SerializedObject so)
{
SerializedProperty it = so.GetIterator();
it.Next(true);
while (it.Next(true))
Debug.Log(it.propertyPath + " " + it.propertyType);
}
Oh sorry, don't use {GameObject}, but {AnyObject}
I can get the guid or assetPath of one of my prefabs, for example.
These are the files/items whose icons in the project window I'd like to conditionally change.
For example, a prefab can be marked as "Done". If so, I might change its icon in the project window to a green one.
Hum... I think I need to clarify one thing
You can customize Icon for scripts & Prefab
And I definitely don't care about its icon in the Inspector window, not at all.
I care about it's "file" icon in the project view.
Well, the only reliable way I know is the one I gave you already
Right, drawing over the existing icon. It is helpful, I can make it work to some degree.
Unity uses few methods to fetch an icon from an Object.
I just wish there were a way to actually change the icon.
But if you want your own custom icon, you need to do it manually
It's okay, I can settle with an overlay now, and tweak it around to work with every zoom level (since it moves around as you change the icon view zoom)
What do you mean a custom editor?
@tough cairn You can get layers using LayerMask.LayerToName()
@onyx harness is that possible to know the layers count ?
hhhh
64 perhaps one day
how does Unity finds out the layers tho ?
in the drop down screen shot
i mean it knows what to show
does it simply check all 32 via LayerToName for nulls /
I think yes.
( or empty strings - i didn't try to read the return value of the name of a none existing layer yet )
If one day, a user set layer 30th
How would you know? You kind of have no choice but to check all layers
searching someone who is good to animating for a project
2d platform
if the game will get money i'll give half of them to who helps me
var layers = new int[32]
.Select( (x,i) => i + ": " + LayerMask.LayerToName( i ) )
.Where( x => ! string.IsNullOrEmpty( x.Substring( x.IndexOf(":") + 2 ) ) )
.ToArray();
var layers_indexes = layers.Select( x => LayerMask.NameToLayer( x.Substring( x.IndexOf(":") + 2 ) ) ).ToArray();
EditorGUILayout.IntPopup( "Layers", 0, layers, layers_indexes );
