#↕️┃editor-extensions
1 messages · Page 8 of 1
What do you mean by this?
is there a way to avoid having to write EditorGUILayout.Space() everytime I want to add a space, can't it be shortened somehow
it seems it only sets a minimum width
Yes, of course. It's automatically aligned. One of the better features in the system.
I'm not sure what else you'd want or why
I just wanted all labels to have a fixed size like above
which works now
just have to override it for each label 🤷♂️
This sounds weird.
and at that point, none of them have the GUILayout.Width() ?
yeah
wait lemme try it again
EditorGUIUtility.labelWidth = 80;
this line
results
Post the full script
https://gdl.space
might be messy
the way I understand it though
just because you reserve 80 pixels doesn't mean it won't be bigger
This following line inside OnGUI is a bit overkill.
Place it inside void OnEnable instead. Then it runs only once, instead of several times per frame.
_managerScript = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
ah
I wasn't aware onenable was available
yeah I had that tab open but didn't scroll down far enough
but yeah seems like I have to override all my labels manually
You're somewhat extremely lucky that I've been available all this time, and have previously fixed this issue.
Replace GUILayout.Label() with EditorGUILayout.LabelField()
The mess between GUI and EditorGUI classes will easily make anyone's head spin.
It's an incredibly vague mismatch
well
I changed it to label fields and all
but now the width of my labels is the same, except I can't really change it
unless I missed something
actually the labelWidth thing doesn't seem to have any effect... 🤔
Well this is perplexing.
I have solved this in two projects before, but my initial tests right now cannot make it actually do anything.
did I miss anything
also in general how is the code structure
Curious, it does actually affect the width, but I can't seemingly get it smaller than what is shown above
but definitely bigger
ig for now I'll just stick to manually overriding them
probably gonna make a helper functio
I have created a property drawer to expose some variables of an object when its added in the inspector. This works when its a regular property, but if i add the object to an array it does nothing. Do i have to do something special for it to apply to lists?
My testing was skewed by using OnEnable, as I did not reopen the Window between tries. Use it inside OnGUI when testing.
i do have it in OnGUI
@tawdry kraken
but it does not work
I'll just use a workaround for now
🤷♂️
Doesn't work? What about what you said earlier?
it does actually affect the width, but I can't seemingly get it smaller than what is shown above
because it doesn't get smaller
Doesn't work isn't the same as being too limited to do what you need.
Np
true
Fair point
this is what I wanted to achieve though
anyway thank you
tremendous help overall today
This is how you can make an array of GUILayoutOptions.
It's one of the more difficult to comprehend.
GUILayoutOption[] options =
{
GUILayout.Width(10),
GUILayout.Height(10)
};
I don't use it at all, but from these issues I suspect you may find it useful.
You're welcome 👍
Ahhh
That seems pretty good
I solved it like this for now
since for now I only have labels like this
and if I wanna change the width I don't want to edit 100 labels
That's a good solution.
Alternatively:
private GUILayoutOption[] _width = { GUILayout.Width(10) };
//..
EditorGUILayout.LabelField(str, _width);
mostly useful if you're going to mix and mash layout options
@lilac wave Last thing, your Window needs better code to Open/Close correctly.
And perhaps a hotkey for easy access.
^ is CTRL
is Shift
& is Alt
_ is no modifier
private static bool _isOpen;
[MenuItem(" Tools / My Window _F12")] // <-- no modifier F12
private static void Window()
{
_window = GetWindow<MyWindow>("My Window");
if (_isOpen) _window.Close();
else
{
_window.Show();
_isOpen = true;
}
}
private static void OnEnable()
{
_isOpen = true;
}
private static void OnDisable()
{
_isOpen = false;
}
The Shortcut attribute is much improved and I wouldn't add shortcuts directly to menu items any more
That sounds interesting, and it seems to tie into Shortcuts (the manager window)
But I see two problems:
- Doesn't display tooltip in Shortcuts
- Doesn't show up in the actual menu item.
I'm not sure what you mean by the tooltip thing, but yeah that does suck. Personally it's a small price to pay for rebinding, conflict resolution, and a sensible attribute constructor. I'd love if they added it to menu items though
For large projects or collaborations, it seems a priceless tool.
For beginners, a bit impractical for the scope.
Thanks for making me aware. @visual stag
And for anyone reading, the docs are a bit unclear:
[Shortcut("Name in Shortcuts", KeyCode.F11, ShortcutModifiers.Control | ShortcutModifiers.Shift)]
private static void Example() //...
// Additional overloads
// Context: Only when this EditorWindow type is open.
[Shortcut("Name in Shortcuts", context: typeof(EditorWindowTest), KeyCode.F11, ShortcutModifiers.Control | ShortcutModifiers.Shift, displayName = "Optional name in shortcuts")]
Ah, it is possible to add a shortcut to any existing MenuItem, including ones created by users. (Shortcut window)
Does the shortcut end up appearing on the menu item in that case? Itd be weird if it did if it doesn't when you additionally use a ShortcutAttribute
Huh, indeed it does appear!
At least there's that :)
That probably means it's possible to use ShortcutManager.instance.etc to rebind all existing binds 🤔
Thus fixing that
I imagine there's some specific combo of paths or something that would tie the menu item to the shortcut attribute. Maybe I'll look into it when I'm home
That would be nice.
At worst, I fear you need to dig into the source code.
ShortcutManager isn't doing anything for me yet. Might need internals.
I hope this is the right place to ask this, but I am trying to find a way to edit the 2d animation package to fix a known bug, but every change I make reverts. I've been searching how to edit Unity packages, and the best thing I have seen says I have to remove the copy the package and edit the copy, but that would break everything else even if it did fix my issue 😄 anyone have a direction for me?
I'll keep asking around too. 🙂
I'm not really familiar enough to say, but as a side note: If you have instructions which can reproduce the bug, Unity themselves should be able to fix it.
From what I have been told it is a known issue, but I am not really sure because the fix seems really straightforward. Just an issue with a Count parameter being used as a method, so all I have to do is delete a bunch of empty () parentheses and its fixed, but it keeps reverting it back.
seems like if they knew about it a hotfix could sew thing up quickly, but what do I know.
There's a copy of every package in the local AppData cache
My first bet is they are using that. But they might be checking online, or even validating those as well.
Make sure the local copy is also your modified version.
C:\Users\YourUserName\AppData\Local\Unity\cache
Only other thing I can consider, is perhaps giving your package a higher version number.
(I really don't want to bloat the chat any more than necessary.)
@north sphinx here
Either @gloomy chasm @waxen sandal can definitely answer your doubts here... I'm just an NPC regarding SOs as I'm not too fond about it
for context #archived-code-advanced message
sorry being sus here 🤘
If you have a domain reload then all instances get recreated (since well, the domain is unloaded so there's nothing left)
Not sure what you mean without domain reloads @north sphinx
I disable domain reload
Are you seeing an actual issue or is this hypothetical
hypothetical
as of now I just unsub on every registered event
but it's kind of
doubles amount of code
In that case you are responsible for cleaning up references and subscriptions
So SO C# objects are persistent between Play modes?
I think there's no guarantee that they are destroyed but they might be in some cases
why this over init?
the name of the method doesn't matter
SOs don't reset their data when exiting Play Mode, unless you create a function that does it
not data, C# instance
Ah, they are assets, so I don't believe they are destroyed.
But C# instance, I can't say 🤔
I think this might have a bug though
window gets closed instantly when I try to openit
hey i have a prefab and i change materials of gameobjects that gameobject has, lets say i have a level and i have 3 items in level. when i press button item colors changes. but i dont want this to be overriden. when i save the prefab and exit prefab mode i dont want this to be overriden
in this level prefab item colors changed if i save and exit prefab mode
basiclly i dont want this changes to be saved to prefab
is there a way to achieve this?
maybe a method from prefabutility
I am using this exact code in two other projects.
Post your full script.
Restarting Unity might fix it.
Only difference is your GameManagerWindow window is local instead of private.
Just make it private.
I'll see how it is with the restart
it did not change
like it works once to open it, and when I close it then it won't open again
it works if I don't do add the onEnable/Disable
and handle the isOpen stat in the open function
Pardon the late reply. Good that you made it work.
I'm not sure why you're experiencing errors with code which works for me, unless I'm messing up, or you're on a different version of Unity. I'm on 2021.3.
If you can bother, I would like to read the code which works for you.
Otherwise, good luck and have a nice day.
I can always bother
but tbh my unity has been wonky recently anyway
whenever I drag a script to a component it gets added twice, some gizmos are not displaying properly
Which version are you using?
What do you mean by 'added twice'?
2021.3
it's not the right channel but when I drag in a script it gets added twice
instead of just once
I'm having trouble making a custom editor for a component. Here is my code (located in /Assets/Editor/)
using Levels.Game.Scripts.Environment;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(TimeOfDay)), CanEditMultipleObjects]
public class TimeOfDayEditor : Editor
{
public override void OnInspectorGUI()
{
//base.OnInspectorGUI();
GUILayout.Label("HELLOW!");
}
}
But still the Inspector shows the normal editor (when it should show only the Hello label)
What am I doing wrong?
Nevermind i see that after compiling i must de-select / select the component before it will show up with the updates
Question: I want to have a button on a component that opens up a pop-up window for you to enter a value in, and then when you hit accept it closes the popup window and uses that value. How do I make a pop up window like that?
This is one of the few classes that allow you to make popup windows
Though a trade-off is you can't drag the popup around
Another means if you're looking for specifically making a popup-style editor window is: https://docs.unity3d.com/ScriptReference/EditorWindow.ShowPopup.html
how do i get a return value from this?
if i have a base abstract class with a custom inspector - how do i get it to show with a derived class which doesn't have a custom inspector?
because it seems i have to make an editor script for every derived class to show the base class inspector which is ridiculous
all my base class does is show a label field
The CustomEditor attribute has a Boolean you set to be derived
i set that to true but it didn't show the custom inspector
[CustomEditor(typeof(ObjComponent),true)]
you mean this right?
when it is set to true all that changed was it showed a notice about multi object editing:
but doesnt show the base class inspector only the Condition class which is derived
If you see the multi object editing thing without having multiple objects selected you should reselect it to fix the editor
You'd need to serialize the object you're modifying and set the value through serializedObject.FindProperty()
once you've changed the value, if the accept button is clicked then you do SerializedObject.ApplyModifiedProperties()
oi
Yeah?
What if I just passed a string back to a callback method? somehow?
Are you just trying to set a string value?
Is this for a game object - or is it for a ScriptableObject?
Could be either, but the most important is scriptable object. Basically, I have 2 scriptableobjects (that gameobject components depend on) that can connect to eachother by an ID. I want to make a popup on a custom inspector for the scriptableobject I've made that allows you to select another one from a list (Ive already written the list) and it will "connect" both by adding the ID references to eachother
So you want to do more probably a GenericMenu?
Generic Menu is arguably more suitable to that task as that's all you need for the popup behaviour you're looking for.
You have to manually add each element though
I'll have to look at that
I have a method for it
I'm just trying to figure out the specifics
so, if you were to have say a list of objects - A, B, C, D, E and F
if you wanted to link A to C, you clicked on the option then A will be linked to C
and then C would link to A in return
yeah, basically. I would hit the button on A and a popup would let me choose C
I sent you a method for automatically laying out a dropdown in DMs because it's experimental and the documentation is a bit finnicky with it.
I'll try to help you as best as i can
Is it possible, and if it is, how to implement somewhat of a custom component system? I wanna make some state machine creator with xNode framework and I wonder how to achieve funcionality implemented in AnimatorController, where to every state you can assign StateMachineBehaviour class, just like a MonoBehaviour to any GameObject. I already peeked a bit into AnimatorController source code, but it is a massive chunk of not commented code that I dont understand at all. All I got from it is that StateMachineBehaviour class derives from ScriptableObject and is somehow "converted" into what it is, but that is all that I uderstand unfortunatelly.
how do you get a dictionary in a custom editor so you can iterate its keys/values? i tried serialized property but i cant figure out from there how to get the data back to the type i want
Dictionaries cannot be serialized by default by Unity
well i also tried reflection but thats giving me problems too
What are you wanting to do?
oh it suddenly decided to work
i just wanted to text output the dictionary
reflection did the job
seems reflection is a lot simpler than unity's serialised property nonsense
var result = typeof(TestObj).GetField("_test", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(target) as Dictionary<int, float>;
foreach (var kvp in result)
Draw(kvp.Key, kvp.Value);
was how i got it to work
how could i make it to where, let me explain in simple (ish) terms:
i have a WeaponSystem script.
i want to have custom values i can edit based on what Round Type i choose
for example, if i chose "shell" it would only show up shotgun settings.
how would i go across doing this?
im confused how do i change a field from serialized properties? I have in my scriptable object:
[SerializeField, HideInInspector]
Color _pathColor;
And then in my editor class i have:
var c = serializedObject.FindProperty("_pathColor");
c.colorValue = EditorGUILayout.ColorField(c.colorValue);```
but this doesn't seem to work how do i make sure it applies to back to the field `_pathColor` in my scriptable object?
very confusing api unity have made for this
Right-click the Property in the inspector.
Select: Copy Property Path
also, in order to actually apply the changes you made, use serializedObject.ApplyModifiedProperties()
You'd want WeaponSystem to implement some interface and check if ISomeInterface implemented to WeaponSystem
ah was missing the apply
thanks ! docs dont make this easy to find ! 😄
It's a bit overwhelming when starting out. A good tip is to simply copy the docs examples and see how they run.
yeah though a lot of their code examples dont cover much or explain much
i had to dig deep into the forums to figure out how to click in the editor window without losing focus in inspector on my scriptable object
On some of that, I would agree, but the more I learn, the more the docs make sense.
In 2021 you can now right-click any Object (including components) and select Properties,
to get a separate window that will not have focus conflicts. It wasn't persistent between sessions before, but it is now.
i meant for selecting things in the scene window
if i clicked to select a node it would defocus the scriptable object in the inspector lol
was a pain
exactly, you can either Lock the inspector, or have a Properties window
What solution did you come up with?
apprently adding this:
HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive));
before you use the event fixed it
Interesting.
now i can add nodes and it wont lose focus
That's handy.
yeah!
is there a way to call an editor function from another editor script for example a player references a scriptable object, now i want the scriptable object's path to be drawn in the editor when i select player which is a method in the scriptable object's custom editor
I think you have to be more specific.
What type of function are you going to use to draw?
or do you mean File Path to the asset?
Player has a reference to scriptable object Path @tawdry kraken when you select SO Path it shows the path in the scene view, but i need it to also show when i select the Player which has a reference to that Path
Show the code you're already using.
to show the path in editor?
How does it show the path in the scene view?
i have a method in PathEditor : Editor which draws on SceneGUI:
for (int i = 0; i < points.Count; i++)
{
var point = points[i];
if (_modifyIndex == i)
{
Handles.color = new(1, 1, 1, .3f);
Handles.DrawSolidDisc(point, Vector3.up, .55f);
}
Handles.color = _colorProperty.colorValue;
Handles.DrawSolidDisc(point, Vector3.up, .5f);
var pos2D = HandleUtility.WorldToGUIPoint(point);
var rect = new Rect(pos2D.x - 60, pos2D.y - 10, 120, 20);
Handles.BeginGUI();
Handles.DrawSolidRectangleWithOutline(rect, new Color(0, 0, 0, 1), _colorProperty.colorValue);
GUI.Label(rect, _target.PathName + " -> " + i);
Handles.EndGUI();
}
looks like this
this is when the SO is selected
but i need the path to also show now when i clicked the object that has been assigned this path
I would imagine something like
That code segment should be a public method.
Make a custom editor for the Player (or use a different approach)
so that when the player is selected, it executes that public method.
is it possible for PlayerEditor : Editor to access PathEditor class from the player's reference of the Path class?
i get the impression it isn't possible
because Path doesn't have a reference to PathEditor
If you can move the logic to the static, I believe it should be possible that way, but I have not actually done this before (with custom editors).
Do you have a firm concept of how static works? @snow pebble
Hi there (dunno if this is right here to ask)
does anyone know how to use a custom property drawer inside a custom editor script?
Custom property attribute doesn't work (help)
- If it's valid to ask about custom tools here, are there any manuals out there on how do i add interactive gui elements to my objects? In a nutshell, i make an alternative resize tool, being able to expand and contract my "object". I'm a complete beginner to this and i struggle to find anything related to this, probably because of my poor terminology
You can use [DrawGizmo] on a static void.
This is a problem I encountered with my own custom AI regions system in university.
What you would do is have: ```c
// In selection hierarchy if you want to have it display when the object attached to a path is linked
[DrawGizmos(GizmoType.Selected | GizmoType.InSelectionHierarchy)]
public static void DrawAssignedPath(yourObjectType t, GizmoType gizmoType)
{
// ... Path Drawing Code here for Gizmos ...
}```
This attribute is able to work in editor scripts.
this is the attribute in action with my AI path system (ignore the UI, it was placeholder by another student in our team project)
- I managed to make a resize tool with 4
ScaleSliderhandles around it. It invokes a method of the edited object directly, passing the drag value in there. So it's first 1, then 2 and so on. This makes my object expand by 1, 2, 3 etc. grids, and this causes my object to scale way faster than the cursor tells it to. How can i work it around?
@earnest talon@tawdry krakenah i had a suspicion i would have to use statics - okay i will go for that then, thanks!
How do i use enums with serialized properties? I tried this:
_typeProperty.enumValueFlag = EditorGUILayout.EnumPopup("Type: ", _typeProperty.enumValueFlag);
but it seems to not like it im not sure how to do it correctly
So how do you get editor variable fields to display in the Inspector, as opposed to an existing custom window?
how can I display OnInteractivePreviewGUI in a VisualeElement (uitk) container?
why not just EditorGUILayout.PropertyField(_typeProperty);?
oh I forgot IMGUIcontainer exists 
When creating a new asset, Unity will automatically rename it to prevent duplication. AssetDatabase.CreateAsset will silently overwrite an existing asset if you give it a path that already exists. Is there a function I can call that will give me a path that doesn't conflict (by adding the correct number to the end)?
for example:
Seems there's this: https://docs.unity3d.com/ScriptReference/ObjectNames.GetUniqueName.html
But that's for scene names?
oh, list of existing names...
Okay, so I can load all assest in a folder and check
oh, amazing!
Thank you!!! <3
Is it possible to make a scriptable object numeric, dynamic ID system?
e.g I create a new object, which auto generates a readonly id which equates 64, because there have been 63 other objects of that kind.
Is there any way to cache a variable into the unity editor?
Then, on validate for my scriptables, I could just assign the id based on the cached count.
I'm having a teeny issue. I'm trying to get a struct to have a custom editor, but all I'm getting is a "No GUI Implemented" message. It works for other elements that I have made, so I'm scratching my head as to why this does not work
In this example, Level is of the Stat_int type
I have found my answer 😄
I really don't recommend doing this. What if you are working on a team, you create one, and someone else on the team creates one. Neither of you push so both would have the ID of 64. You could of course do some sort of validation on asset import or something else. But unless you really need it to be an integer I would recommend using System.Guid.
Here is a serializable implementation that I use all the time if you want it 🙂
https://gdl.space/uyicoruzaz.cs
@gloomy chasmThank you!!
Anyone know how I could insert the custom editor buttons along side each element?
Hi there!
I'm having trouble with my editor preview system. Whenever i set a color on the same sprite on two custom tile the colors merge I have provided in the video what is happening, here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Tilemaps;
[CustomEditor(typeof(LevelTile))]
public class LevelTileEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
}
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
{
Tile Target = (Tile)target;
if (Target.sprite != null)
{
Texture2D newIcon = new Texture2D(width, height);
Texture2D spritePreview = AssetPreview.GetAssetPreview(Target.sprite);
Color[] pixels = spritePreview.GetPixels();
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = pixels[i] * Target.color; // Tint
}
spritePreview.SetPixels(pixels);
spritePreview.Apply();
EditorUtility.CopySerialized(spritePreview, newIcon);
EditorUtility.SetDirty(Target);
return newIcon;
}
return base.RenderStaticPreview(assetPath, subAssets, width, height);
}
}
Thanks!
pls
anyone
having a look for you. Is this what you are trying to create or am I missing something?
https://gyazo.com/65ea9fe67d89e8b647b4c84ba73b9d17
Kinda, i'm trying to make the icon on a custom tile (inherited i think is the word) appear, as it doesn't appear whithout doing some funky code The object's code is
public class LevelTile : Tile
{
public TileType Type;
}```
Just inheriting, with taking a TileType.
Thanks!
But yeah, kinda like that
https://gyazo.com/8d0cda868f29a17bd395c33ee9064156
https://pastebin.com/nMZmjeFu
@fierce cave think this does the trick. I used sprite.texture but might be able to still use sprite 🙂
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.
To resolve it, I made a copy of the current assetpreview texture which I saved in a new Texture2D, this way there is no way the texture is applied globally to all previews.
Thanks! That completely fixed it!
Now all i need to do is finish replicating all the tile editor formatting stuff 😅
How can I zoom in/out OnInteractivePreviewGui? ... pretty sure we can do this by default when previewing in inspector but when put in a IMGuiContainer just the model being shown
var t = new IMGUIContainer(() => edtr.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(prevWindow.contentRect.width, prevWindow.contentRect.height), bgColor));
I can manipulate the Rect for zooming in/out but still looking for a built in solution if any
aight, seems like OnPreviewSettings is what I'm looking for
How do I save a sprite generated in the editor to asset folder?
By "sprite" do you mean a Texture2D?
Nice.
In the past I have output it as a PNG
Using System.IO to actually save it to the file I want
There might be a better way.
Just AssetDatabase.CreateAsset("Assets/MyPath/MySprite.png", sprite); 🙂
(In case that isn't the way you figure out)
AssetDatabase is extremely handy
Indeed!
One thing I'm looking to find is if I can forcefully set the background of the editor window element itself.
What do you mean?
To directly change the GUIStyle that an editor window is created with
instead of having it in the default, usual grey
changing it to be, say, transparent
or cache the screen
one of the two would work.
well then I'm thinking
Cache the screen
and use that as an overlay for a draggable windows HUD, of sorts.
I know we can make draggable windows but the limitations of events isn't good.
Can you explain what you are wanting to do?
Create a popup window with a semi-transparent overlay so I can create a grid which I can use to provide developers with the means of creating draggable, borderless windows in an overlay.
I've seen caching the screen done before, for a contained editor window
and if that's possible then you can for sure do it for popups
only reason to do this route is because, even with draggable windows without such a technique the means to handle mouse dragging stops if the mouse cursor falls out of the editor window itself
meaning you can't actually take into account editor window offsets based on cursor position
Oh, wait so you just want it for your own window, not every/any window?
yeah
OOOH
What I want is
That makes it way easier!
Unity Editor stays the same
we don't touch that
that would be a bad idea
very bad spaghetti code idea
There is an article on it
thanks, that helps a lot.
My reason for this
is I'm building an Editor Framework
I've got a 1.0.0 done and I'm doing documentation for it actively
I thought you were wanting it to be for any editor window. And that would require a bunch of reflection and stuff. And even then it would be iffy.
It's nothing fancy, I'm building it so others students at my university can get an easier introduction to Editor Windows.
Oooh?
yeah that's gonna be dumb lol
but it's basically a lot of simplified nomenclature and stuff that abstracts Unity's IMGUI-style editor window creation (for context on why I deleted the image, just got a message to delete it from someone else - not moderators/unity staff)
Ooh, very cool!
(also I'm fine with my uni being known for various reasons, this would be in the final publication anyway)
If you can I would look in to UIToolkit, probably be easier to learn for some people!
Also, IMGUI is going the way of the doe doe (at some point)
Ahh
I'd immediately say
deprecating IMGUI for editor windows is a bad idea
It's definitely the most accessible way for programmers (or ones that I've shown it to, now they understand it)
some of the stuff I added into Cappuccino are personal taste, others are more broader-reaching
I mean, IMGUI isn't going to be deprecated. It is used in far too many assets and projects. But all of the default editor is being rewritten to use UIToolkit.
ah fair
that's good
here's one of the things I've added with Cappuccino
A property wrapper
allows me to create (kinda) serialized properties, directly pull the value as a cast-necessary object
and find underlying properties directly w/o FindPropertyRelative
there's also extensions, hence the partial
Array Handling, CProperty.Draw (simpler than EditorGUILayout.PropertyField in a lot of ways but just uses that & EditorGUI.PropertyField)
I see... well whatever works for you!
yeah it's definitely not the best in some regards
other regards ofc being more personal opinion
thanks a lot for the screen capture article though
that's going to be extremely helpful for creating the first extension for this framework
by far the most creative error I've ever seen in unity.
LOL
I did get it working before, mostly
just decided I wanted to capture the whole screen
Turns out 128GB might not be enough for over 8 million pixels worth of colors.
anyone tried UIElements? looking for feedback on if u liked it and why
looking to set up editor stuff soon and I'm already quite familiar with the vanilla way.. wondering if it's worthwhile going with UIElements instead for w/e reasons
If you just want to hack something together go with imgui
Need to maintain it longer? Go with uie
I'll just say
UIElements is practically what happens when Unity butchers web-dev languages.
As much as I can understand why they went for it and why it's a more native layout language
It just won't surpass IMGUI in terms of legibility a lot of the time.
i'm planning for long term yeah.. curious why you say so though (?)
With UI Elements, you're dealing with (Essentially) forked CSS & XML
Unity has said it's the future and it's arguably easier to maintain more complex editors
Well, complex editors can be easier to maintain
with just a good file structure
an some basic housekeeping
I use a practice of "Editor" and "Panels" layout, where Editor Windows and each subsequent attached panel are separate
the project is some quite complex (hoping to simplify over time via design iterations) visual scripting
no, I'm a vanilla guy
everything is pretty much copy-pasteable to Unity 2017 😛
still experimental for god knows how long
I'd be surprised if there's any devs working on Unity 2017 nowadays
yeah I sticked with Unity 2017.4 until unity 2021.3 was here 😄 REALLY not much for experimental stuff 😄
The way to put unity and experimental stuff into context
the entire engine's experimental.
oh well the stability and performance makes up for it in every way
They've left GraphView on experiemental for years
and I don't know if they just forgot a few years back to remove the experimental tag
or they just forgot to finish it
anything to back it up? 😛 either from Unity's side or yours
If you're going 2017.4
go IMGUI
no I'm with 2021.3 now
Nothing public from my side, idk what unity currently has as public demos
I'd argue IMGUI purely for legibility (provided you don't write code without comments and follow some sense with structure)
and for backwards-compatibility.
UIE is basically butchered web-dev crammed into the engine
UIT barely works on earlier verisons of unity because it was designed for later ones
what is UIT?
UI Toolkit
Without a doubt though, IMGUI is probably one of the best GUI creation toolkits I've ever seen for a game engine
purely for how straightforward it is.
I totally agree
if you're a programmer and you have a grasp for what Rects and Vectors are
as well as a basic understanding of "sprites" (kinda), you're able to pull off LOTS of crazy stuff with IMGUI that just
you can't really with others
IMGUI is just that flexible and powerful.
ikr lol.. UnityEditor.dll in general is so OP
and UnityEngine.dll is just simple.. which can be good as well
the fact I can do all this in IMGUI
and still understand every line of code
it's way better.
I'd say for sure UI Elements is a good inclusion into the engine
It'll enable web-developers to start getting involved with toolkit creation
but there's nothing that compares to the careful management you can obtain with IMGUI
btw are GUI calls also considered IMGUI?
yeah
Immediate-mode GUI
all that's just done via Handles (in the scene view)
I just like to include extra wrappers like this personally
pretty much how that handles GUI works.
cool!
I would have an aneurysm trying to exploit the way editor windows are created
if I were ever forced to use UIE for it
I'd imagine the only difference in UIE would be the design of the layout stuff.. Like literally expecting to use it in editorWindows like so
override void OnGUI() => UIE.EmbedLayout("..somepath", context: this);
Do you mean on the future part or on the easier to maintain part?
either, but I'm mostly interested in the maintaining part
Forever, Unity is replacing it with something called GraphToolsFoundation which will be a more complete package and all graph based tools in Unity will use.
I'm guessing it'll still be in the API at least
Ahh, well it tends to be easier to maintain for a number of reasons. It separates style from logic so there is less clutter and mixing of concerns. It tends to be easier to do more complex things in a more readable way.
considering the amount of people who experimented with, well, experimental tech
It'd make at least some sense to keep it in
Yeah I would imagine so, at least for a number of versions.
when it comes to UI Elements though, I don't think it's easier to maintain for everyone
USS and UXML are forever web-dev language forks
Also, they have stated repeatedly that IMGUI (and UGUI) is going to be replaced with UIToolkit. It is quite literally the reason they made it. They are working on rewriting every editor window currently. The inspector, and sceneview have already switched over. I know they are working on the Hierarchy, and I think they said they are rewriting all of the custom editors as well.
I'd use UI Toolkit for sure, just right now it's not compatible with half of the versions we use at university.
for some reason it just force CTD's Unity Engine every time you try use the package.
(Unity 2020.2/Unity 2020.3 is the versions this is happening in)
It does what?
Crash to Desktop
Unity 2020.2/2020.3 just doesn't like UIToolkit
maybe it's some patches more than others but some of us have had our projects corrupt because of it
(which is probably in part due to the PC security too)
Ehh, that is odd. 2020.3 works fine for me. I have developed an asset on that version that makes heavy use of UITK.
reading more about Unity's documentation for UI
it seems they take a more nuanced approach on who should use UI Toolkit (or rather who it's most suitable for)
and I'm guessing it's all based on preference given their considerations in the manuals
Which version are you looking at? Also, their runtime and editor UI recommendations are different.
For the editor, they recommend UITK now
2020.3, 2021.2, 2021.3, 2022.1, 2022.2, 2023.1
and yeah I can see why they recommend it
and I've been reading carefully about it
For the use cases and structuring I follow
IMGUI is better
that and I don't like doing web-dev-like code because it's just annoying with tags.
anyone knows if and how would I be able to suppress this warning in specific cases? (e.g.: when [SomeAttribute] is applied to something)
You'll have to show code, instead of screenshots.
Is it enough to manually write the workaround each time?
no, lol.. I want a solution that just works
prepared to add an analyzer if no solutions are found.. would just like to avoid that for some extra performance in compilation
Do you know how to suppress warnings in general?
yeah in either a per-case context or a global context.. I just want to get rid of the false-positives tho -- specifically to events I apply the attribute on
Hm. Why does this error appear?
Why is there an event which is not being used?
I'm not trying to be coy. I am looking for the phrase for something I think might work.
Meanwhile, I wonder what could identify if it would not be used
But it's a compiler-level thing, so I'm not sure if that would make sense even if it was possible
I'm using the attribute to scan usages via reflection, and inject on them -- so the events are used, but as far as the compiler can tell, they aren't
Would it cost you to write it so that it is being used?
My search yielded no results.
A pragma warning disable is the normal way to deal with this issue.
I'm not aware of any other ways. There could be a VS Extension for it.
you mean instead of using reflection for invoking it? or create a dummy class that just accesses it?
a dummy class or anything called DoNothing or IJustExist
There is actually a function in Unity's documentation named DoNothing() {}
well I would consider invoking it to another dummy class, but it's an event, only invokable by the class that hosts it
child class then?
and I REALLY don't wanna add a random unused function to all the classes that use that attribute
still not possible. events are only invokable by the class that hosts them
I could potentially just discard the event keyword as last resort lol.. but curious on how one'd go for it normally
Does the event have to be used in that manner?
What if you just print the name of it, so that the variable itself is in use?
an event, only invokable by the class that hosts it
Apparently, there seems to be a hack to work around that.
https://stackoverflow.com/questions/4378339/raise-an-event-of-a-class-from-a-different-class-in-c-sharp
these wouldn't work either -- the warning won't go away unless there's an .Invoke() call of some sort
Well, last idea I have is you could write a VS Snippet to encapsulate existing code in a pragma warning disable
would be fast and translate to any other project
thanks, I'm more considering this though -- if it's hard for the compiler I can only imagine how hard it'll be to debug in the future
I'll give it a day and decide tomorrow whether I wanna just go for an analyzer or completely rewrite the architecture lol
thanks! was good crossing out all potential solutions and getting feedback
Disclaimer: I don't know of all solutions 😅
Anyone know how to input editor buttons within a class drop down?
like if you make a custom class that's serialized so it's viewable in the editor, and then want to make a custom button within that default drop down menu, how would you do that?
You would use a Property Drawer https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
This could be what I need, and definitely is for most things, but would this work with GUI buttons?
It is just a GUI call, you can put any GUI code in there that you would put in a editor or window
You sure? Cause one of the tutorials I'm looking at calls it a custom property drawer, and im used to putting the buttons in custom editors
It is a custom property drawer. When you do EditorGUILayout.PropertyField(myProperty) that is basically just calling the custom property drawer's OnGUI method.
Interesting, I'll definitely play around with it and thank you for the tip
Should I be concerned about this?
Child GameObject 'Wall_Narrow_Block(Clone)' was not registered into undo system and became dangling during an undo operation.
Use Undo.RecordCreatedObject to correctly add a child GameObject which can be handled by the undo system
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler ()
I have registered every object with the undo operation, but I think repeated creation + destroy of objects during the same undo step is causing issues.
yeah you should fix it imo
- it's annoying to see a warning
- you might wanna actually undo at some point
I'd say go for a single undo addition per mouse release, instead of when merging blocks / on SceneGUI or smth
Which Unity version?
There is only one per mouse release, the problem is that as the mouse is moving it's creating and destroying many objects (at least that's my assumption as to what is happening).
Perhaps I can keep track of the first round of deletions and the last round of additions. I'd need to somehow get the release event to submit them, which I'm not sure I can get from a drag handle.
no you should just not delete them until the mouse is released -- imo
-- mark them for deletion, then mass perform OnMouseReleased with a single undo
can 'hide' the 'marked-for-deletion-objects' if this sort of thing is THAT important. I'm usually marking them with red and fading their alpha while keeping them in some list
or, well.. if it's a grid thing in which you know no more than 1 objects will be on that specific grid cell at the same time, then deleting real time and forgetting is an option
Hm. Yeah I could do that. I'm generating a wall that updates as you swing it around. Seemed easy to just use the normal generation code that deletes all and creates them again.
But if I can somehow get an event for when the handle stops moving I could do something like that
But it's kind of just called once per frame so I'm not sure how I'd find it when it ends
I'll have a think about it. There must be some way to do it.
Feels like you be doing in a way that should not be done. Also, yeah you should be concerned about the warning. Assuming I remember correctly, that GO is still there in memory, just sitting there. That can cause unexpected behavior and also over time increase the memory usage of Unity.
Thanks. That was my concern re: memory.
I'll have another go at the problem tomorrow. Might take a bunch of unwanted code but I'm sure I can solve it somehow.
Kind of a long shot but I will go ahead and ask here.
I have a method that creates VisualElements for each item in a list and 'binds' their value to the expanded state of a the serialized property. However the expanded state is not keeping for all of them.
foreach (SerializedProperty fxItemVariableProperty in fxItemsProperty)
{
var headerFoldout = new ScatterFXHeaderFoldout();
headerFoldout.value = fxItemVariableProperty.isExpanded;
headerFoldout.RegisterValueChangedCallback(evt => {
Debug.Log($"Set {fxItemVariableProperty.propertyPath}, to: {evt.newValue}, from: {fxItemVariableProperty.isExpanded}");
fxItemVariableProperty.isExpanded = evt.newValue;
});
// Other stuff here...
_fxItemsContainer.Add(headerFoldout);
}
Here is the inspector that it creates. Note that the two expanded items are set to "preset", and they are numbers 3 and 4. Only when things are set to "preset" are the expanded state saved for some reason.
Additionally, you can see the debug.log message that is sent when you select a the Scriptableobject that the editor is for. You can see that neither 3 or 4 show up. It spams the value changing 10 times for each other item (weird UITK thing?) and it oddly sets the to true a couple of times. Any ideas?
Any idea how to find out when the drag event ends in the editor?
It seems that the change check returns false during the drag
Basically my problem is this: I'm dragging a wall around using handles, and generating blocks to fill out its length. They get created and destroyed during the drag. I want to be able to undo this operation afterwards, but I get a warning about dangling references if I both add and remove the same prefab instance during the same drag operation.
probably would need to see how ScatterFXHeaderFoldout is implemented
lol tried to make a video
Obtained 35 stack frames
0x00007ff7d4125381 (Unity) DestroyOrphanedObjectHierarchy
0x00007ff7d4124618 (Unity) DestroyOrphanedChildrenAndComponents
0x00007ff7d4122b19 (Unity) StructureUndoBase::ApplyInternal
0x00007ff7d41345c0 (Unity) ObjectUndo::ApplyUndo
0x00007ff7d4134f7c (Unity) UndoManager::ApplyUndo
0x00007ff7d4140f02 (Unity) UndoManager::Undo
Yep, this does seem bad.
Does Undo.RecordObject include its child objects and components?
It is nothing special, basically just a copy of the unity foldout element https://gdl.space/udupenerow.cpp
Cool. Okay... So I feel kinda stuck with this, but I know there must be a way.
there's a lot of setting values in loops in this code, like _headerToggle.value is set in value, and then SetValueWithoutNotify is called, which also sets it.
I'm fairly sure that it wouldn't loop a bunch, but I wouldn't write code that relied on that fact
Oooh, it does loop you're right!
so you could click the button, which sets header toggle, which sets value, which sets header toggle twice... it's a lot
if you set you set value, which calls _headerToggle.value, which then calls value again the first time I think, and then you have it running twice
value should definitely be using _headerToggle.SetValueWithoutNotify, and so should SetValueWithoutNotify
Yep, you're right! Switched it. Though it didn't change anything.
Worth noting, if I do Select > Expand > Deselect > Select it will still be expanded, but going Deselect > Select again it will no longer be expanded.
I can't really think of why it would do that, but I can only imagine that your logic is setting the toggle or value somewhere else, or perhaps some logic is the inverse of what you think it is, like a toggle appears expanded but returns false
Idk why it would only be doing it for "preset" though. "preset" is a pool so I almost wonder if that could be messing it up. Also feels like there is a chance there is a Unity bug. Will probably try to repro it I guess
I haven't seen any pooling logic, but if there is any that sounds like a point of concern for sure
public static void GenerateAgentTypeNamesEnum(string path, string enumTypeName, string namespaceString)
{
int settingsCount = NavMesh.GetSettingsCount();
if (settingsCount <= 0) return;
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"namespace {namespaceString}");
stringBuilder.AppendLine("{");
stringBuilder.AppendLine($"\tpublic enum {enumTypeName}");
stringBuilder.AppendLine("\t{");
for (int i = 0; i < settingsCount; i++)
{
string agentTypeName = NavMesh.GetSettingsNameFromID(i).StripSpaces();
int agentTypeID = NavMesh.GetSettingsByIndex(i).agentTypeID;
stringBuilder.Append($"\t\t{agentTypeName} = {agentTypeID}");
if (i < settingsCount - 1)
{
stringBuilder.Append(",");
}
stringBuilder.AppendLine();
}
stringBuilder.AppendLine("\t}");
stringBuilder.AppendLine("}");
File.WriteAllText(path, stringBuilder.ToString().TrimEnd());
AssetDatabase.Refresh();
}
}
For some reason this is not giving me agent names beyond the first one.
This is what it produces:
public enum AgentTypeName
{
Projectile = 0,
= -1372625422,
= -334000983,
= 1479372276,
= 65107623,
= -629701670
}
Strange and confused

Nvm I was dumb, it expects ID instead of Index
Hey all! I'm trying to make an extension for the editor for a project im working on, and while the extensions works fine...ish, it's not creating the asset due to the asset's class being abstract. How can I make the asset with it being abstract? Code is at the pastebin below
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.
hey. you can't create instances of abstract types. no way around it
what you should be doing instead is to change the definition of the method to this: static void CreateBlankCard<T>(T CardTemplate) where T : new(), CardTemplateSO
..and find the proper type to pass as T (e.g.: var x = ScriptableObject.CreateInstance<EnemyCardTemplateSO>(); CreateBlankCard(x);)
I think i'm getting somewhere with it, it's just driving me crazy trying to actually execute the method XD
any questions let me know 😄 idea is that whatever object you pass in the parameter CardTemplate, will be used to assign the generic Type of the method
so if you do this: var x = ScriptableObject.CreateInstance<EnemyCardTemplateSO>(); CreateBlankCard(x);, you're actually invoking CreateBlankCard<EnemyCardTemplateSO>(x)
aannd.. the where T : new(), CardTemplateSO part is there to make sure you can only use non-abstract types that derive from CardTemplateSO to invoke it
so im trying to run the method when the gui button is pressed, but I can't figure out what I need to put for it. All i've got is
CreateBlankCard(CardTemplate)
}```
you check if cardTemplate is not null and then invoke the method with a completely different variable CardTemplate? 😛
Just this would suffice:
if (GUILayout.Button("Create Blank Card"))
{
CreateBlankCard(ScriptableObject.CreateInstance<EnemyCardTemplateSO>());
}
in place of EnemyCardTemplateSO you just have to specify a type that is not abstract and inherits from CardTemplateSO
like
public class DummyCardTemplateSO : CardTemplateSO { }
Hi, i'm doing a custom editor window for my Sprite Animator, how do i create a preview like this ?
so i can put in here >
Question, given a path, how can I know it's from an scene and (if so) how can I read the scene to iterate its content?
A simple AssetDatabase.LoadAllAssetsAtPath(path) fails
What do you mean "know it's from a scene"?
Is that path an scene?
Check the file path for a .scene extension?
Or better yet AssetDatabase.GetMainAssetTypeAtPath(someAssetPath)
Ok
But then, how can I get the root gameobjects of the scene and other assets stored in that scene (i.e: scriptable objects)?
What are you trying to do?
It's a bit complicated, but I'm opening all prefabs and all scenes, then iterating over all components and scriptable objects, and the through reflection, traversing all the possible paths.
Basically, I want to reach all the objects which are reachable...
Then, for each one of this objects, I check if they implement a custom interface of mine (and/or if the field which contained them has a custom attribute) and do some custom logic with that.
I assume this is editor only. Maybe using Unity Search would be a good option with a custom indexer.
It is multi-threaded
@sleek island Stumbled across your post from April of last year here while searching how to do exactly what you were trying:
https://forum.unity.com/threads/draw-a-curve-graph-in-the-inspector.1168892/#post-8090540
It sounds like you succeeded at implementing, so I'm trying to give it a go. The pieces are mostly there but just a bit incomplete. It doesn't help that I've always relied on Odin to make custom inspectors... this isn't my forte.
I don't have any console errors and it appears that the custom drawer element is there, at least according to the UI Toolkit Debugger, but I don't see it. Anyone have any ideas what I'm missing? I assume there's nothing wrong with the CurveDrawerElement.cs or ParametricCurve.cs as I copied those exactly... I built this editor script CurveEditor.cs and perhaps I'm missing something to make this display 😵
I would suggest maybe try removing the whole OnInspectorGUI block from your CurveEditor.cs, as this is only for the legacy UI system
why does this text box get weirdly cut off?
Appreciate the response! On your suggestoin, I've given that a try and migrated the CurveEvaluator lambda into the CreateInspectorGUI, but no dice 😦
I was monkeying around in the UI Builder and I can see what it's supposed to look like in there:
Back when I did this, I'm not sure I ever attempted to draw it in a custom inspector. I managed to make it work in UIBuilder but I gotta admit I'm not sure what's missing to make it work in inspector
Ahh, okay. So if I want to follow in your footsteps on this one, I should spend some time learning UIBuilder?
It should be possible to make it work in the inspector I would guess. Maybe a good first step would be to draw a simple box in your custom inspector, and once you have this working, try to switch it up with the CurveDrawerElement
(it's been a long time since I attempted editor UI programming, I unfortunately can't be of much help)
For sure, I appreciate the attempt all the same! ;D
and how can I make a panel using that same logic
This. This is the solution. 🤷♂️ 😂
Because you set it to be 100px wide and 50px tall
Then what do I set it to?
Can the ui toolkit allow me to make ui and turn it into code for the next he ongui function?
@gloomy chasm instead how can I use a uxml file or uss?
if so do you have a tutorial?
like I found this https://www.youtube.com/watch?v=J2KNj3bw0Bw but i can't really understand it
Like building your own UI tools? Here we go step by step with the UI Builder to quickly create an Inspector for real-time Play mode debug data visualization. Then we’ll enhance it using USS Transitions and the Vector API, migrate it to a custom Editor window, and finally port it to the Player/Runtime.
Learn more about the UI Toolkit: https://on...
Ok well I found out how to do it with gpt but how can I make the ui scale with screen size basically that option in a canvas
anyone ever bothered trying to retrieve XML documentation in editor?
like display it in an editor window or smth
Hello guys, I am playing around with GraphView and i am just curious - how to change the icon of the port to yellow square like this? (as default it is circle):
I need some help understanding why custom propertyattribute is behaving like it is
You just use AssetDatabase.LoadAssetAtPath like you would with any other asset
If you open the UIElements debugger and select the port. You will see it has a uss class. You can then use a style sheet to set the border radius and border color.
Thank You a lot! 🙂
Hi people, i have a custom editor window, and upon opening that window i get the reference to a serializedobject, the problem is whenever a recompile happens it loses reference to that object, how to avoid that ?
here's the code
You can't and shouldn't. Instead you pass it the spriteAnimationObject, and in the window you create the serializedobject from it.
Make sure to mark the field in the window as [SerializeField]
sorry, i explained it wrong, when i open the window i create the serialize object from the spriteanimationobject, it works just fine, however whenever a recompile happens it loses reference and the editor window stops working properly
I understand, what I am saying is to keep the reference to the spriteAnimatedObject, and recreate the serializedObject in OnEnable
like this ?
yup
it's giving me an error: ArgumentException: Object at index 0 is null
for some reason the "_spriteAnimationObject" is always null by doing this
nvm, fixed it, thank you very much for all the help

What's the best way to assign a texture to an editor GUI object. Since it's a static editor window, I don't exactly want to have texture references to assign
Hey, so I sort of figured it out. It looks like it is Unity being dumb. I switched out my header foldout with the unity foldout.
The issue seems to be some sort of binding issue. If I add a field that is bound to a bool as a child of the foldout. If the bound bool is true, than the foldout's expanded state will be true. It cannot be false, however it can be expanded without the bound bool being true.
And binding a child to the custom class causes it to have the behavior I was having originally.
Just AssetDatabase.LoadAssetAtPath
Tried that and it kept giving null answers. Maybe I'm not using it correctly.
Share the code?
Texture2D transitionArrowTexture => (Texture2D)AssetDatabase.LoadAssetAtPath("Scripts/State Machines/directional arrow.png", typeof(Texture2D));
You need to start at Assets/Scripts/..
oh yeah it could be looking for packages as well
nope, still null
whoops
hang on
now it works
thanks @gloomy chasm
np 🙂
That is used to get the preview icon that you see in the project browser
ah gotcha
One thing I was trying to figure out is how to make the Inspector display a set of values, based on something selected in an editor window.
Like how in the animator state machine you click on a transition and that data is shown in the editor window
please help
You mean setting it so it takes up the whole window space? Probably are looking to set the style to flexGrow = 1
I dont fully understand what would that as a line of code look like?
Well I don't know what your setup is. If it is code, you do myVisualElement.style.flexGrow = 1; If it is a css file, you do .my-style-sheet { flexGrow: 1; }
Like this?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
No it would be ui.style.flexGrow = 1;
like it doesnt work i'm aiming to get the ui to look the same no madder the window size and nothing getting cut off
Can you show what you do want it to look like?
I dont have an image but I can explain it. In roblox studio for example if ui elements are set to scale and not offset it will look the same if its on a computer or a phone
which is basically what im trying to do. In which my window size is the size of the device connecting to roblox
Is there any access to the Animator/Meccanim EditorWindow API, so I can write custom node-based tools with same GUI controls? Infinite canvas, arrows, etc.
I'd like to create an FSM visualizer as a separate window...
If tool im writing uses its own resources and I locate them by EditorGUIUtility.Load("Assets/MyTool/MyFolder/Myfile"), what happens to it if I export it as a package? Should I manually change path everywhere to "Packages/MyTool/MyFolder/MyFile", or what?
the path will be carried in the package, nothing will be changed...
what you mean? this means that before exporting i have to manually change the path everywhere, right? :/
I haven't actually published yet, but you should have Assets/MyPublisher/MyTool
You could try using a path relative from the location of the script. I think that might work. (untested)
is there a way to show a list that is in the target script in the custom editor, i have a list that is made of a custom class, this custom class contains a gameObject and an int but it only draws this, i cant get it to show me whats inside. I know i am doing it right as i have another list that is just made of ints and that shows find. i read a bit and turns out its doesnt liek the monobehaviour that is maybe in the gameobject type? any solutions
Show code
one sec
You probably have to create a serializedObject around each field and find the children using that and draw them
Don't forget to dispose the serializedObjects
I'm going to walk the dog
Is it any different if you remove the [HideInInspector]?
draws it twice if i take it out but does techincally show the inside but still not a desirable outcome
Ok, but that's the problem then. I don't think there's anything you can do to make it ignore that attribute for your PropertyField call.
So I think your only options are to either draw the list and each child property manually or stop using the base.OnInspectorGUI / base.DrawDefaultInspector and draw all the fields yourself in the order you need them in.
🥹 ok well i will look into all that, might just leave it for now as this is not a necessity, thank you anyway
The container class needs the [Serializable] attribute, in the class declaration.
i think the best path forward it make everything manually, maybe using this https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
Have you tried my suggestion?
ah nevermind (you did)
i have put serializable and serializefield everywhere in the code just in case lol
from the code example I'm seeing, I would remove [SerializeField] inside the Serializable class
do not think that is necessary
yh i know it was just me adding stuff to see if anything made it work i have returned everything to how it was and i am just going to move on for now tbh its no big deal
Whops, I was not aware I was the editor channel when initially replying 😆
Looks like PropertyDrawer is the way to go. The only other thing I could think of trying, is [field: SerializeField]
which works for properties without a customized getter or setter.
yep that already tried too unfortunately
perhaps a workaround - What if the GameObject field is private, and you have a GetGameObject() method that returns it instead?
you could have a string name to reflect which game object it is
unless you need to set the references in the inspector
i need the reference in the inspector but tbf i was thinking of somthing similar as theoretically i dont want the obj to be changed from the inspector because it has to be set from a loaded file
that's 'the' solution yeah 😛 I'd say create a custom/manual drawer for List<T> and .Draw using that (likely a standalone thing)
You could possibly have a separate list of game objects which correspond with index.
you may be interested in Odin Inspector if you haven't heard of it -- makes doing stuff like this a walk in the park
is it an asset or something built in?
$50 asset
Do you think there is any merit to the approach I suggested?
well i cant use assets and i am broke
this one?
every approach is good it depends on the contex
the drawer one is the most "right way of doing it"
well i would rather not have to create extra code each time I wanted to draw a list 😛 so I'd still go with the drawer
but if you don't mind that then sure, it'd work! (would still require drawer code to back it up though)
Thanks! 
check this out tho: https://answers.unity.com/questions/682932/using-generic-list-with-serializedproperty-inspect.html
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
you can iterate through objects of an array's serialized property to get the references
damn, those answers are so good and detailed!
and very long....
yeah 😆
will look into that too lol
and you can use this snippet to render any serializedObject (custom class or not)
SerializedObject so = new SerializedObject(SomeSOAsset);
SerializedProperty sp = so.GetIterator();
sp.Next(true);
// Skip drawing the script reference?
if (!includeScriptField)
sp.NextVisible(false);
EditorGUI.BeginChangeCheck();
while (sp.NextVisible(false))
{
EditorGUILayout.PropertyField(sp);
}
so.ApplyModifiedProperties();
EditorGUILayout.Space();
if (EditorGUI.EndChangeCheck())
{
Initialize();
AssetDatabase.SaveAssets();
}
actually that may only apply to UnityEngine.Object.. let me check
You wouldn't happen to have a full switch for correlating property types with the serializedProperty output type? 😅
It's not needed from 2022, but I'm on 2021, and not motivated to make one.
I recall seeing someone sending that a while ago in #archived-code-advanced lol.. they even used object casts to make it easier, sec
For anyone reading, 2022 introduces serializedProperty.boxedValue
ah it was here: #↕️┃editor-extensions message
seems it's not full code tho, sry 😄 you can ask them 😛
trying to remember what I did with Lists rn..
oh it was just a
for (int i = 0; i < sp.arraySize; i++) {
EditorGUILayout.PropertyField(sp.GetArrayElementAtIndex(i));
}
I saw he's working on a bigger solution.
But I suspect he has heard about boxedValue and maybe stopped
still seems it could have some use
maybe they're the one that added it to 2022 
@earnest talon did you end up completing your CProperty.Value thingy? 😛
@fervent kelp this could be enough for what you're doing -- as soon as you have the list's SerializedProperty
yep i actually just saw that in a forum answer looking into that right now
Oh yeah
Lemme get it in a mo
I've been working on a C# -> USS translator
set is basically just a bunch of castings that i can't compress to fit on an image
forgot to fix enum mb
I'll fix it later because i'm already focused on the USS conversion thing
for the value setting, there's actually three ways to set the value
property.Value
property.SetValueUnsafe(object value)
property.SetValue(type value)
What is it that you were trying to do that wasn't working?
btw, layermask corresponds to the intValue
thanks, the documentation can be hazy
iirc character is string
I'm guessing layermask is set via (int)value
generic means it is a custom class/struct, so basically means it is just a parent that contains other properties
how I convert that would be itself a rather unique task.
I think gradient references the same thing as animation curve. But that is just a guess. I never use it 😛
You don't 😛
Or you do reflection
Hi! i'm not good with editor scripting so i''l ask for help.
I have 2 cameras and i want them to have always the same ortographic Size. So When i change the values in the inspector of one of theme, in edit mode, the value of the other also change.
just generic would be pretty much a pain
fair enough
I don't know specifically if I'll implement it
as those are hefty use cases and I'll be including proper documentation for cases like that
Probably would be easiest to have say, one camera maybe the main, that you set the values on, and then when you enter play mode you have a script that copies the needed values to the other camera.
it's neat to see bewildered-core though
What I might do with generic is instead of directly getting it
you can just do custom iteration
Yeah, it is kind of a pain. It is basically the newer boxedValue property. Just more of a pain 😛
yea i thought on that as an ez solution, but i'm trying to do something more sophisticated. So when I tweak the values in EDIT Mode, the other change as well.
what you might want to do is
create two sliders in an editor window
or int values
or whatever you choose
and have those sync both *cameras' edits at once
so instead of changing one and applying the changes to the other
you change both at once
because otherwise why?
you'd have to update both SerializedObjects and apply the changes to both of them
but it'd be the same result
It isn't worth tbh. But if you want. You can use this https://docs.unity3d.com/ScriptReference/ObjectChangeEvents.html to get an event whenever an object changes And https://docs.unity3d.com/ScriptReference/ObjectChangeKind.ChangeGameObjectOrComponentProperties.html to get the type. Then check to see if it was a camera that changed, and if it was you copy the values over.
But again, it is like 3 lines of code to do it at runtime.
you can do it at runtime and edit time
i'd personally say try do it anyway because even if it isn't worth it, the experience and experimentation is helpful
yea yea i know that in runtime is really ez but i want to see visual changes in edit also
what's the fun in life if you can't break a game engine or two
thats the point of this jajaja
Sure! Just wasn't sure what was important to you 🙂
Hello, I have a problem since I can not access the play mode by an error, someone could help me thanks. I have come to wait more than 30 minutes and it has not worked for me, any solution?
that's not.... an editor extension?
its all good bro the answer is using drawers
one thing I don't think I'll do again, mech
Where can I ask for help?
write an interpreter for C# <-> USS
This channel is for creating custom editor stuff like windows. You want #💻┃unity-talk probably.
What... what do you mean?
I feel like you have done something very cursed, but will hold judgement..
the reason being is
ok thanks
I prefer to work in C-based languages
I can use USS and UXML, I just don't like to.
so my result is, what if I just make it possible to read, write and modify USS stylesheets in C#?
because it's a very simple language
you can compile .uss files easily
you just need a few basic pieces of information
- property/selector name
- property/selector value(s)
-property/selector type
etc, etc
I was going to do this for UIElements as a whole anyway
for USS and UXML
but i wanted to do graphview
then gridbackground requires USS* (oh lord help me)
so, when I noticed the syntax again
it was just a case of "why not write an interpreter"
can't post gifs here
Gifs are not allowed, because it could be a meme or reaction gif. Sad. (sometimes gifs are allowed though.. dyno bot be weird)
fair enough
anyhow I am very well aware that I could just use (or suggest) UI Toolkit
and UI Builder
So you write a stylesheet in C# and it creates a uss style sheet from it?
yeah
and you can read a style sheet into that format too
decompiling all the rules, etc.
That is really cool! I hate it xD
I knowwww right!?
I really hate USS so much
but that's why I'm building it in now
I know interpreters are hard but at least USS is a sandboxed/simple CSS
and I want to be able to have an interpreter coded for 2019.1 and onwards
It seems like a cool/fun project to do! But also I really hate it, it takes away so much good of uss.
plus it'll look good on a portfolio that I did that
I mean it does technically
but also
I plan to include every base USS Property/Style Rule used
and all this
is so I don't have to gat dang use USS to supply a graph-view based editor window extension
and then it became part of Cappuccino's core package
because yes
I'm also fully cognizant and aware that I would not recommend this to people who can better use USS (this is pretty much a solution to an opinion-caused problem)
this is just for people who want strict C# usage.
mmmm trying but not sure how to use it
I can't wait to get even the basics up and running and see it work fully
I am never going back to IMGUI. You don't know the horrors (or maybe you do idk) of making a custom property drawer and changing fieldRect.width = 21, recompiling, see it isn't right, changing it
fieldRect.width = 23, recompiling, see it isn't right, changing it fieldRect.width = 22, recompiling, see it is good, then move on to the next field.
oh I'm aware of IMGUI that's why I'm creating Cappuccino
I love IMGUI a lot but (@ it) my sweet summer child you cause me and my fellow peers so much pain
and the only reason I love it is just I can write editors strictly in C# without issue.
You first create a static class that uses the InitalizeOnLoad attribute, in the constructor you subscribe to that event.
if I could use USS in C# directly, creating and modifying style sheets - I'd love it more
maybe even go further with that than IMGUI
but sadly I can't
You say that, but if it was true you wouldn't be massacring my sweet uss that lets you style without recompiling 😛
oh you-
that won't be possible?
I'm not doing it to style w/o recompiling
if you can do that as a byproduct, neat
main goal is just to make it so I can create style sheets when they're missing for something.
and you're not alone in that feeling either
but its not necessary that this class inherit from Editor class no?
dad's a web developer and he saw what I was doing to a CSS-based langauge
and even he weeped
Correct!
well I know you can do that but I'm not looking to create it like that myself
I want to be able to assemble a style sheet directly in C#
I know, and that is cursed 😛
I think that's just the beauty of this discord sometimes
we all have our own ways and we all get to laugh at the absurdity of some ways
Indeed!
also good luck with your projects!
I'm gonna go back to butchering the native tounge of web developers with C.
I feel like im close but no getting at all. Now when i change ANY value of ANY component in inspector, it print the mainCamera ortographicSize, but not the playerCamera.
Yep, that is how it works. You then do
for (int i = 0; i < stream.length; i++)
{
if (stream.GetEventType(i) == ObjectChangeKind.ChangeGameObjectOrComponentProperties)
{
stream.GetChangeGameObjectOrComponentPropertiesEvent(i, out ChangeGameObjectOrComponentPropertiesEventArgs changeArgs);
Object obj = EditorUtility.InstanceIDToObject(changeArgs.instanceId);
if (obj is Camera camera)
{
// you can then see what camera it was and copy the value from one to another.
}
}
}
The Editor world is a scary world🫠
Haha yeah. That is why I said it was easier in runtime only xD
to be honest it could be quicker to do it another way
yeah i wanted to do something cooler that those 3 lines in Start method, but im giving up
well it's not about cooler
it's about probably doing it
in a more extensible, universally appliccable method.
I mean, you are almost there at this point... might as well finish 😉
might as well go whole hog and not do that
instead doing something more reasonable like an actual editor window
Also, 'cooler' is 100% a valid reason to do editor scripting xD
which allows you to view the selection of and modify multiple cameras at once
instead of just two.
No, that is ~worse~ bad UX
if he's only ever doing it for two cameras for one project, yes
but it's more universally applicable
and you'd be able to modify more than two cameras
I don't see how that's bad UX personally - it allows you to do more than two fixed, single objects in one project's scene file
as a notice, it wouldn't be all in one panel
you'd have tabs, of sorts, within the panel
If you want a simpler way, but less performant, you can use EditorApplication.update. It runs just like the MonoBehaviour Update method does. You could use the InitalizeOnLoad thing again, and get the two cameras like are doing and just check them in there to see if they are different 🙂
I'm guessing in this case bad/worse UX is just dependent on the house rules of the company/companies you've worked for
It is poor UX for 2 reasons. Firstly, because you can still change the settings on one camera 'manually' and not have them propagate to the other camera which can lead to 'bugs'. And secondly, you would have to then remember both to open this window open, and which 'random' values should only be changed in this window.
and what rules/guidelines you use as a basis for your UX design.
you'd not change them on one camera?
???
you'd change both cameras simultaneously
like - you can do that?
you'd be selecting all the cameras and you'd be able to even add restrictions as you build the editor window
such as - only two or more cameras may be modified at a time
I mean, if you are using your window approach, nothing stops you from just selecting the camera in the inspector and changing it there.
Which means the second camera would not be updated
yes but that would be different to what I'd be doing
which would be actively modifying two cameras' values at once
using two (or more) fields and synchronising the values of both cameras
cause you don't have to rely on displaying one camera's values over the other's
you can just mass-modify
I know that
What I am saying is you might forget or someone new might join the project. And want to update the settings on the camera, so they just go select the camera directly in the hierarchy and change it's values in the inspector and never even touch the window.
i'm trying to finish this. In any case thanks both of you, im learning a lot and having a good time. Learing Editor scripting is something its in my plan ahahha
in the case of forgetting, that can be accounted for with additional measures itself and if a new person joins the project, I would be asking more questions as to why they were let in on the project without any sort of walk through of any of the tools
Sure, I love editor tooling, so feel free to ask away if you have more questions or issues!
any project management structure where you can just let new people join without any tool education (which is what happened at uni somewhat but between game engines) is questionable at best
Nah, it is pretty common xD
weird
you'd think someone in the development cycle would go "oh by the way we have a few changes done to our version* of x game engine. here's what we've done"
It depends on the size of the group and how much management experience they have
okay okay okay im alomst ther, but the problem is, I dont know how to get reference of the child camera object in editor
uhhh
this is what it prints
mainCamera?
so
what's going on with GetComponentInChildren<Camera>(); returning the main camera
that one is weird
Ahh, yeah that is a pain. For wahtever reason InChildren also checks the GameObject it is called from. mainCamera.transform.GetChild(0).GetComponent<Camera>() to be safe you probably want to loop through the children instead of getting the first one
or mainCamera.transform.Find(childName) also works
though whether or not that would work in your case is hazy at best too
Please don't ever do that. Someone can rename a GO so easily.
well yeah, you generally wouldn't.
mmmm what!? this doesnt happens when in play mode no?
It does 🙃
but additionally, getting children themselves are also a pain as someone can also change the order of a game object accidentally
Yeah that is why I said to loop instead.
the main questions I have is how many clueless people are being let in on projects industry-wide
well either way it is what it is
AAAAAAAAA!
i got it hahahaha
it works poerfect, when i change the ortograpficSize of any of them, the other change as well
YAY! Congratulations! 😄
this code u send me, is something u use to use often, or it has been very specific for that?
Nah, I use it rarely. So far I have used it once to move objects between scenes in a world streaming system. And once to create ScriptableObject variants.
Maybe this is my starting point for learning more in depth Editor scripting
and just a final question, i dont want to bother any more, its necessary that the class who uses the [InitializeOnLoad] attribute is an static class?
No, I don't think it does. All it does is call the static constructor, and if memory serves, any class can have a static constructor. But don't quote me on that, I am blanking on if that is the case or not really
nice!
well, so after this break, i can continue with the gameplay hahaha, if i finally end this game i will mention u on credits😂
yeah it seems to not matter on that
even I was curious about that
I think the only dependency is static constructors?
and static voids maybe
The reason for the static method is because it is used in the static constructor. So in order for it to be called without creating an instance of the class, it needs to be static.
Haha, best of luck!
the more you know
never found an instance where I've had to static a constructor before so hey
learn something new every day
That is true for all static methods.
Not just static constructors.
By reading this i wonder if the ortographicSize change in build gameplay, it will apply the changes on both, or this is something just for the engine?
The thing you setup is editor only. So it will not change in build
so in build i will need that 3 lines code u said at the beginning of this journey
Yup, if you want to change them at runtime. But if they will not be changing, then there is no need since the values set in the editor will stay.
at this moment im not sure if they will change at runtime, but its good to have it in mind already
@gloomy chasm I will say that I didn't expect there to be so many USS Property types.
LOL
oh well
just hard-coding them all in anyway
(there's a reason for this, dw)
enum -1 : custom (not marked as variable, for any unsupported types that get added before support is added)
enum 0: variable, for any variables
i have to move this enumerator to a new script after though lol
100% though
I can see the appreciation behind USS and why it's useful
with all this
it's neat to see how I can translate it, but god damn this translator is cursed 💀
hurdles like this just make me more motivated to prove they won't get in the way of sheer determination
well it's partly there now
@gloomy chasm I don't know specifically what the value types can be so I've got this for now.
it is cursed i know
Why not use StyleValue
as a naming convention?
only StyleValues exist which might be similar?
but no StyleValue
only reason I didn't so far is the absence of the ability to use keywords in the StyleValues type
such as auto, visible, hidden, etc.
Oh, nvm, I was thinking of StyleColor and StyleLength etc.
There is IStyleValue<>
it makes assumptions that you know what you're doing.
not for 2021.3
which is the version of unity I'm using primarily as a base for forward-porting and back-porting
I would love to go to 2023 if possible but it's not a personal choice sadly
it's a university course restriction due to the fact we don't get software installed unless:
A) a PC fails spectacularly and needs a reinstall of windows
B) it's summer and all PCs need new updated versions of software