#↕️┃editor-extensions
1 messages · Page 66 of 1
I dont use them a lot, just for typesafety for my writer in the UI. im just storing them internally as integers
huh, how do I even represent > and < for a selector with UIE
Make a sprite? Cuz I saw Unity tends to make Chevrons sprites for their UI
that would work
Hello
How to dynamically load items into this list?
i have this scripteble object
and wanna add this prefabs array to context menu
Hello
@full vault Ur 1st image is kinda hard to see
@full vault use Resource.Load to load ur prefab?
how i can dynamic add to list there?
Well u just load the items and add them in lol, I would suggest use a button to do it, cuz u don't want to run that function on update
@full vault protip when screenshoting, Windows key + shift + S will let you maintain open context menus
As far as the menu items
There are methods you can call to add items to the context menu without using Attributes, which you would need to do in this case
Courtesy of Vertx
omg
https://gist.github.com/vertxxyz/22a7e5fb6ea6ec907afdfd6993deeb5c
@severe python ty!
no problemo
addMenuItem.Invoke(null, new object[]
{
$"GameObject/Room/Components/c {i}",
string.Empty,
false,
i,
(Action) (() => Debug.Log(j)),
(Func<bool>) (() => true)
});
what is parameters?
$"GameObject/Room/Components/c {i}", //path+name
string.Empty, //?
false, //?
-i, //order
(Action) (() => Debug.Log(j)), //action on press
(Func<bool>) (() => true) //can execute
I dont know myself, you'd have to look at the unity reference source
and how remove it from list?
Unfortuantely, that doesn't appear to exist
thats how this answer even came up
I was looking for a way to dynamically remove menu items
@severe python solve it
MethodInfo rm = typeof(Menu).GetMethod("RemoveMenuItem", BindingFlags.Static | BindingFlags.NonPublic);
rm.Invoke(null, new object[]
{
"menupath+name"
});
all what we can using menu
It was nice to work together)))
yes
super
my question keeps getting removed from here
i type it out and it auto deletes
I'm trying to Update an array field in the inspector
[SerializeField] public CombatState[] combatStates; #if UNITY_EDITOR protected void OnGUI() { var states = GetComponents<CombatState>(); combatStates = states; } #endif
When I add or remove states to the inspector, it doesn't update the array properly
i've tried using OnValidate() also but that doesn't work either.
wdym by dinamically?
for assets, you use resource load
Scriptable Objects arent really modificable on runtime (any changes you make to them in runtime only survive while the game is running), so if you plan to use them for saving data, you will need to serialize them as json and load them back
Do you know what channel you're in @magic lintel ?
yes?
AssetDatabase.LoadAssetAtPath and you should use SerializedObjects to modify them to get proper undo and serialization support
how can i update the array in the component each time a component is added to the inspector?
@waxen sandal Passive aggressiveness isn't a good way to tell somebody they gave a wrong answer btw Specially about one with 0 context
Could he have responded better to your statements, sure, but this is Editor Extensions, the context that is there is that this is for an edit time change
there is definitely more than 0 context here
@snow bone Do you need something that runs every time the inspector is changed or only the first time?
Because if it's only the first time it sounds like you can do it in Awake when you enter playmode?
You can use the OnValidate callback to change it every time something is changed in the component through the inspector
Or you can write a custom editor that checks whether a specific value has changed
In both those ways you can also just check if your variable is already set; if not you can generate your value and otherwise do nothing
Can I somehow track changes within a specific folder? delete / add as well as update inside an object?
@severe python yeah but its an editor extension, you can easily load assets or SO "dynamically" by having them exposed as serialized variables
There are asset import callbacks where you can check if they're in a specific directory
@full vault If you want to track changes to the FileSystem you can use a FileSystemWatcher
FileSystemWatcher is quite performance intensive to run though iirc
True, last time I heard it was more a thing you can use if you have nothing else to use
I want when changing inside the folder my context menu is updated
for a specific asset type?
what I've done for something that sounds similar is that my type keeps track of itself in a static field
so when a new instance is created I add it to that static field
I forget what I did exactly tbh
I think you probably want this if its available to you
okay. I have a Components menu. there will be a list inside. How to update this list from time to time?
you could always register a callback on EditorApplication.update and do your check and updates there
@waxen sandal thanks
anyone know how to use EditorGUI.BeginChangeCheck
i'm having difficulty finding any documentation or examples
the unity doc for it is completely lacking
Is there a method or something that is triggered when an object in the inspector is changed perhaps?
@snow bone try OnValidate()
I solved that already, but thanks.
the answer was to add a [ExecuteOnEditMode] attribute to the class and just use OnGUI, as neither is called when a component is deleted
I'm trying to make a popup that contains a list of Components in an array, that has been assigned in the inspector
{
[SerializeField] private CombatStyle[] combatStyles;
}
public class CombatStyleManagerEditor : Editor
{
private SerializedProperty combatStyles;
int choiceIndex = 0;
protected void OnEnable()
{
combatStyles = serializedObject.FindProperty("combatStyles");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
EditorGUILayout.Popup(choiceIndex, combatStyles);
serializedObject.ApplyModifiedProperties();
}
}```
this doesn't work, as the pupup method requires a string, but is something like what I want
Maybe get the hash, if it changes, update the strings
I found an answer.
Good
Is there a way I can create custom attributes that generates code?
you can code your own attributes to do stuff, so yes, but I don't know how
and making your own code and putting it in a file is just a matter of file serialization
however, to make a code file to be compiled and run during runtime execution is a different kettle of fish entirely, which I would strongly advise you leave well alone from
have you thought about using code snippets, they are much easier to do
use a key combination and VS will paste the contents of the code snippet into your code.
I want to make an utility package
do a google for "unity create my own attribute" you'll get some answers from that
native c# has file IO functions for serializing text to a file
Should my conditional nodes be different nodes in a node editor? I have 3 nodes that each have different parameters, but my writer asked if I could put them in a single node. They re all conditional nodes, but one needs a function reference, another needs a number and another needs a reference to an object. I am thinking since they hold different data they should be different nodes but I could also make them the same "conditional node" with a type dropdown.
You can serialize generics now using SerializeReference so I don't think you need one giant conditional class
Your nodes in your editor should really only be a visualization of your model layer
But I think the better question is, how are you going to get a method reference in your data?
Since you'd probably need an instance to check right?
ow yeah shit
I was gonna attach a script to my graphrunner and reflect/invoke the functions tbh
make a little dropdown to select the invokable functions, which I would store the names of in a list. or is that a horrible idea @waxen sandal
That's a fine idea
But what if you want to do things relating to one of the characters in the dialogue
Or based on a world event
Will you make method for all of those?
well no, I reflect a method with a parameter field as well. no?
SO
Then how are you going to serialize a reference to an object in the scene?
the SO would only need to interact with the player, its controller (npc) or the world. which are available at all times when the npc exists
cuz those references will also be passed into the npc at creation
Right but an object in your project view can't have a reference to anything in your scene
Sure but you're going to be instantiating your prefab
So your reference will be getting data from an instance with preset data
fuck?
Yes
I could make a base npc class and have overridable functions for it. Have it hold a reference to the SO. but that requires me to write a class for every npc 🤔
I'd just make a bunch of preset targets
Like current speaking character
Then resolve those in your dialogue runner
are you thinking a dialogue runner is on the npc or somt global that controls printing to the screen as well?
and is told who is speaking
cuz I would think having it on the npc and sending data to a printer to print it to the screen is the best idea
Some thing that has a reference to both your NPCs and your dialogue then something else that handles the UI
why do you separate the dialogue runner from the npc?
Because it's irrelevant for the dialogue runner to have a specific NPC
It just cares about X characters in a dialogue
fair
another one, do I make all my nodes and make the system work before getting into properly storing data or should I be doing that on a node by node basis
as in serializing it
Well if you figure out that your idea for serializing doesn't work then your system is pretty useless isn't it 😉
I mean yeah, but you gotta just find a way to save it. but I wonder if its better to do it once you have everything working and know exaclty which data needs to be saved for each node
but each node needs to be serialized separately anyway so its kinda idk
You got to get your basic idea of your data layer working
Then you can build on top of that
fairs
should work on a generic node serializer, then expand and populate with more nodes
What I do is I take the saved Graph asset put into a monobehaviour and build a runtime tree .
With this way Runtime Tree is a transient data that lives in scene
But your "source" graph is still an asset so you can't save reference to that scene right?
how can I save PlayerSettings with code so everything will be ready for version controll after running script?
anybody happen to know how do i manually draw this section of a monobehaviour with editor API ?
does anyone use any specific tools to document their assets code?
I need to write some documentation for my team members. Do I just write that inside an editorwindow?
@steady crest What kind of documentation? Do you want to explain what something does or also how it does it?
mostly how it should be used
If they only need to know what, then a ///<summary> documentation comment makes the most sense and will show as hints in most IDEs
that would require him to use an IDE, he is not a programmer 🙂
There's the [Tooltip] attribute
We use Confluence
I made a stencil mask for walls to clip out so the player can be seen throuhg em but im 100% sure it wont work when he tries it cuz you need to give the walls you want to have do taht a specific material so it can clip it
@waxen sandal looking good and free up to 10 users 🙂
Lots of small bugs
Like sometimes it seems to delete the first letter of your page
Or the header styles that you can set no longer work correctly
Things like that
I don't know
That's such a mess to maintain imo
there should be some npm package to get for that tho
otherwise its like 2 components, a side navbar and a main window for the data
should take like an hour or 2 to write myself xD
Heya everyone. Not sure if this is the right channel for this. but got a question: Im trying to setup MeshSync between Maya and Unity : https://github.com/unity3d-jp/MeshSync
But the problem is that I cant seem to find the DCC plugin download for maya...
the documentation says they should be in the releases but there are no plugins there ... ??????
The build process for these^ looks out of my league.. Im going crazy because I swear they had the DCC plugin builds up there before..
Just fyi, this isn't the right channel really, this channel is for help with developing these kinds of extensions (among others) not utilizing them
hey guys how do i go about doing this. I have an editor scrip that has a button that runs a function on my grid creation script. In that function it generates an array. How do i make it so that array keeps the data i generate when i enter play mode
perhaps #💻┃unity-talk or #497872469911404564
yo
in your editor class you're casting your target to your class and editing the list like normal right? that's not the way to do it 😆
you need to work with the serialized properties
so i saw a guide where you can call a function from your class in the editor
var prop = serializedObject.FindProperty("FieldNameHere");```
then you can use some awkward methods to alter the array
yes you can call, but those won't get saved
if you want it to be saved you need to edit the serialized prop
basically i just want to be able to create my array and generate my tilemap from the editor and hit play and it still be there
or you can ask whoever is pressing the button to change something else in the editor so that it wakes up to the changes 😆
so in the thing i was watching they made a new class with the [CustomEditor(typeof(myscriptName))]
a bunch of stuff you prob understand but essentially i can make a button and call a function on my actual class script
in that function the button calls it sets up an array
at what part of this process can i edit the property
like what am i typing to access it
You can do Undo.RecordObject before you invoke your method
Check the docs to be sure
I had the same issue recently where I altered my class's list from the editor but it wasn't getting saved, because I wasn't modifying the serialized one, I was modifying the temporary editor one
if you want to simulate editing the editor, then you need to go via serialized property stuff
so im looking at this example for the undo thing and it just goes over my head
so i have the target script
see my code snippet above, declare that in your editor method then you can add/remove/clear the array from the editor with that
don't mess with the original class' objects from editor
ok im going to have a fiddle see if i can get this working
yeah it just creates an array
If so, then just call Undo.RecordObject(target, "description");
Right before your method
whats the description for
what happens if the method changes another object
It won't be recorded
And you'll have to call Undo.RecordObject for that object as well
i see well it doesnt change anything else but i just wanted to know for future incase it blew something up lol
oh so that's what I needed back then too 😦 (Undo.RecordObject)
hm, do I need to call it before every list.add or field assignment? xD
it worked with a single list.Clear() but now it doesn't when I added the rest of the stuff
and by not working I mean hitting play loses all changes
In an AssetPostProcessor, when I update (overwrite) a model, In PostProcessModel, can I get the instances of the gameobjects it will update somehow?
@oblique hamlet not sure what "model" is in this context, is that a 3d model or smt else?
I want my update of my monobehaviour to also run in the editor (probably periodically) to allow a shader to update in the editor. Should I just add an ExecuteInEditor attribute to my Update function or is that a bad idea?
I don't like it but it's probably your best option there
this exists but idk https://docs.unity3d.com/ScriptReference/EditorApplication-update.html
Yeah no
how so?
Because you want it to run per instance
ah ye, logically
How can I add my own context menu to add UI Components? I have extended existing UI classes. Would like to be able to right click and add new UI Controls (Perhaps under its own menu) but still requiring a canvas.
[MenuItem("GameObject/UI/...")]
you can see the implementations for the UI components in the MenuOptions class in its package
That only adds it to the top menu, not to the right click.
[RequireComponent(typeof(CanvasRenderer))]
[AddComponentMenu("UI/Raw Image", 12)]
public class Something : RawImage
thanks
Uh, it adds it to both menus iirc
Sorry, tagged the wrong person before, @whole steppe just to reiterate, LoadAllAssetsAtPath requires a path to an asset, and this is the right channel to ask editor scripting questions
oh, forgot this channel was a thing, srry...but yeah; in my code i have that (and a valid folder path) but it returns nothing
If you wanted to get all the assets under a folder you can use Selection.GetFiltered with SelectionMode.DeepAssets
that works, thanks!
is there a way to do some actions right before unity sets things up to play the current scene ?
nah, I want to exec code once I press play but before everything else starts; want to recompile my asset bundles on each play & each build to always be up to date
I tried doing this with an assetpostprocessor but unity will straight-up crash from a segfault if it builds asset bundles while starting up
There's a playmode cahnged event
Anyone have some open-source code or way so that in public Vector3 teleportPosition I can have a way to put the world position in the editor via a Gizmo in Scene view?
nvm I guess it might be better to specify a gameObject
than a Vector3 teleportposition
@steady crest 3d model
Uh what? @oblique hamlet
im using classic UI for a mobile app , got a vertical scroll view , within it multiple horizontal scroll views , when i try and pull it down to scroll vertically it scroll horizontally
seems like the top most scroll view locks them up
is there a way to make both scroll views under the touch point to get activated ?
nvm solved it
@plucky inlet "post"
roflmao and two hours i suppose
ur point ?
oh lol, my brain lagged for a moment there 😩
they say exercise keeps the mind healthy, but i guess power lifting temporary reverses this effect
Are there any existing frameworks for doing codegen in Unity? I'm wondering if common problems have already been solved by an open-source solution.
I'm hoping to automate some repetitive coding tasks by using a code generator to spit out logic based on [Attribute]s I put on my classes. For example, initializing Component references, dealing with the repeated if(collider.GetComponent<T>()) logic in OnTrigger, stuff like that.
I have a generator triggered by [DidReloadScripts] that uses reflection and is working well enough.
One problem is that if my generated code has any errors, it brings everything to a halt. Compilation breaks, so reflection breaks, so codegen isn't able to fix the problem that it made.
i would probably go for out of process new roslyn codegen to decouple this from unity build completely
but practically dont have good recommendation
Ok thanks, I'll do some research.
I hope roslyn has a way to codegen even when compilation is technically failing, so you can be coding with temporary errors errors and it'll still do its best.
Errors tend to fuck with your IDE so I wouldn't suggest it
If I have asset references stored in the project settings, they dont get compiled into my build right? or can I pull them from there onto runtime scripts?
@steady crest I was asking a question, and you answered but I wasn't online- "In an AssetPostProcessor, when I update (overwrite) a 3d model, In PostProcessModel, can I get the instances of the gameobjects it will update somehow?"
Not that I know of @oblique hamlet
I doubt it's possible without manually searching every scene/prefab
@steady crest Like a settings provider?
Thanks Navi
@waxen sandal yes its a settings provider
It depends how you save it, if it's in a SO then that'll get included iirc
https://hatebin.com/hjkpvnrgbw @waxen sandal
Sounds like they'll get included
Actually 🤔
If your SO is defined in a editor namespace and uses editor APIs
What would happen then
I guess they'd be stripped if they aren't referred
And otherwise you'll get an error
Since the type can't be found
it wont build if that happens will it?
i mean, its not hard to make a scene reference setup from that SO but it would be nice if i didnt have to
If you refer in your code by the type directly then it definitely won't build
Not sure what happens if the SO can't find the type
I mean I can make a scene object that has an editor script that gathers the data from project settings for the stuff I need
not all of it is needed either way, I was just wondering if I could directly reference it
I'm new to creating custom menu items. I want to add a new item to the context-menu "Create / C# Script from template" that will create a C# script, but use a custom template file I have.
Is there a proper way for me to tell if the right-click menu was brought up in a particular folder, or if it was clicked in the global "Assets" menu?
EDIT: nvm, found a code example that answers my question: https://bitbucket.org/liortal/code-templates/src/master/Assets/CodeTemplates/Editor/CodeTemplates.cs
can i use undo with non unity objects?
Maybe you could do this if you created a unity object that proxied property access to an underlying non-unity object? So Unity would serialize the unity object into the undo stack, but secretly all those properties were actually write/reading to/from your non-unity object
I want to run some background code in the unity editor, compiled into its own assembly, and I don't want it to reload unless that assembly changes.
Is this possible?
Right now it's reloading anytime any code changes, even if the changes are not in that assembly.
I've tried DidReloadScripts and InitializeOnLoad; I'm not sure if one, or the other, or both is best.
Does anyone know how to create sub assets inside a newly created ScriptableObject?
// inside ScriptableObject script
void Awake() {
var test = ScriptableObject.CreateInstance<TestDO>();
AssetDatabase.AddObjectToAsset(test, this);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(test));
AssetDatabase.SaveAssets();
}
I get an error
AddAssetToSameFile failed because the other asset is not persistent
I was able to do it by delaying the AddObjectToAsset until after the asset was named in the project...
public static async UniTask<T> AddSubAsset<T>(string subAssetName, Object mainAsset) where T : ScriptableObject {
// wait until asset is created in project
await UniTask.WaitWhile(() => String.IsNullOrEmpty(AssetDatabase.GetAssetPath(mainAsset)));
// create new subasset
var subAsset = ScriptableObject.CreateInstance<T>();
subAsset.name = subAssetName;
// add subasset to parent.
AssetDatabase.AddObjectToAsset(subAsset, mainAsset);
// refresh project.
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
return subAsset;
}
kinda worked.... renaming the file is now wacked. Renaming main asset moves it itself as a subasset and a subasset becomes the main asset 🤔
anyone know how to refresh the project folder after doing a AssetDatabase.AddObjectToAsset() ?
Hello - does anyone know if there's a way (prop drawer?) to show UTF16 in the inspector/editor windows.
e.g.
this: 🍎 looks like this in any text box
(i.e. nothing, even though the unicode for apple is there)
this isn't a question or anything but i just wanted to say i'm super proud of the property drawer i just made
it maps a number to an array stored in a different object
and it displays the value of the array at that numbered index
super late but this is what it looks like
changing the number on the right changes the icon next to it, to the icon of the object stored in the array index
Hi
Does anyone know why Selection.GetFiltered(typeof(GameObject), SelectionMode.DeepAssets).Cast<GameObject>(); doesn't give any results when selecting a Folder with GameObject assets? Altho it does work the same code if I replace GameObject with Texture in a Texture Folder.
Is there a way to remove this button from propertyfields? I've tried a custom drawer but it seems it's baked into PropertyFields themselves.
How do you make a function to run on edit mode without declaring the whole class as ExecuteInEditMode ???
would it be feasible to extend the Terrain/TerrainLayer classes to enable material support in TerrainLayer instead of being forced to use a texture?
i know unreal lets you modify the engine but i'm not a fan of epic
something similar to that though
how can I get a list of all assets in a project? I tried using AssetDatabase.GetAllAssetPaths, but it seems to returns assets from other packages as well (e.g. com.unity.textmeshpro)
Should ask in #💻┃code-beginner not here
ok sorry
This channel is for extending the editor not writing game code
ok ok
Does anyone know how to access the Scene Window toolbar to lets say add your own buttons? I assume it's through reflection, but I've not had a deep dive into the Scene Window source yet
Unless I'm that blind and it's right in front of me without knowing
This is what I mean by the way (just in case anyone didn't get what I meant)
Perhaps UIElements give you easy access
But I'm not sure if the scene view is rewritten yet
there's only two events for SceneView currently, and it's just beforeGUI and afterGUI, but neither draw to that toolbar
I assume I'm gonna have to use reflection, which in that case I'll ignore it and make some form of toggle GUI in the scene view directly
Right
But if the SceneView is UIElements you can just find the window, get the root element, then find the toolbar and add or remove w/e you want
You can draw the content of your window with either IMGUI or UIElements
So it's an EditorWindow, yes but that's because everything is a EditorWindow
I find it kind of yikes that it's not just a general toolbar with a callback for additional draw
But yeah you're right
heck it, it's not worth tryna calculate positioning to draw on to it
I have created custom editor for my component with a button (in the properties window) that creates children based on a property.
The problem is I have a GameObject with said component inside prefab, and I can't create children because of it.
Any ideas?
Im not sure why this doesn't work.
Accessing SerializedProperty.arraySize gives nullRef, even tho i already FindProperty a list and all that..
Ohmy god. What a stupid bug/mistake
I used List<> but apparently VS automatically fetched from Boo. namespace... which is the wrong one...
@real ivy Rider can remove those references from autogenerated Unity projects. For VS you can use this, drop it in any Editor folder https://gist.github.com/Fogsight/d8dd87315ff12245614334dfdcff5b28
Won't have Boo anymore after regenerating project files.
Thanks 😄 Will be helpful
Im doing as per the docs
AssetDatabase.AddObjectToAsset(newAsset, skill);
// Reimport the asset after adding an object.
// Otherwise the change only shows up when saving the project
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newAsset));
skill.apply.Add(newAsset);
AssetDatabase.Refresh();
But the child SO still doesnt show up until i click another folder and come back to it
What's the most sure way to make it showup immediately?
edit: actually even "saving" doesnt make it showup (as claimed)
Even added
EditorUtility.SetDirty(skill);
AssetDatabase.SaveAssets(); and still not doing it
Im trying to do a nested SO list, which i know works
But im doing it like this
public class ContainerSO : SO
{
List<NormalClassContainer> classContainer;
}
public class NormalClassContainer
{
List<ClassSO> listSO;
}
Then somewhere in editor script:
SerializedProperty myListRef = weaponVariance.GetArrayElementAtIndex(i);
SerializedProperty myWeaponType = myListRef.FindPropertyRelative("listSO");
EditorGUILayout.PropertyField(myWeaponType, new GUIContent("Weapon Types"));
It throws ArgumentException: Field type defined on type WeaponVariance is not a field on the target object which is of type ActiveSkill. on the last line
Aaa nevermind
@real ivy I think you can't access it because it's not serialized.
No its serializable and all that
But it works now
Sorry i was actually trying to draw this https://forum.unity.com/threads/property-drawer-for-enum-flags-masks-download.517750/ but was using the script in the first post instead of the updated one
does it actually look like that tiny screenshot O.o
Yes, and it works
Basically trying to mix that enum mask, this thread
https://forum.unity.com/threads/display-a-list-class-with-a-custom-editor-script.227847/
and this thread
http://antondoe.blogspot.com/2016/08/serialization-with-polymorphism-and.html
to make my omega event basedskill system drawer!
This example will attempt to show you how to display any List<> array in the inspector when using a custom editor script with a few options. I pieced...
(Im quite a beginner in custom editor, all i can do is leech 😦 but hey it works!)
https://github.com/vertxxyz/NUtilities/blob/feature/v1.3.0/Editor/Core/PropertyDrawers/EnumFlagsDrawer.cs
Is mine, though I found a bug in it the other day where it doesn't work properly if you're missing a flag index 😄
it looks like the normal one but it properly displays a list of the values
instead of just saying Mixed
it may or may not require some other stuff in my rando package 😉
Nice collection
I think i came across that a few times before
I really need to split it all up and clean it up so it's more appealing haha
remove the stuff that's no longer maintained
Btw i havent tried the new UIElements but with that around, does it change anything to custom editors? Anything became obsolete or just not preferred?
(I may not know what i'm talking about...)
It changes a lot, but I only use it when I can be bothered
it's more tedious
(for me at least)
Can i safely assume UIElements is more for cosmetics?
What do you mean?
You can make 80% of what you can now using it
and for that 20% you can use an IMGUI Container
Compared to custom editors (which has a lot to do with serializiation etc), ui elements is like just the css part of web dev, to compare (which has nothing to do with the actual content like html/php)
it's entirely about GUI
though it restructures about how you think about writing GUI code
as it's stateful
One cool thing about UIElements is u can use UIBuilder to help u build ur UI
I used it yesterday, it is a godsend superb system
Tho currently it only works for editor UIs only
How do i do this EditorGUILayout.PropertyField(myWeaponType); in UIElements?
The property is a special enum. In CustomEditor, using EditorGUILayout.EnumPopup doesnt work, and PropertyField works
Likewise, in UIElements, EnumField doesnt work, so something equivalent to PropertyField maybe works?
And how does it look like in the uxml side?
Tried MaskField and this happens
There's a PropertyField element as well, not sure what the syntax is
There's a bunch of examples on github
It seems i ran into this https://issuetracker.unity3d.com/issues/ui-elements-propertyfield-in-createinspectorgui-throws-argumentexception-when-staticeditorflags-is-used
And it doesnt say anything about it being fixed for my version (2019.4)...
Reproduction steps: 1. Open attached project "1194627_StaticEditorFlags" 2. In the Editor folder, click on the "SampleSo" asset Expe...
Well not exactly, as im not using static editor flags, but im getting the error and im using PropertyField in uxml. This issue is the closest to it..
I get that error when the property is a normal enum
When i do the EnumMask attribute to it (making it the special enum), it crashes unity everytime the inspector is inspected...
Im stuck in var inspector = new InspectorElement(target);
Does UIElement work on its own custom editor script?
I do this in
[CustomEditor(typeof(ActiveSkill))]
public class ActiveSkillEditor : Editor```
Where ActiveSkill is just an empty SO.
But im getting StackOverflow
Why are you creating a new inspectorelement..?
You're registering your editor as an editor for the ActiveSkill type
Then you create a new inspector for your target
Which then goes and finds the editor that is registered for ActiveSkill or a generic fallback
Which then in turn creates a new inspector for same target
Thanks. I need to sleep now but tmorrow ill continue a bit more fresh
Noob question: I have my project split up with asmdefs. How do I tell an assembly to be excluded from Builds, the same way as an Editor folder?
I'm reading https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html and I must be missing something obvious
Figured it out; had to add a UNITY_EDITOR constraint.
Follow-up: is there a way to make an assembly reference the predefined assembly? My code's in an assembly, but I have third-party code that I can't easily put into an assembly. So I need my code's assembly to reference the predefined Assembly-Csharp.dll
see: Backwards compatibility and implicit dependencies
on the page you linked
Thanks!
You cannot declare explicit references for the precompiled assemblies.
Did they mean to say "predefined assemblies" instead of "precompiled assemblies?" A bit confusing because they have "predefined assemblies" which are Assembly-Csharp and Assembly-Csharp-Editor, but they also have "precompiled assemblies" which are third-party plugins.
they mean like an assembly you download from the internet and put in your project
Can I get help on changing the cursor via custom inspector? I'm trying to make it so the cursor changes after you click a button in the inspector but I can't seem to actually change the cursor when it's inside the scene view.
private void OnSceneGUI()
{
e = Event.current;
//Picking is set to true when the user clicks the button. I've checked and yes, it is true whe I test it.
if (picking)
{
//I've tried the AddCursorRect method but that only works as long as the cursor is within the bounds of the inspector GUI.
GUI.DrawTexture(new Rect(e.mousePosition.x, e.mousePosition.y, 24, 24), Resources.Load<Texture>("Sprites/icons/small/EyeDropper")); //Nothing shows up.
}
}
Does anyone know of a way to add an option to the kebab menu for a specific editor window ?
Yeaaay it works in UIE ! Thx @waxen sandal sry for the ultra noob problems
Default Index is beyond the scope of possible value this is caused bcoz i didnt put a None = 0 element for my enum
And the last puzzle piece is whether UIE can handle polymorphic SO...
they mean like an assembly you download from the internet and put in your project
@severe python
That's the problem; I don't think they meant that. It seems like a typo, and they meant to say "predefined assembly" because that matches what they're describing and the diagram
Help..
I cant click on my enum pop up
public override VisualElement CreateInspectorGUI()
{
SkillApply addApply = SkillApply.Damage;
EnumField enumAddPlanet = rootElement.Query<EnumField>("enumAdd").First();
enumAddPlanet.RegisterValueChangedCallback((t) => {
//addApply = t.newValue;
Debug.Log("Selected add: " + addApply);
AddPlanet(addApply);
});
return rootElement;
And how do i apply t.newValue? Should i just cast it?
Omg it works!
https://forum.unity.com/threads/enumfield-does-not-work-for-custom-enum-type.678580/
<editor:EnumField name="enumAdd" label="Enum Add Popup" type="SkillApply, uMMORPG needed to add the type
How to check if a UIElement field is focused?
Is it possible to filter the object selector serialized field for a TextAsset file to only look for files with a specific extension?
If you make your own
Otherwise just do it in a on change check
And show a notification if it fails
its more about the selector showing all the script files because it indetifies them as text
Then you need to write your own window
yikes
should I make a custom search window for certain assets? or just write to the project window and fill it into the search bar?
the first is probably cleaner
Yeah you gotta make your own filtering
its not that hard tbh. just itterate a list based on the directory namespace
Should use the assetdatabase but yeah
With keybaord navigation, double clicking, tree view, search
or I could cheat and use this https://odininspector.com/attributes/file-path-attribute
tho having an editor window for quick access to everything might be nice, as well for items 🤔 so i can quickly add them to the player or invoke their effect for testing
@waxen sandal
Doesn't Odin have that?
tho having an editor window for quick access to everything might be nice, as well for items 🤔 so i can quickly add them to the player or invoke their effect for testing
@steady crest you mean Unity QuickSearch?
Like Hąste
Ou Spotlight
He means like the objectpicker but for specific type + extensions etc...
I can drop you some code
I have a picker for textasset, but its also got cs files selectable. which I wanted to avoid
To make a small search window
I've only got one for types
I think I have one for objects as well somewhere
But I don't remember where
I could solve it with Odin like this tho
[SerializeField, FilePath(Extensions = "xml", ParentFolder = "Assets/NPC/Data")] private string npcDataPath;
it opens a windows selector which only allows xml files to be selected
tho a generic editor searching window might not be bad, have a nice grid for items on it too with a generic menu to perform some actions on edit mode debugging 🤔
@onyx harness what is this code you speak of to make a search window?
I got a generic purpose window search
On which I implement my more specific needs
Like files, Types, Objects etc.
interesting, that sounds exactly like what i would need (to make)
But it's a bit big
Here's one of mine https://hastebin.com/ocaviwukaj.cs https://hastebin.com/hesusasega.cs
It's made for Unity 2017 though
Few files
So it might be a bit outdated
The filter is the same as the search in the assetdatabase
aha, those filters dont allow extensions tho, which is what im looking for
You can easily extend it 😛
I could even make it a propertydrawer 🤔
oh wow
Not my choice 😛
lol
public class ObjectPickerAttribute : PropertyAttribute
{
public string filter;
public string[] folders;
public ObjectPickerAttribute(string filter, params string[] folders)
{
this.filter = filter;
this.folders = folders;
}
}```
I do wonder, why are you using regular gui and not the layout stuff?
It's a propertydrawer
dumb question
I also just found some weird construct I made a while back
public static GenericMenu CreateGenericMenu(params Tuple<bool, string, UnityAction>[] OnClick)
{
GenericMenu currentMenu = new GenericMenu();
foreach (var keyValuePair in OnClick)
{
if (keyValuePair.Item1 == EditorApplication.isPlaying)
{
if (keyValuePair.Item2 != string.Empty)
{
currentMenu.AddItem(new GUIContent(keyValuePair.Item2), false, keyValuePair.Item3.Invoke);
}
else
{
keyValuePair.Item3.Invoke();
}
}
}
if (currentMenu.GetItemCount() != 0)
{
currentMenu.ShowAsContext();
Event.current.Use();
}
return currentMenu;
}
im not sure why I made this lol
thx for that code! I'm reading it through. I'll see if it needs updating 🙂
It's a lot of stuff. They all rely on my own tools, that's why it won't compile
thats a lot of code. im gonna skim through it and learn some stuff! lol
I did a lot of tools
https://gist.github.com/Mikilo/a6fcde3815330181f67b435b13fe7ccb#file-example
Check this file to learn how to use it
im hesitant to actually spend a lot of time developing tools for the store... cuz i would need to update and support them and thats kinda idk 😦
That's why I don't 😛
I just get myself hired at a place where I write tooling most of the time
I am currently writing tools to lower the workload on my artist for our game while he is working on the story 🙂
I alrdy made a level editor, which is also why i want a editor window with mesh previews. but thats a WIP
I learn while doing my hobby
that's not a hassle for me 🙂
I dropped in the gist, EnumSelector, StringSelector, TypeSelector
StringSelector is the one you want for your "files filtering"
im reading through it right now! 🙂
Mikilo's is probably better than mine 😛
more advanced*
is my visual studio api working properly? i pressed control alt m and control h
What
huh?
ok im just asking because i dont know anything about unity api, so i wanted a quick way to check out libraries and stuff
yeh, but you are running the unity documentation inside visual studio... thats just weird
im new to this, so i wouldnt know that! thanks
Embedded browsers tend to be shit
So it's best to just use your normal browser
I wouldn't even know how to get the embedded browser to open in vs
im guessing its some sort of extension tbh
so if i wanted to check out what this class does for example? what do i do?
Well that's not something from Unity
So you'd just browse to where that is defined in your code
ctrl+click does that
oh
im still looking for the shortcut in rider for that xD
what about stuff native to unity, stuff implemented by using UnityEngine:
I was looking through the right click menu just being confused
I usually just google Unity classname
that makes sense
cant yuo press f1 on unity classes to get the documentation in VS?
Rider throws it into a google search, idk about VS
vs has that installer thingie
and inside that you can install a unity package with documentation
just looking for a way to access it
google is cool, but i have one monitor so sometimes it gets messy
f12 in VS? shift+f12 to find refs?
MonoBehaviour
though if you go to class definition of MonoBehaviour you won't see anything useful 🙂
they're talking about something else - F12 is symbol definition / reference
in-project refactoring support
i don't think ms docs are tied to unity documentation no
ah.. looking for docs? I see
though it might redirect some stuff to unity website if VSTU are isntalled
yeah i installed that
you might be getting something by pressing F1 on a symbol
generic MSDN page most likely D
oh wow I found this https://www.youtube.com/watch?v=erWEG-6hx7g#:~:text=now there are two classes,simple as it could be.
@onyx harness I think this is what I need exactly lol
Creating custom inspectors in Unity can be difficult and time consuming. Odin Inspector make it easy to add custom editor windows to your project with just a few lines of code. This video looks at creating an editor to create and manage scriptable objects.
Video Files (Githu...
I own odin so 🙂
that's funny, in the video, the skin is square
Im actually curious what is done with the propertydrawers from Odin and "unused" functions as a result of it.
propertydrawers are just not included in the build I assume. what about unused functions? what happens to those when you build?
They're probably all in the editor namespace so it won't do much on build
And they're not stripped usually
IIRC there are options for it
They are if the options are set
And since we are usually talking about IL2CPP
They are by default
Not in editor
isn't he talking about a build?
im referring to a compiled runtime
because the stuff Odin uses is in the actual cs file, not an editor for it
since its all propertydrawers
for the editor it doesnt rly bother me that there are unused functions tbh
I'm not sure to understand your question/statement
im just kinda wondering about a situation like this, what remains after the executable is built
[OnValueChanged("change")] public string t;
void change() {}
is it just the string? or does it remove its reflected function as well? or does it not matter at all?
Those keep exciting unless you enable code stripping
Your attribute probably keeps existing as well
Perhaps if there is a conditional attribute on it might get stripped, not sure
I should probably not be asking that here, but on their discord
Attribute is most likely to stay
The method will be stripped
As no one is referencing it
the attribute is in the editor namespace tho? or you mean the attribute reference?
The attribute isn't in the editor namespace
oh
Otherwise you wouldn't be able to use it
If the attribute was in the editor world, you won't be able to build
oh yeah right
The only way would be to wrap it between UNITY_EDITOR
that sounds like a nightmare to do for everything
and probably not worth the effort
Just dont, not worth it
@steady crest https://github.com/Mikilo/ng-unity-versioner
Check this tool I made few months ago, it checks your codebase against many Unity versions in one click 🙂
ooh thx 😄
Do you know about sabresaurus?
I dont, and the only thing google is showing me is yugioh cards
oh, so yu can see what is available for which version
interesting
my compile times on this laptop are literally making me cry btw
cant wait to leave work and get my home pc compiling my editor code
Use more AsmDef maybe
oh, so yu can see what is available for which version
@steady crest Yep, very convenient.
And from this idea, I wrote NG Unity Versioner, which is local, and much more powerful, since I don't just check one single API, but a whole codebase.
Also, I can check private/internal stuff, which Sabresaurus don't
For people doing Reflection/digging stuff, this is a gem.
I made it as an exercise to learn MonoCecil, ended up using it frequently
it does sound like a headache prevention
I need to use that
cecil?
the api thing
What's the best tool for quickly creating compound collider or mesh collider for complex meshes?
How do I draw editors created using CreateEditor BELOW the current custom editor? This (https://docs.unity3d.com/ScriptReference/Editor.CreateEditor.html?_ga=2.180409443.559879248.1593999933-565234236.1534300992) shows them doing it in OnInspectorGUI, but when I do it, it draws them inside the custom editor. Here's my current code. I know it's gross, but it mostly works: https://hatebin.com/byplcpbsqa
@torn zephyr have you tried calling base.OnInspetorGUI() at the start?
No, will do
You mean at the beginning of OnInspectorGUI?
Still draws the new editors inside 😦
thats what I meant :/
anyone familiar with UMA2?
Idk what UMA2 is, if it's an asset then this is the wrong channel
And I've got no idea what you're even trying to do
How do I access the Results? I have the selected values object but I have little idea where to go from there
I want the name of the selected field so I can figure out what the user has selected
Isn't Results the values of a collection?
So yuo should just be able to iterate over it
its the <>4__this thats confusing me
It's a generic
I dont remember how to do that, damn. gonna google
I forgot how to use an enumerator somehow
I fkn hate this laptop...
I will once its done compiling, so in like 5 minutes
Why does rider need to initialize the debugger every time tho... its locking up my editor constantly
I cant seem to... make my ListView have height other than 0. Anyone have an idea?
There's examples on github on how to use it iirc
Im using that, and it does the 0 height thing
So if i
ListView damagePropField = new ListView(damageOut, 100, makeItem, bindItem);
damagePropField.style.minHeight = 100;
ret.Add(damagePropField);
The pic happens
The makeItem among others makes a button, which is that square white button on the left that's behind the text "Enum Add Popup"
ret is VisualElement of the darker box. So it just doesnt stretch and... not "in" the box to begin with
And first of all, something shows up only bcoz i set style.minHeight, otherwise height will just be 0
damageOut is just List<string> btw
When I try: PrefabUtility.UnpackPrefabInstance(newObject0GO, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction);
I then tried: var thePrefabInstance = PrefabUtility.InstantiatePrefab(baseGameObject); PrefabUtility.UnpackPrefabInstance(thePrefabInstance, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction);
And I get: Argument 1: cannot convert from 'UnityEngine.Object' to 'UnityEngine.GameObject' [Assembly-CSharp]csharp(CS1503)
I really need some hep with this there are no examples to work with in the api and almost nothing is found when searching the web.
Is baseGameObject of the type GameObject or Object?
According to the error, it's an Object, when it should be a GameObject
baseGameObject is a GameObject
Try replacing the line with:
var thePrefabInstance = PrefabUtility.InstantiatePrefab(baseGameObject as GameObject);
removes the editor error but: https://paste.ofcode.org/A2zDcmprheMbehCCvKGTTa
what is a prefab instance?
it doesn't seem to be an game object nor and object
the problem is in this line: PrefabUtility.UnpackPrefabInstance(thePrefabInstance, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction);
it is a GameObject
when I do this: GameObject thePrefabInstance = PrefabUtility.InstantiatePrefab(baseGameObject as GameObject); I get: Cannot implicitly convert type 'UnityEngine.Object' to 'UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?) [Assembly-CSharp]csharp(CS0266)
A prefab is a GameObject model.
An instance is an actual working copy of its prefab.
And obviously, a GameObject is an Object.
Because PrefabUtility.InstantiatePrefab returns an Object. You forgot to cast it.
when I do: var thePrefabInstance = PrefabUtility.InstantiatePrefab(baseGameObject as GameObject); PrefabUtility.UnpackPrefabInstance(thePrefabInstance, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction); I get: Argument 1: cannot convert from 'UnityEngine.Object' to 'UnityEngine.GameObject' [Assembly-CSharp]csharp(CS1503) in the 2nd line
isn't thePrefabInstance the cast?
well there is no Object variable
thePrefabInstance is an Object because that's what InstantiatePrefab returns
public static Object InstantiatePrefab(Object assetComponentOrGameObject);
so public static Object thePrefabInstance = PrefabUtility.InstantiatePrefab(baseGameObject as GameObject);?
I was just showing you the definition of the method
oh ok
Not how you would call it
I still don't understand how to call it tho
UnpackPrefabInstance is expecting a GameObject
You are giving it an Object (which is actually a GameObject, but the compiler doesn't know that)
So you need to cast the Object you get from InstantiatePrefab into a GameObject
Before you pass it into UnpackPrefabInstance
well when I do: PrefabUtility.UnpackPrefabInstance(baseGameObject, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction); I get: https://paste.ofcode.org/AjAcrdNVgtVvSVz2BprQuV
And what type is baseGameObject?
GameObject of course
You say it's GameObject, but you define it as var baseGameObject
Which means it will be whatever type the compiler figures it is
nope it is a public GameObject baseGameObject;
the var was in front of the thePrefabInstance
And what have you assigned to baseGameObject?
here is the whole script: https://paste.ofcode.org/rVddghZZBnzKYm2Q65A6pX
I drag and dropped the prefab into it via inspector
If you just need to copy paste an asset, you can use AssetDatabase.CopyAsset where you pass in the asset path of the original prefab and the new path
AssetDatabase contains methods to get the asset path of a given asset instance
I want to duplicate a prefab so it has no attachments to the original
like d&d into a scene then unpacking it and then d&d the unpacked version into the project folder
I don't see why duplicating the asset wouldn't do that
I don't think it will create a variant
then ctrl + d should do that too sec
wtf ok it works again
for some reason ctrl+d didn't duplicate right
works now though
I still would like to understand how to use PrefabUtility.UnpackPrefabInstance tho
this is the 3rd time I tried to get it to work and I still can't
So is unity bugging out with PrefabUtility.UnpackPrefabInstance or is it my inability to understand how it works?
Well, it seemed like you were trying to unpack a prefab asset, not an instantiated prefab
Unless baseGameObject was referencing a scene game object
no it wasn't in scene, was that the problem that the prefab isn't in scene?
UnpackPrefabInstance means unpacking a game object in some scene so that it's no longer connected to whatever prefab it's an instance of
You can't unpack a prefab asset in the project
ahh ok I thought that since they have their own scene when I open them up that that would work
thx then I understand what's wrong at least but man unity is stressing me today with bugs
Guys how can I use 2 custom inspectors to draw a class?
Basically I have a class "A" that inherits from "B", "B" inherits from "C".
"B" and "C" have a custom editor, the problem is that in the inspector of "A" only the custom editor of "B" is shown: https://pastebin.com/YDKsLtqV
How are you expecting that to work though? Would it draw both inspectors one after the other?
Somehow merge them?
One after the other, this is a simplified version of what I'm trying to do
What should I use instead?
PropertyDrawer
Editor is for class
PropertyDrawer is for members of the class
The first is okayish, do its job
Ah ok, I've already used it in other parts of the project.. Maybe I should try using the property drawer
The second is reusable, maintainable
A lot of people use Editor while PropertyDrawer is clearly the best way
I implemented a shitton of tools/editor stuff, I almost never used Editor
you could force this to work wtih editors, but it will be janky and it will duplicate fields
Can I create something like an attribute for a function and then use a property drawer to draw the return value of the function? Something like:
[Preview]
public float MyFunc()
{
return 6;
}
Something like [Context menu("Menu")]
In a ScriptableObject
This thing might be heavy
But you can find many resources about calling a method from the Inspector
Hi all. Im back with the next problem with ListView
So if i understand, makeItem and bindItem is called while u scroll down (and it generates more elements)
I have a ListView, each has a button to RemoveAt, and a button outside of list to Add. Pretty standard
They work, but if i have more elements that i need to scroll down, the button is called twice.
Say the scroll view can only fit 2. If i make 4 buttons, then scroll to most bottom, pressing button 3 will delete element 2 and 3 (in that order)
Then, if i have 5 buttons, pressing button 5 will RemoveAt 0 and 4 (the RemoveAt(4) also causes IndexOutOfRange, expectedly so, bcoz 0 is removed and therefore index 4 becomes invalid)
But you can find many resources about calling a method from the Inspector
@onyx harness the best way to pass variable as parameters in an attribute is to pass the name (string) and then use reflection to get the value?
Yes
@wraith crane Anything in an Attribute must be constant.
Pass the name of a method, or use nameof()
Thanks!!!
can I enforce a unityevent to preset it to a certain object?
Using Reset()?
Pass the name of a method, or use nameof()
@onyx harness can't I just get the name of the "marked" property (the function) in some ways?
Using
Reset()?
@onyx harness how tho? it wont show in the editor will it?
@steady crest Oh I thought you were talking in a MB context
@wraith crane I guess yes
trying to assign an object and lock it so you can only change the functions
From an Editor?
aye
assigning functions in the editro
making a state machine to put it in context @onyx harness
But the Editor is relying on an Object
Which type of Object are you working on?
SO? GO?
SO
SO has the script, I wanna enforce it only to pick from the functions I provide on that object
well, in the SO script to be precise
I provide that SO with the functions on it. and I want to only make those functions available
so I wanna preset the object into the method selector
Does anyone know how to put an attribute on a method?
Because I have created the property attribute class and the property drawer class, but OnGUI of the property drawer is never called (because the method can't be drawn?)
How does [ContextMenu] work?
PropertyAttribute is only on field
What is ContextMenu?
Isn't context menu a property attribute?
An Attribute
There's no built-in function that gets called for an attribute every frame? I have to create a class that manually searches all the methods in all the classes that are marked by the attribute using reflection?
InitializeOnLoad
In your specific case, you want this one:
https://docs.unity3d.com/ScriptReference/TypeCache.GetMethodsWithAttribute.html
Ok ty
Is there anything available that will add mesh colliders for all meshes in an fbx and hides or removes the mesh renderer
Hi all. I have CustomEditor for some ScriptableObject. In this SO, there's a c# class, that i can change the member values. But the values dont save when recompiling scripts.
What's the equivalent of serializedObject.ApplyModifiedProperties() for normal c#?
Can you share some code?
FloatField numField = new FloatField();
numField.RegisterValueChangedCallback((t) =>
{
num = t.newValue;
}
I'm using UIElements, and the value changes are there. The saving values should be a common thing tho
num is inside the normal c# class, which is in this SO
Well, you need to make sure it's all serialized properly
And then you can either create a SerializedObject from the parent SO and use FindProperty to find the specific value
Or you can use Undo.RecordObject or EditorUtility.SetDirty on the SO
Does anyone know why my reflection only returns one attribute every time?
System.Attribute[] attributes = Attribute.GetCustomAttributes(type);
foreach (var attr in attributes)
{
Debug.Log("Found attribute");
}```
But then you'd need to handle undo support yourself
My attribute classes are basically as basic as you can get
[AttributeUsage(AttributeTargets.Field)]
public class OutputAttribute : Attribute
{
public bool ShowValue;
public Port.Capacity Capacity;
public OutputAttribute(Port.Capacity capacity = Port.Capacity.Multi, bool showValue = true)
{
this.ShowValue = showValue;
this.Capacity = capacity;
}
}```
System.Object[] attrs = type.GetCustomAttributes(typeof(InputAttribute),false);
Debug.Log(attrs.Length);```
this just gives me 0
Can I draw in the inspector outside an Editor/PropertyDrawer/... class? If yes, how can I say in which position to draw what I want?
You can get the root UI element and add w/e you want wherever you want
How can I get the root UI element? (What do you mean by root UI element?)
The MonoBehaviour script?
All EditorWindows ahve a root VisualElement, so if you find the window (you can use Resources.FindObjectsOfTypeAll) then you can just add things
Ok ty
With the root visual element of the inspector do I have to draw the things "manually" or can I access something like EditorGUI functions?
Because if I have to draw things in my MonoBehaviour I want to draw them on a blank space, I don't want to draw things on top of other things
(I am searching in the documentation how it works, but I can't find what I need)
It sounds like you just want a custom editor and not some other way to draw in the inspector
And you should look up how UIElements works
Ok, I'll search on yt how UIElements works (I can't use a custom editor, I need to draw an attribute that is used by functions)
??
I have an attribute [Preview] and I want to mark methods with this attribute. Then I want to draw things in the inspector based on the return value of the method marked as [Preview]
You can still do that in CustomEditors, but you either have to overwrite all editors for monobehaviours or extend all your scripts from your own base class
That's probably a lot easier than trying to match a UIElement to an instance of a component
If I use a custom editor for UnityEngine.Object (basically for everything) then can I still use other custom editors for the classes?
Because previously I had some problems with 2 custom editors trying to draw the same thing.. only the second one was drawing the editor
Whenever I try to cache the current value of style properties (UIElements), the value gets set to null. Is there something intentionally preventing people from caching these values?
Hmm. Still cant manage to properly save normal c# class
I have a ScriptableObject, made custom editor for it.
This SO has List<A>, A is a normal c# class. This A gets saved properly
Inside A there's also List<B>. Added this via the custom editor stuff, made sure the instance is really there (debug log the actual SOinstance.list.list.count), and it really is there
The way List<B> gets added is the same as List<A> (didnt even call ApplyModifiedProperty).
But List<B> just disappears when recompiling!
What's happening?
Ok n then figured it out.
It's bcoz class B is abstract (List<B> contains different derived class) and unity just can't handle subclass (unless it's Unity.Object)
My super skill system's custom inspector will need to use many small class B : SO to be saved as SubAsset... but i guess it has to be done..
In a custom editor, if I use property.nextVisible() it also gives me built-in properties that should not be visible (like in UnityEvents "m_persistentCalls", "m_calls"...)
How can I check if the property should be visible?
You don't, Unity has written a custom editor for those things where they decided manually which to show
This is why you don't want to write a custom editor for all Object types
Can I check in some ways where a method info is inside a class? Basically I need to check if a method info is before or after a FieldInfo
Afaik there is no guaranteed order
https://docs.microsoft.com/en-us/dotnet/api/system.type.getmembers?view=netcore-3.1 will probably give you some sort of useful ordering
Afaik there is no guaranteed order
@waxen sandal ok thanks (well I would like to have the same order as the SerializedProperty.Next() function but ok)
Yeah there's no way to guarantee that those will be the same, you can find all serializedproperties and then try to find the matching property/method/field or w/e
Is there a way to find the "parent containing" .asset of a subasset?
IIRC if you put the path of the subasset in this method then you get the path to the main asset https://docs.unity3d.com/ScriptReference/AssetDatabase.LoadMainAssetAtPath.html
Eh the object not the path to the main asset
So..
ScriptableObject so = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(applyDef)) as ScriptableObject;
(Where applyDef is my some subasset of some parent SO)
?
So a subasset's path and that subasset's parent asset's path should be the same?
Someone please explain to me what is this raycast padding ???
If I want to use my editor with scriptable object it doesn't work very well..
If I use target.GetType() it gives me "AssetImporter" instead of the type of the ScriptableObject
(I've solved with a simple trick)
@unkempt fern probably not the right channel to ask and I've never used that property - that said, I would guess it's for modifying the clickable/touchable area for an image - for example if you had a small button but wanted the interactable region to be larger than the image
@real ivy yea that's correct - they have the same path
@split bridge ok thanks
Can I get FieldInfo from SerializedProperty? I've tried in some ways, but it only works if the serialized property is an UnityEngine.Object..
The property could also be in a parent (inheritance) class
You gotta find the targetObject and then go through each layer to get your field
Does anyone know the class that shader graph uses for their right click add node thingy?
How can I get the SerializedProperty.NextVisible without modifying the actual property?
I want to get the next visible property as a return value, I don't want to modify this property
I should clone the property variable and use the clone instead of the real variable, but I don't know how to clone a SerializedProperty variable
(I've solved, I use FindProperty to clone the variable)
So in my SO.someVariable, i can do <editor:PropertyField binding-path="someVariable"/>
But if it's contained in say, SO.someList[i].someVariable, how can i do the binding-path this way?
I don't think you can
😦
I can't get m_Script using .GetField("m_Script")...
As far as I know m_Script is a UnityEngine.Object variable, but I can't get the fieldInfo using GetField ()
Isn't that only a serialized thing so unity can match it to the correct type
What do you mean? (I need the m_Script FieldInfo)
(I've found another solution, I don't need m_Script anymore)
@waxen sandal
It does work!!!
https://forum.unity.com/threads/cannot-figure-out-binding-within-listview-details.660787/
🙂
I've created a simple example to illustrate a problem I'm encountering. In the complex case, I have a list of objects, some fields of which have custom...
weaponVariance.Array.data[0] that's the serializedPath for list stuff
Oh nice
A .uss question..
I did <engine:Foldout text="Weapon Variance" class="heading" value="false">
But then all child of this thing gets the class heading effect. Checking the debugger of the child, it doesnt match any heading selector..
Style rules apply to the visual element and all of its descendants ok i guess that's how it works..
Can I get the editor instance from a serializedProperty? (The editor that is drawing the property)
No
Ok
I'll explain what I am trying to do
I have a class "MyClass" (that has some fields inside it) that is being drawn by a property drawer.
In the property drawer can I check if the value of some field of the class that contains the variable of type "MyClass" was changed?
I don't want to check if a field inside "MyClass" is changed. But a field inside the class that contains "MyClass" is changed
A sibling field of MyClass
You can't do that
PropertyDrawer is not fully aware of its siblings
Ok
And if I have a property attribute and from a property drawer I want to check if a value inside the same class (not a sibling) was changed what should I use? GUI.changed?
I'm creating a RenderTexture in code and attaching it to a camera.
I'm trying to execute this code in editor time (ExecuteInEditMode), but it seems to only work when using a RenderTexture that is an asset.
How do I get camera to render to a code-created render texture?
And if I have a property attribute and from a property drawer I want to check if a value inside the same class (not a sibling) was changed what should I use? GUI.changed?
@wraith crane Yep
You are the one drawing the GUI of the sub-fields, you are suppose to know who is changing already
Wait I am only drawing the attribute
I have a class:
{
public int myVar;
[MyAttribute]
public int other;
} ```
I want to check from a property drawer of "MyAttribute" if any value ("myVar" in this case) is changed
I think I can't do that
You can't do that easily
Is there an hard way?
(Without drawing "manually" all the inspector in the attribute and check if a property change?)
Really dumb question, how do I open an editor window when I ‘open’ a scriptable object
Is there an hard way?
(Without drawing "manually" all the inspector in the attribute and check if a property change?)
@wraith crane Yes there is a hard way, as I stated, a PropertyDrawer (PD) is not "fully" aware of its siblings. But you can still know them and monitor their value
I tried that, but i have a method and I would like to pass the ScriptableObject i clicked on to a method
and I cant pass this in a static function
My class that is in a random folder can't recognize classes that are in Editor folder...
How can make the classes inside Editor recognizable from outside? (I will use them only in editor, using #if UNITY_EDITOR)
do you use Assembly Definition files?
https://forum.unity.com/threads/listview-binds-more-than-it-should.927744/#post-6068436
Anyone came across this problem with ListView?
Basically the bindItem callback is called multiple times when scrolling, on items thats already binded. Its like the bind is done without it clearing out the previous bind
Does anyone know why the canvas is invisible?
@devout iron This channel is for creating extensions to the editor. #📲┃ui-ux or #💻┃unity-talk is what you want
sozz
Anyone able to quickly point me in the right direction for editing the Animator editor interface?
End goal is being able to right click and duplicate layers in an animator
do you use Assembly Definition files?
@weak spoke nope
I am trying to make a property attribute that dynamically show/hides the variable in the inspector.
I have made a property attribute, the problem is that the OnGUI function in the property drawer is only called if the variable is public/serialize field.
How can I make my attribute work like SerializeField? (So if the variable is private, the drawer should be called)
You need to a write an editor for a base class (preferably your own) then use that to check the attributes of the fields
Just a property drawer is not enough for that
Ok, I already have an editor that draws everything (UnityEngine.Object).. I'll make some tweaks to make it work, ty
I am trying to make a property attribute that dynamically show/hides the variable in the inspector.
I have made a property attribute, the problem is that the OnGUI function in the property drawer is only called if the variable is public/serialize field.
How can I make my attribute work like SerializeField? (So if the variable is private, the drawer should be called)
@wraith crane https://gist.github.com/Mikilo/8cb969a50a1eac87c9500d4f9f181324
Just a property drawer is not enough for that
@waxen sandal it is enough, but more complex to achieve
That only works for serialized fields though
But showing/hiding fields are only for serialized fields, I don't understand your concern
You need to a write an editor for a base class (preferably your own) then use that to check the attributes of the fields
@waxen sandal well I can't use this method, because if I want to draw the field I need the SerializedProperty, if the property isn't public or [SerializeField] how can I get the SerializedProperty?
You don't, you get the fieldinfo and figure out how to draw it yourself. Or serialize it
@onyx harness that's what he wants sooo
I have the field info, to figure out how to draw it what should I do? Put a lot of if(field is IDK) to check all the types?
(Can I serialize fields manually from my custom editor? How does SerializeField work?)
Just check the type yeah
And you either need to add serialize field or make it public
But you can't edit it if you don't serialize
Ok
Ok
@wraith crane you can do anything you want manually
But the Serializer requires the fields to have their Type serializable, and either public or private with an attribute.
Should do a write up about how editor scripting works
And how serialization works
And that you're not really interfacing directly with the instance of an object
Hey Mikilo, does NG Remote Scene work if you have no assets?
What kind of no assets?
If you dont possess the assets of the build, in your Unity Editor current project? @severe python
If so, yes it works.
anyone know how to refresh a scriptableobject asset in the project folder? I've tried assetdatabase.import() and assetdatabase.refresh() and it doesn't work. the only way i could do it was to leave the folder and come back to it but i want it to refresh in code
How can I draw the array size of an array in the inspector? If I change the size, I want to also change the size of the actual array
Use the default property drawer for the property
I am using a custom editor that draws every field (also the field inside the array), I can't draw the array "normally", I need to draw every field of the array manually
(Hoping this is the right channel)
So i'm looking to call functions on a specific script attached to a lot of the objects in my game using Timeline, i'm seeing that I would need a signal track and a signal receiver, the problem is the amount of objects that have this script, is there any way to just broadcast the signal gamewide without needing a receiver on each object?
@whole steppe you could have objects "subscribe" to an Action, would that work?(https://docs.unity3d.com/ScriptReference/Events.UnityAction.html)
@wraith crane you cannot change the size of an array. you need to create a new array of the size you want, and copy elements from the existing array into it. (or you could use a List<T> instead, which is dynamic in size)
His question has nothing to do with how to change the size of an array
It has to do with how to replicate the default editor for arrays
How can I draw the array size of an array in the inspector? If I change the size, I want to also change the size of the actual array
@wraith crane
guess I misunderstood, oh well
@keen pumice i'll look into that, thanks
how i can display List<GO>?
if (Script.Prefabs.Count>0)
for (int i = 0; i < Script.Prefabs.Count; i++)
{
GUILayout.BeginHorizontal();
Script.Prefabs[i] = (GameObject)EditorGUILayout.ObjectField($"Prefab {Script.Prefabs[i].name}", Script.Prefabs[i], typeof(GameObject), allowSceneObjects: false);
if (GUILayout.Button("X")) Script.Prefabs.Remove(Script.Prefabs[i]);
GUILayout.EndHorizontal();
}
if (GUILayout.Button("+")) Script.Prefabs.Add(new GameObject());
when i press create new create object on scene
i dont need to create it
i need to add value
@uneven jewel
That's some random person
It's a bit rude
I'm not even sure what you're asking
Do you want to add an empty element?
yes
If so just pass null
no i cant
if (GUILayout.Button("+"))
{
Script.Prefabs.Add((GameObject)null);
}
NullReferenceException: Object reference not set to an instance of an object
DungeonEditor.OnInspectorGUI () (at Assets/MapGeneration/Editor/DungeonEditor.cs:42)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <143cf05d15c44625b70169dc5194636e>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
oh shit
i forgot about smth
all work
ty
Hey so,
//select by search string (object name
script.targetString = EditorGUILayout.ObjectField("Target name", script.targetString, typeof(String), true) as String;
//select by transform (object
script.target = EditorGUILayout.ObjectField("Target", script.target , typeof(Transform), true) as Transform;
I'm trying to have both a transform field as well as a string field, transform field works fine but I can't seem to get the string to work
and using a text field https://docs.unity3d.com/ScriptReference/EditorGUILayout.TextField.html (or text area) is not working, why?
text field worked, I didn't realize it was working because I was getting red squiggles all over as soon as i added it
works now**
This is probably an age old question. I have a class that is extension of MB class. And many of my component inherit from that custom class. In my custom class I have a couple properties that display on inspector. But because that class is sort of a base class, those properties get listed first. I want to write a [CustomEditor(typeof(CustomClass), true] script that will simply place those base properties at the bottom of all other properties defined in the componetn classes. What's the quickest and cleanest way of doing this?
I usually just make some helper functions that draw all things with a few exceptions
And then draw those exceptions later
can I get a sneak peak?
I can give you some pointers but I can't share my code
Just like generic/sample code. A quickie.
Uhh, no.
Oh yay! I accidentally stumbled on it. I installed NaughtyAttributes and but a BoxGroup around them, and now they appear at the bottom of the inherited scripts! I feel like I hit the lottery on this one haha
😆
I'm trying to write a property drawer to rename backing fields to a useful name<foo>k__Backing Field -> Foo, but this broke array drawing
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(bool), true)]
[CustomPropertyDrawer(typeof(char), true)]
[CustomPropertyDrawer(typeof(double), true)]
[CustomPropertyDrawer(typeof(float), true)]
[CustomPropertyDrawer(typeof(int), true)]
[CustomPropertyDrawer(typeof(object), true)]
[CustomPropertyDrawer(typeof(short), true)]
[CustomPropertyDrawer(typeof(string), true)]
public class BackingFieldEnhancedPropertyDrawer : PropertyDrawer {
private static MethodInfo defaultDraw = typeof(EditorGUI).GetMethod("DefaultPropertyField", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
private static Regex pattern = new Regex("<(.+)>k__Backing Field", RegexOptions.None);
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
var match = BackingFieldEnhancedPropertyDrawer.pattern.Match(label.text);
if (match.Success) {
StringBuilder sb = new StringBuilder(match.Groups[1].Captures[0].Value);
sb[0] = char.ToUpper(sb[0]);
label.text = sb.ToString();
}
BackingFieldEnhancedPropertyDrawer.defaultDraw.Invoke(null, new object[3] { position, property, label });
}
}```
```cs
using UnityEngine;
[CreateAssetMenu(fileName = "New Test", menuName = "Gameplay/Test")]
public class TestObject : ScriptableObject {
public Foo[] foos;
[System.Serializable]
public class Foo {
public string bar = "hi";
}
}```
Library\PackageCache\com.unity.inputsystem@1.0.0\InputSystem\Plugins\HID\HID.cs(14,10): warning CS1030: #warning: 'The 32-bit Windows player is not currently supported by the Input System. HID input will not work in the player. Please use x86_64, if possible.'
why is this an issue?
new project, with new input system
??????
@stone summit looks pretty self-explanatory to me. You need to change your build target to 64-bit.
According to that message anyway.
@full vault custom editor with LabelWidth on the property
and one more question
how i can get asset path
like C:/...
maybe this Application.dataPath?
EditorGUILayout.PropertyField should support multi object editing right?
hasMultipleDifferentValues is false for some reason 🤔
Bleh, apparently we're making a new SO for each instance so it doesn't think they're the same