#↕️┃editor-extensions
1 messages · Page 88 of 1
No, I just used var to make it shorter.
internally EditorGUILayout.PropertyField basically just does
if (property.type == PropertyType.Bool)
property.boolValue = EditorGUILayout.Toggle(property.displayName, property.boolValue);
(This is pseudo code, and isn't exactly what it does, but I think it should give you a better idea of what is happening)
oh nice
It does more than that, like makes sure that Unity treats the field properly when working with prefabs. So it is best to just use PropertyField unless you know what you are doing or need it to display differenty.
if I were to then put it in an if statement, can I just call the value directly, or do I need to just do boolvalue too
use boolValue.
You almost never want to use both serializedProperties and direct access.
ok I'll keep that in mind
The reason is that SerializedProperties manipulates the object data on the C++ side, while accessing directly manipulates the data on the C# side. So you can get unexpected values if you use both.
I changed one part, is this correct?
Yep!
Alright I'm on track then, think I have a feeling it'll mess up the dialogue and responses, but that's fine
I fixed it and it crashed Unity, but it seems fine now
alright, that fixed it, thank you @gloomy chasm
Hi, i'm trying to follow Sebastian Lague's tutorial on bezier curve and implementing it in EditorWindow (not scene view) (https://www.youtube.com/watch?v=n_RHttAaRCk),
I have a problem using handles. apparently i can't use handles on editorwindow because it needed a camera, how do i resolve this ?
In this episode we begin creating the curve editor.
Source: https://github.com/SebLague/Curve-Editor
Previous episode: https://www.youtube.com/watch?v=RF04Fi9OCPc
Support the creation of more gamedev tutorials:
https://www.patreon.com/SebastianLague
https://www.paypal.me/SebastianLague
Vector2 newPos = Handles.FreeMoveHandle(path[i], Quaternion.identity, .1f, Vector2.zero, Handles.CircleHandleCap);
this line of code cause a nullref error
void Draw()
{
for (int i = 0; i < path.NumSegments; i++)
{
Vector2[] points = path.GetPointsInSegment(i);
Handles.color = Color.black;
Handles.DrawLine(points[1], points[0]);
Handles.DrawLine(points[2], points[3]);
Handles.DrawBezier(points[0], points[3], points[1], points[2], Color.green, null, 2);
}
Handles.color = Color.red;
for (int i = 0; i < path.NumPoints; i++)
{
Rect handleTan = new Rect(path[i].x, path[i].y, 10, 20);
BeginWindows();
handleTan = GUI.Window(i, handleTan, DrawNodeWindow, "");
EndWindows();
Vector2 newPos = new Vector2(handleTan.x+handleTan.width/2, handleTan.y + handleTan.height/2);// Handles.FreeMoveHandle(path[i], Quaternion.identity, .1f, Vector2.zero, Handles.CircleHandleCap);
if (path[i] != newPos)
{
Undo.RecordObject(creator, "Move point");
path.MovePoint(i, newPos);
}
}
}
i've tried this approach but it also does not work
There's no easy equivalent afaik
You can't really apply a tutorial like that to something else
yeah, i'm trying to replace the handle with gui.window, so it looks like the shader graph but with a window of 20*20
but it also returns a nullref
Chances are something else is null then
You should attach a debugger and see what's null
okay i didnt think about that, i'll try it tomorrow, thanks for the advice
and also, i've managed to create smting like this
but i'm too anxious to implement it myself since my math is not that good
but i'll give it a try
I am working on ScriptableObject Variants, and have the basics working really nicely (with almost no reflection too!).
I was thinking of how to handle Undo, right now I am storing the variant data with AssetImporter.GetAtPath(path).userData, but that of course does not support undo. I can handle it, but it would be rather messy.
The other options I thought of are to store the variant data in hidden sub-assets on each SO, or to have a single file that contains the variant data for all SOs.
Thoughts?
I posted my question in #🔀┃art-asset-workflow but I guess this would actually be a more appropriate place... I started learning probuilder yesterday and decided to make a simple 3d lamp, it turned out as youd expect from a begginer like myself but my issue is that I can't figure out how to make it so that when I move the body of the lamp, the object keeps being connected and moves the head of the lamp down? ( I want this to decorate a house in my game )
any help appreciated
Actually #🔀┃art-asset-workflow or maybe #💻┃unity-talk would be better. This channel is for things related to extending the editor, like making new editor windows and custom inspectors.
You're having the issue where undoing the parent doesn't undo the children right?
No, the problem is that if I change the override state of a property, and then undo. It will still think that it is overridden.
(Well I have not tested undoing children, but I am using SerializedObjects, so I don't see it being a problem, I can just group the undos)
I had an issue where grouped undos did not cross contexts but I'm not sure if it was only my specific case or what
so it would only undo 1 object at a time regardless of how many undo's were on the stack
even if you crushed the groups together
My thinking was that if I had the variant data stored in an asset (thus a UnityEngine.Object) it would be trivial to support Undo. But both ways I mentioned are a bit, ehh.
Just tested and undo/redo works fine for applying it to the children.
Not sure if this should be here or in #💻┃code-beginner, but I'm curious if it's possible to write a script that lets me do custom inputs for navigating the scene view
eg, have orbit on my scrollwheel
Sweet, so the issue you have currently is because the undo state has a different override it's using instead of the current one?
The issue I am having is override states are not stored as part of the ScriptableObject, so are 100% ignored by the undo system (they are not recorded).
So if I change a property in a child and make it overridden, but then undo. It will still show that it is overridden.
ahh yeah I see
that's a tough one, I don't think you can even interact with the undo object in a meaningful way
you could set up an undo listener that fixes the object after it's been undone
but that's obviously pretty gnarly
Undo.undoRedoPerformed += ...
Yeah I wasn't thinking of doing that. I was thinking that if I stored the variant data in an Unity Object of some type (maybe just a text file), then I could group it's undo with the object's undo. However that requires either making one large file for all the variant data, or a file for each ScriptableObject's variant data.
ah, completely missed that this channel exists, might be better off asking here. I'm having Object reference not set to instance of an object error at line 51 and it's to do with Handles.DrawBezier I'm probably missing something obvious http://pastie.org/p/0UJmQXSo3NzAQsSdxUbOOo
I am going to make a wild guess here and say that it is the parameter you are passing that is null.
You can use Texture2D.whiteTexture for a default 1x1 white texture.
@civic river Ah, I found Undo.RegisterImporterUndo() which works! I need to do some messing around to group things properly, but it should work just fine in the end! 😄
I feel unqualified to ask, but this is kind of a big deal,
I want to move the scene viewport with scripts, eg, orbit
For the life of me I can't find any way to hook into the viewport's camera though
If I must, I found a plugin that lets you use 3DConnexion devices to move the viewport, so surely I can figure out how they did it
You probably want to use the EditorTool class
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/EditorTools.EditorTool.html
And you can use the SceneVIew.duringSceneGUI delegate to get get the scene and you can get the camera from that.
You would use the EditorTool if you want to make a tool like the transform tools (Move, scale, rotate).
If not, you can just use the [InitializeOnLoad] attribute to add a listener to the SceneView.duringSceneGUI event, and handle the movement with that.
I see. I wish I was not stupid so I can continue figuring it out
Thanks though, this is worth thinking about for me
Not stupid, I would consider this pretty advanced for a beginner. Even more so if you don't have much or any experience with writing editor extensions!
well, in which case it's my stupid to pursue such a thing, but it would make working 100x smoother for me!
What is it that you want to do exactly? Something about orbiting the camera?
Yeah, I have a mouse that can scroll horizontally as well as vertically, and I want to replicate the behavior in Blender (scrolling by default orbits the focused object, with modifier keys for pan and zoom)
I gotta AFK for a while, thanks for the help!
Hi Everyone, how do I get a world position on SceneGUI in 2D?
I'm trying to create an Editor Tool to help me create a POE-Like Skill tree.
Thank you
Probably the property drawer for that field
So, you still can't draw grids with UI Elements? Because I'm confused to no end because of the runtime variant.
Something like this I mean
My question is, is the grid layout system there yet, because I see nothing of it in the examples.
Instead of having to do it all manually
Because it was asked 3 years ago but on the docs is says it's still not there yet.
Well I'm not sure what they mean by grid view though, but I guess it's this.
Alright, that's what I wanted to know.
Didn't want to work on something I don't need to.
Is there some way to delay reimporting a specific asset until after the user is no longer inputting a value in to a field? (Can't require a custom editor)
As long as you don't apply the import settings while it's being changed it doesn't reimport
Yeah.. that is exactly what I am doing 😛
I am doing a check to see if any fields of an SO are different than the SO it inherits from, and if so I am adding those fields to a list which I then store in the AssetImporter.userData. And then I need to save those changes. It works great but the problem is if the user is dragging a field, the field will lose focus and it messes up the hot controls.
Going to need some more context here
Right, sorry. So I am making ScriptableObject variants. I store SerializedObject paths for all of the properties that have been overridden, the GUIDs of all of the variants of the SO, and it's parent GUID if it has one. They are all stored in AssetImporter.GetAtPath(path).userData.
I have hooked in to a unity callback for every time a object property changes. I iterate over all of the properties in the object that changed and see if any are different than it's parent. If so I add them to the data stored in the userData. I then save the importer.
if (RegisterOverriddenProperties(targetSerializedObject, data, archetypeSerializedObject))
{
Undo.RegisterImporterUndo(path, "Changed Override States");
var importer = AssetImporter.GetAtPath(path);
EditorUtility.SetDirty(importer);
ArchetypeUtility.SetArchetypeData(path, data);
importer.SaveAndReimport();
}
// Then here I iterate over all of the properties again and apply each to the variants of the SO assuming that the variant does not override it.
The problem is that the change callback is invoke every time that a SerializedObject has ApplyModifiedProperties() called (and it actually has things to apply)
So when someone drags a field then it'll try to apply every time?
No, it only edits and saves userData if it is actually different. So once a field has been overridden, it will not edit the importer data if the same field changes.
Honestly I would prefer it to work how Prefabs work, and only apply changes it the variants after an edit has finished. But I am am not sure how to do that. (looking at the source now to see if I can figure out what Unity does for prefabs...)
@waxen sandal So it is kind of hacky but I can do it in EditorApplication.update by keeping track of the undo group when I set the import data and then in the update call, see if the current group is different, and save it there.
But that sometimes will give a warning about hot controls, and the editor will not longer update for hover events and stuff until I select something.
Would it be a bad idea to just use hidden subassets to store the data instead...?
I'd just save it in a SO in ProjectSettings
Like just have a master file that keeps all of the data for every SO?
Yeah
Maybe that would be best, but it annoys me that this works perfectly except for this one thing :/
I can't remember, are ProjectSettings included in repos normally (in regards to version control)
I guess I will do that then. On the plus side I won't have to make a note about not using the userData. It just hurts a bit because using the userData of the importer is so clean, and so close (yet so far) from working.
Eh, userdata is annoying
There's no standard so if someone else uses it they might relpace your data
Yeah I guess that's true. Would you save in ProjectSettings, or just in a folder within the asset's own folder? I ask since the data isn't exactly Project Settings since it is just directly related to assets. Put it also kind of feels right in the Project Settings.
The worst they could do is delete it I guess. I could hide it too I think if I really wanted to.
I got 2 questions.
1. I have been struggling with naming.
A. I can't call them prefabs, so I have been calling them Archetypes, is that good?
B. What do I call the SO that another SO derives from? "Original", "Source", "Root", "Parent", "Archetype"? I know this is dumb, but I keep waffling between them and want another opinion.
2. Should you be able to change in the inspector what SO an SO inherits/derives from? Or should it be like prefabs and be locked it?
Opinions please
You should probable be able to change it if it's the same type
But it's not that big of a deal probably
Is there any callback for when an inspector opens?
Edit: I found Editor.finishedDefaultHeaderGUI which does exactly what I was wanting.
Or better yet, a way to have a custom editor for a ScriptableObject Importer.
is there a extension that makes code look good
and how would i implement it onto my editor
Uh... do you mean like when you select a C# file in the project browser and it shows the code in the inspector?
no i mean format it
in the editor
I'm sorry you are going to be more clear on what you wanting. I am not able to follow.
hmm i dont know terms that good let me show you in images
1 sec
so heres how code will be looking
Do you mean you want it formatted like that?
i want it to be formatted like the second image
u can see the difference
uneven spaces,massive unused space
i need to do this because yesterday i called a function in a function
You are talking about in Visual Studio, not in the Unity Editor right?
yep
and i have also seen stuff like these
OH, this channel is for writing extensions to the editor (Like new editor windows and custom inspectors).
I think you would be better asking in #💻┃code-beginner though the forums may be best. Tbh I am not sure what happened, Visual Studio should handle the formatting for you. Is the formatting like that even when you create new scripts?
yes it formats like theat even when i create a new script
after saving it looks all wonky
Not sure what to tell you, best suggestion I have is to uninstall and reinstall maybe? Good luck.
ah lemme try that ty
I understand that EditorWindow.focusedWindow will let me see what window is focused, but how do I compare them?
eg,if(EditorWindow.focusedWindow == [what goes here?])
note: please ping, I will probably be in bed in a few minutes
What are you actually trying to do
That snippet is intended to compare it to a certain window, i.e. sceneview or your own window
Hiya, actually I trying to use the mouse over one, which works the same.
I’m currently using EditorWindow.mouseOverWindow == SceneView.lastActiveSceneView
But I don’t know how else I could refer to a window
What exactly are you trying to do?
@crimson estuary
If i understand you correct, you probably want to do something like
if(EditorWindow.focusedWindow == MyWindow.Instance){}
make a static field "Instance" in your window class and then set the Instance either in OnEnable or when you're creating the window
I'm trying to make a script (extension? plugin?) that lets me orbit my scene with my scrollwheel, but I want it to only do it if I'm moused over the scene view
Why not use OnSceneGUI?
I'm not sure if OnSceneGUI will be called at the correct times
What are the correct times?
any time the mouse is over the scene view, for now
Any time gui receives input it'll redraw and get called
So at the very least mouse clicks + scrolls but likely move mouse as well for hovering
The issue is I don’t think it will receive input
And it should work when the mouse is stationary
Scrolling is input
Scrolling will be overridden as something else afaik
Eg, I’ll be grabbing the scroll input to do a calculation with
Not to mention the editor doesn’t seem to recognize horizontal scrolls at all right now
I must be stupid or something but I can't get OnSceneGUI to work
Like I said previusly, you will want to use the SceneView.duringSceneGUI event.
You will want to use Event.delta
if (Event.current.type == EventType.ScrollWheel)
{
float horizontalScrollDelta = Event.current.delta.x;
// Do something with the horizontal scroll...
}
I'm processing that
one moment
I'm currently still struggling just to print one line when I press a key
Oh I see. Well where are you putting the code. That makes a big difference 😉
It's currently in ondrawgizmos
probably the worst place to do it but that's where it is right now
Yeah.. idk if you can even get the events in OnDrawGizmos.
Probably not, but it's the only one that updates once per frame as if it were an Update()
*That I can find, and that's probably the wrong way to do it
void OnDrawGizmos()
{
if (Event.current.keyCode == KeyCode.B)
print("Pressed B");
}```
This works, ish, it starts filling the console but doesn't stop until I move the mouse out of the unity window
Oh, my bad. It keeps sending it until I move the mouse at all
[InitializeOnLoad] // This calls the static constructor everytime unity reloads.
public static class CustomSceneControl
{
// This is a static constructor and is called only once.
static CustomSceneControl()
{
// This adds the `OnDrawSceneGUI` method to this event. So everytime this event is raised, the methods that are added to it are run. This event is called everyimt the SceneView's OnGUI method is called.
SceneView.duringSceneGui += OnDrawSceneGUI;
}
private static void OnDrawSceneGUI(SceneView sceneView)
{
if (Event.current.type == EventType.ScrollWheel)
{
float horizontalScrollDelta = Event.current.delta.x;
Debug.Log("Scrolled");
// Do something with the horizontal scroll...
}
}
}
ok let me process this for a minute, thanks
Sure, and don't forget you can look at the docs on unity for more info about something 🙂
Sometimes the docs expect me to know more than I do, or I can't actually figure out what the tool I actually need is called
I don't want this to turn into MyFirstProgrammingExperience™️ but can I know what the [...]duringSceneGui += OnDrawSceneGUI does?
I just wanna know so I can actually learn it proper and not have this kind of issue again
Sure! So duringSceneGui is a type that is called a delegate. It is a way of basically referencing and invoking methods.
private MyDelegateType logInfo;
void Start()
{
logInfo = LogName;
}
void LogName()
{
Debug.Log("My Name is John Smith");
}
In this example, every time you call logInfo(); it will be as if you did LogName();.
If you want a more in depth explanation, just search for "C# delegate" and some good info will come up 🙂
so it's like, an alias for something else?
And the += you did added OnDrawSceneGUI to.. duringSceneGui?
Correct, just like with int where += means 'add this other value to my current value`
By using += you added it to a list of everything that DuringSceneGui will trigger, and if I added something else it will also trigger with it?
Ohh I see
Theoretically I can add more than one of these "lists" together?
Yeah (assuming I understand what you mean)
Well I don't think there's a use for it but lets say there's another delegate similar to duringSceneGui, and I have a few things on that. Can I do duringSceneGui += theOtherDelegate?
Honestly I'm not sure. I think?
Well, it doesn't matter that's a dumb question, but thanks!
One more, is, why does it not have () on the end of OnDrawSceneGUI?
Is it supposed to just be the method name without arguments?
Because you use () you are telling it to invoke the method and it would return whatever it's return value is. Instead we are passing the reference to the method itself.
So it is indeed just the method name, and there's no way I could possibly screw it up(...?)
Cool!
Thanks a bunch!
private static void OnDrawSceneGUI(SceneView sceneView)
{
if (Event.current.type == EventType.KeyDown &&
Event.current.keyCode == KeyCode.B)
{
rot.y += yRotBy;
if (rot.y >= 360) rot.y -=360;
sceneView.rotation = Quaternion.Euler(rot);
Debug.Log("Work!");
SceneView.RepaintAll();
}
}
So far this is what I have going, and it does work, but it's very choppy. It seems to only be once per keyboard repeat in this case. Is there any way to get it to move constantly?
Also, it only works if I have the Scene tab active, where I would like it to work whenever I'm hovering on the Scene window
Im not sure if I should ask here or general code, but since the code are in editor window, i assume i can ask here.
It is a tool to package prefab in asset bundle 1 by 1.
Basically the code is simple:
- Check the selection (can be in project or hierarchy). If hierarchy, get original prefab
- Go through all the list of objects in the selection (atm, i will manually select only prefab)
- Then process it to send to asset bundle (it just a list of object) to pack individually.
Question here, I already have some solution to check if object is a prefab in scene or project.
Problem is, somehow even I selected couple of fbx or other file type, it got sent to asset bundles.
So i know the check for prefab was incorrect.
I used : PrefabUtility.IsPartOfPrefabAsset(), PrefabUtility.GetPrefabAssetType()
But seem it failed sometimes (especially when you select multiple objects)
The prefab is simple prefab, no variant but contains some 3d model packed individually
Anyone have tips / idea? (i will delete this if this was in wrong section)
This is editor script not for runtime.
I'm guessing that the gameobject that unity generates for meshes (to drag it into the scene etc) is a prefab and thus detected by those APIs
Not sure how to differentiate between them though
Maybe try AssetDatabase.GetMainAssetType ?
oh silly me, 3d model is a prefab, but it prefab asset type model
i done a wrong check earlier (i was using != not a prefab).
so as long as i check if it regular or variant prefab, it should be ok
In the upcoming unity (alpha) looks like we are getting floating tooling window inside scene view - but why break the design defaults and prevent from putting this back where my muscle memory remembers it should go ? this is bad UX :< plz don't break conventions
breaking standards isn't very friendly
so much empty space !
ngl pretty cool snapping , but i'd prefer to have it below the title bar
<@&502880774467354641> this is cool , but and we also add an option to use the old way ?
my gosh, this remind the trauma of GIMP or blender for first time
tru
@tough cairn Don't ping admins with non-server related issues.
There's a lot of problems with the bars, but I think in the long run it'll be much better for in-scene tooling
Do you even lift ...I mean, grid snap?
Single bar setups look pretty good. Had a pretty negative reaction to the multi bar setup where it seems to be taking a lot more space than before.
my point is that the current tooling bar stays ( play button and cloud stuff no the right ) and it's looks empty :\
They said the considering several different things to do with the space. Like letting you put 'favorites' there, or maybe if they do a blender style 'workspaces'. Also said they were considering maybe even just getting rid of it all together. (These are just ideas they said they were considering)
I have ExecuteAlways script. this script calls functions which I need .When I change variable values from original script it executes anytime but when I use custom inspector for changing values functions arent execute always.what is problem here ?
In your custom editor, are you using SerializedPropertys to change the values? If not, then that is your problem I assume.
I will try
Its doesnt work I guess
You will need to show code.
its just basic custom inspector for 1 variable
You need to use SerializedProperties.
That is why it is not updating like you want.
I search about SerializedProperties but its shows very complex things and I guess I dont need complex thing such a basic thing
am I wrong ?
You think you don't need
am I need 😄
If you just want a slider why not use the slider attribute?
You are right but I am trying to learn how can apply thing which I want
is that ok ?
You don't want to recreate the serializedObject very frame and you need to apply it if it's changed
Almost, the editor already has a property called serializedObject so no need to make you own.
Oh yeah that too
You also want to get the value from the serializedProperty, not just set it. Right now you are getting the value from minMap and setting it with the SerializedProperty. You don't want to do that.
And lastly, at the end you want to make sure at the end to call seralizedObject.ApplyModifiedProperties() otherwise the changes will not be saved.
its works and I figured out everything I guees thanks guys @gloomy chasm @waxen sandal
Nice, however you want to change the second parameter for the slider to be serializedProperty.floatValue instead of miniMap.RotationOfMapDynamic.
It can also cause bugs if you keep it how it is.
I got it thanks I can make cleaner
Like what?
In this particular case, not much I guess since the change is being applied each frame. But things could get out of sync and cause unexpected behavior in other situations.
Just being on the safe side, you know.
I see
Hya. Im trying to instantiate a prefab, while working on a Prefab in the editor. Using PrefabUtility.InstantiatePrefab it keeps spawning in the Active Scene, not in the prefab. How would I spawn it where I need it to?
Hi guys! Just looking for some approval if this looks good?
sorry, accidentally covered that line up in screenshot. It's suppose to be if (!AssetDatabase.IsValidFolder(folderCheck)) AssetDatabase.CreateFolder(parentFolder, folderNames[i]);
If it is supposed to be a check, where is the check?
yeah, and it's a class I just call whenever I want to check if the targeted location has the folders for the things being done. Basically I have a default location for the things I'm doing, but, want to allow the user toe be able to change that location. So if they do, it will create those again. I know it seems pointless to probably have something like this. Just trying to break down everything as simple as possible and make it easy to use in other projects
Dunno why, but sounds much straightforward to use Directory.CreateDirectory()
I'm still fairly new to this world, and just learned about that now. I'll look into that!
It just takes a path and create folders if they do not exist
Anyway, i would suggest you to have some kind of Utility classes where you put your reusable chunks of code like the above
so in this case do I remove the need of using UnityEditor?
oh sweet! I love Unity, but, also love to use what I can away from it just in case ever in an environment not Unity
Sorry to keep bugging you, do you mind explaining Utility class further?
Good habit
oh is it basically making it a static class?
Just a class where you gather independent methods. Like a simple folder check, sum 2 numbers, print stuff, simple stuff in general
What do you mean?
I guess I mean do I make the constructer(?) static? So in FolderCheck class do something like, public static void GetFolders(string path) and then I can access that by just doing FolderCheck.GetFolders(string)?
what is "allowSceneObjects"
Those are objects in the scene. If you create an ObjectField the user wont be able to select scene objects without that true
thanks 🙂
I believe the asset graph package will also do what you want without any codding. https://docs.unity3d.com/Packages/com.unity.assetgraph@1.7/manual/index.html
Hey guys.
So I want to write this editor script, which changes the Input type from the old InputManager to the new InputSystem. Also, I want to include certain packages from the package manager, but I don't want to do any hardcoding for the package version numbers depending on unity's version.
Any ideas?
Is it possible to make PopupWindowContent from https://docs.unity3d.com/ScriptReference/PopupWindow.html into a method?
doing
public PopupWindowContent TestWindow()
{
return TestWindow()
}
crashes me Unity and I know that is wrong, but, I'm not googling the proper phrasing to find what I'm looking for
You are calling yourself
so uhh, let me think for a minute, I would instead do a new PopupWindowContent field in there and return that instead?
Perhaps
okay, I'll keep messing with this, thanks for the advice again
okay I decided to just go the normal route and make a new class with popupwindowcontent since I couldn't figure out this way
just put it into same file so I still get the same organization I was trying for
Why are you using SerializedObject?
But yes it is, sort of. You get the material it self from a SerializedProperty using objectReferenceValue, and then just get the texture property from that.
Hi
Is there a simple way to draw a Shader Dropdown selector in a custom interface like in the Material Editor? The MaterialEditor code for drawing this dropdown is terrifying...
Thanks !
I cant assign "SerializedProperty" objects from custom inspector how can I solve this
Not off top of my head. maybe using AdvancedDropDown and Resources.FindAllOfType? I can take a look at the Unity shader dropdown and see if I can give you a better suggestion if you drop a link to the github file.
You are going to need to provide your code in order for us to have any idea what is going wrong. 🙂
If it is a lot you can use https://paste.mod.gg/
Thanks ! Here is the link :
https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/Inspector/MaterialEditor.cs
It use an Advance Dropdown, but the code seems realy complicated for something like this
(sorry for my english)
Here is the code. You can ignore everything that is not between 305 and 447.
https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/Inspector/MaterialEditor.cs#L305
For the most part this exactly what you would have do too. A lot of it is just boilerplate.
(Btw your English is perfectly fine, wouldn't know it wasn't your primary language)
Thank you very much, I look at it 🙂
The AdvancedDropDownGUI class that MaterialDropdownGUI inherit from is an internal class. Hope I can make it work without it !
its strange but I can edit now its works fine now lol
Yeah.. I'm not sure why they are even using it exactly... All they are doing is changing the name of the items as far as I can tell, but you can just set them when you make the item...
Maybe it is legacy code that was never updated properly or something?
You should be able to get the exact same results without it just fine.
Thank you very much, I will try to make it work. Thank you very much for your help !
Sorry, it is a bit hard to follow along. But no, you can get textures whenever.
If you want to share the code I could try giving you some better advice.
Sure thing! If you have any questions about it, or don't understand something feel free to @ me 🙂
Thanks !
Alright lets see. So unless some of the fields do not have public properties, I see no reason to use SerializedObject and SerializedProperties. It just makes things harder in this case.
That is because Materials are not like other Unity Objects. You need to use it's built-in methods to get and set shader properties like myMaterial.GetFloat(...);
Well there is no Material component.
So I would imagine that it would throw an exception.
What you are looking for is MeshRenderer
Take a look at this and see if that helps you 🙂
https://forum.unity.com/threads/batch-change-all-fbx-default-materials-help.626341/#post-6874607
No, look at the code specifically in the commend that is linked there
in the roadmap
@stray hemlock Please don't spam on the server. If you want to discuss something use #💻┃unity-talk
So, I have a frustrating problem trying to make some dialogue data. I want to attach unique behavior to certain lines of dialogue without bloating up a single class. The problem-space in it's most basic form is that:
• I've got a list of some data.
• There is no guarantee that every instance of data is the same format.
• I wanna be able to edit all of it outside of runtime.
• Using ScriptableObjects inside this list would be far too time-consuming and messy, unless they can exist exclusively within it.
Ideally, I'd have a ScriptableObject with a List of line instances which all implement an interface that the dialogue box can call, but Unity doesn't like to serialize polymorphic data.
Anyone solved this problem before?
Tried that. Got nothing.
...I mean, like, actually nothing. Nothing showed up.
once you assign serializable values they show up
the default null case will show nothing
Unless you use an editor for it like mine https://github.com/vertxxyz/Vertx.Decorators
Okay, but how would I assign specific implementors, and where?
Good point. I'ma try an enum and a button. Enum for specifying which type, button to add it. I assume it's a reorderable list where I can just remove things.
It's adding stuff to the list, but it's still not showing up in the inspector.
what are you adding? A plain serializable class?
The List is of interfaces. What I'm actually feeding the List is a serializable class, yes.
I could just convert the interface into an abstract class, if need be.
Can you link to some code?
...Oh wait a minute, I have it backwards. Must have converted it to a class and never set it back to an interface, one sec...
Aha!
That did it!
Thanks for the help. I was rage-coding a couple hours ago.
Hi, I'm having an issue with an editor script. I have a script that cleans up my scene and then exits the editor. When I call the cleanup part of the scripts without the editorapplication.exit it works fine. When I add editorapplication.exit at the end of the cleanup part, It just exits Unity without doing all the things I asked it to do. Anyone that has experience with this issue?
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.
Here you can see the code
If I comment the editorapplication.exit it works
but with it, it just exits without doing anything
I also added a save function before the exit statement so it saves my scene but it didn't solve it
It's likely not saving the scene to disk
Not 100% sure what you need to do to make a scene save but you can try doing SetDirty, then SaveAssets
in editor, is there any way to interact with system clipboard to get something other than only plain text?
I want to add functionality to paste images from system clipboard, but no method I tried works so far
Unity natively doesn't seem to have such functionality, and both Winforms and WPF dll's refuse to work within editor
It'll still just have plain text in it ^
You'll have to parse it yourself 😛
Oh yeah I didn't read the middle sentence
I made my own exe that I called into when I wanted to get RTF from the clipboard. Sadly clipboard stuff just seems to be a pita
yeah, it's for text only - if there is image in clipboard or anything else than just text, it will be empty
ok, managed to figure out promising solution using extern calls to user32.dll API
@waxen sandal I tried using saveScenes but that didn't fix it, I also checked if the scene was not dirty and only then it should exit editor but it still exists without saving
I'm not sure if it's a bug or that I'm missing something but i'm doing it exactly like their documentation but it doesn't seem to work
hello does anyone know how i can bake impostor for multiple objects?
multi object editing not supported
Idk ask the amplify people
This is for developing your own editor plugins not help with existing plugins
yeah but i thought someone can tell me if its possible to write a for each that calls this button on each asset in the scene
Sure, you can just write a static method and annotate it with MenuItem that'll find all of those components and calls a method on them
that's what i was looking for thanks boss
I'm trying to clear my folder through an editor script, using assetdatabase.deleteAssets
But I have to give a list of outFailedPaths, any idea on how to do this?
It is a bit confusing, but actually it populates that list parameter with paths it could not delete.
I don't really understand what they mean by it
oh okay
So I just have to make a random list and they'll fill it?
Yeah, just give it an empty list and it will populate it.
Okay thanks, their documentation is a bit confusing on this part :p
I was wondering how I could generate an image of 3d models when I import them in the editor, so I can use them in my UI. I am aware of render textures, but this seems like it could be a better solution, depending on complexity. Any ideas on how to generate the image in the editor would be appreciated, thanks.
can I ask here help regarding the use of LeanTween?
Greetings, i am working on a room builder editor tool for a project of mine. I am trying to make a Method that detects if a Vector3 exists inside a region. My current problem is that the current region that i am checking for is not local to a rotation. As such, the detection region on some rotations is incorrect as seen below (Magenta boxes are the detection areas):
here is the code: ```csharp
public static bool IsPositionWithinRegion(this Vector3 pos, Vector3 regionCenter,
Vector3 regionSize, Quaternion regionRotation = new Quaternion(), bool showDebug = false)
{
// regionSize = regionRotation * regionSize;
//Testing matrix stuff
Matrix4x4 regionMatrix = Matrix4x4.TRS(regionCenter, Quaternion.identity, regionSize);
Matrix4x4 currentMatrix = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one);
if (showDebug)
{
Handles.matrix = regionMatrix;
Handles.color = Color.magenta;
Handles.CubeHandleCap(GUIUtility.GetControlID(FocusType.Passive), Vector3.zero, Quaternion.identity, 1,
EventType.Repaint);
}
bool isWithinXLimit = pos.x > regionCenter.x - regionSize.x && pos.x < regionCenter.x + regionSize.x;
// pos.x > regionCenter.x - regionSize.x && pos.x < regionCenter.x + regionSize.x;
bool isWithinYLimit =
pos.y > regionCenter.y - regionSize.y && pos.y < regionCenter.y + regionSize.y;
bool isWithinZLimit =
pos.z > regionCenter.z - regionSize.z && pos.z < regionCenter.z + regionSize.z;
return isWithinXLimit && isWithinYLimit && isWithinZLimit;
}
I have tested a bunch of things with no success. My guess is that matrices are the way to go in creating regions that account for both rotation and position but i am not sure how to use matrices in a condition similar to the example above. I am very new to matrix math so, any help would be appreciated.
I feel like this should be the easiest thing to do but I don't know what I'm doing wrong, I can't get a gameobject from this to put in my editor
wdym
ObjectField return the item selected or the item you passed depending on what the user does
So you got to assign the return value to the objectreferencevalue
so I would add "animationSetterGOProperty.objectReferenceValue = " before the ObjectField?
That doesn't work
Gotta provide more context then
I want to make this a gameobject that persists when I restart Unity because for some reason it sets itself to nothing after restarting
I need some help I don't know what I'm doing it seems
this is what I would assume would work, but it doesn't let me assign anything in the inspector
it's just a gameobject that lets me put actors in a position that teleports actors to a position before they play an animation
I mean the definition of the property
I don't understand
if you mean ApplyModifiedProperties, this is in a function called Draw, and everything is applied afterwards
how do I apply the SO in this case
I only really know how to do it for properties
Ah yeah that looks fine
but
it doesn't work
it only shows up as None, and any time I assign anything to it, it still shows up as None, you said to apply the SO, but I don't know how for object fields, could you please help, been googling it for a while now, can't find anything for gameobject fields
@waxen sandal
if I leave it like this, it doesn't give me an error in visual studio, but it gives me this error in unity which doesn't mean anything to me
like this*
can anyone help
leaving it as just the direct object field works...until you restart unity, i just want it to save the field instead of me having to re-assign everything again
the line in red works, but the line in blue sets it back to null, I don't understand
can I just not serialize objectfield
hello does anyone know where is the tool thing because i am following a video and i cant find it
i want aot pre build like this
I've never used bolt
it is for uploading my game
tbh I've never used Unity for more than standalone builds, so I'm completely clueless
I'm just stuck on figuring out on how to make a gameobject field persistent and not disappear after restarting unity
ok thanks for trying
serializedObject.ApplyModifiedProperties()
I changed my code a bit so I have to revert back
if you recall, I set my npc dialogue system so that all of it would update after this Draw function
doing just this causes an error, what can I do to fix it, I just wanna make a gameobject field that doesn't delete itself after I restart unity
I don't know why this is so complicated
If you double-click the error in unity what line does it take you to?
Idk what the behaviour is if you have 2 SOs that you apply in sequence but only change one of them
sorry for my late response but it's this line, the gameobject in question is null at first
@gloomy chasm
I would guess that animationSetterGO is null.
yes
I want it to be null at first so that I can assign it in the inspector @gloomy chasm
Well you can't make a SerializedObject from null.
I'm not sure what to do then
@serene spear Can you share your code through here https://paste.mod.gg/ so I can try to understand what you are trying to do.
@gloomy chasm https://paste.mod.gg/docuxexape.cs
Okay so this is pretty simple https://paste.mod.gg/tovorivoho.cs
I tried that about 10 times earlier, unfortunately, it doesn't let me assign anything to the object field, and your code is basically the same as what I tried then @gloomy chasm
If i understand correctly, you just want the field animationSetterGO to be persisted?
yes
Try to dirty it when it changes.
I can't set it with objectreferencevalue
Before quitting Unity it should pop a warning to save the project
Because a reference from a scene cant be saved in a project asset.
The scene is temporary
As soon as you reload it, the refe is gone already
it saves my animator references though
Where does it come from?
nvm, I got that wrong, that's from my project
OH, I feel dumb sometimes. Why didn't I notice you are trying to save a scene object to an asset. Unity doesn't let you do that.
Many ways, none is really reliable
GlobalObjectId, path, custom Component, anything that can identify this GO from your SO
I'm just thinking about where I should store the reference now
possibly somewhere outside of the SO
Replace the GO by a string or whatever suits you
oh
Well, if it is in the scene, it's pretty easy, it works already
this is probably very close to what I'm going to do
Man, I have been digging through the source code trying to figure out if there is a way to hide an EditorWindow without closing it, but it just doesn't look like there is 😦
The problem is that it seems the only way to do it would be to Close the container window, but that Destroys the EditorWindow. And if I set the field referencing the EditorWindow to null, then I get a null exception.
I take it back. I got it working 👌
hello i have trouble building my game
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002ca] in <03b7a01d7ff445ec8ed231b348714f65>:0
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <03b7a01d7ff445ec8ed231b348714f65>:0
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)```
this is the error also there is another one
Does someone know if it's possible to have a ReadOnly list of objects, but the properties of that object are read/write?
You would need to make a custom editor for it, but yes.
You would use the UnityEditorInternal.ReorderableList (Assuming you want it to look like that, otherwise you can just manually draw all of the items)
What if he'd try to do it in a plain C# class where custom editors are not an option?
Still possible? I'm curious as well
😀
If it is a plain C# class you can make a custom PropertyDrawer instead. But if you want to know if you can do it without any custom editor coding, the answer is no.
Thx!
CopyPaste from MSDN
A readonly field can't be assigned after the constructor exits. This rule has different implications for value types and reference types:
Because value types directly contain their data, a field that is a readonly value type is immutable.
Because reference types contain a reference to their data, a field that is a readonly reference type must always refer to the same object. That object isn't immutable. The readonly modifier prevents the field from being replaced by a different instance of the reference type. However, the modifier doesn't prevent the instance data of the field from being modified through the read-only field.
Short form: if you have a readonly list where the items are reference types, you can change their properties
But ofc not the items themself
Idk if that's helpful or answers the question in anyway
I believe when he said "ReadOnly", he meant a list that you cannot add or remove items to within the unity editor. I could be wrong, but from what I remember I think unity either can't serialize readonly or just ignores it.
nope, you are right. that is exactly what i meant
Ok then Mechwarrior is 10000% correct, gotta need a custom editor or property drawer
yup, i'm trying to figure it out right now^^
With.... A try/catch?
As a trick, putting min/maxSize to 1,1
Not a real hide
For give my ignorance, but how would you use a try/catch in this case?
I got it working using the RemoveTab method in DockArea. This works great however it has the problem of unity throwing a warning when changing layouts if I store a reference to the editor window.
Oh, that seems like it would be worth a try messing around with. Good idea, thanks!
Can we assign something in inspector variable through editor code? 🤔
I don't know you talked about exception when closing
Ah got it. The error was being thrown from C++ in this case, so nothing I can do about it.
How?
@gloomy chasm i tried to hack my way through this, but i'm kinda stuck:
public class AbilitySystemConfig
{
[FixedList]
public List<DataComponent> components;
}
public class DataComponent
{
public float value;
}
[AttributeUsage(AttributeTargets.Field)]
public class FixedList : PropertyAttribute { }
[CustomPropertyDrawer(typeof(FixedList))]
public class FixedListDrawer : PropertyDrawer
{
private ReorderableList reorderableList;
private SerializedProperty myProperty;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
myProperty = property;
List<DataComponent> comps = new List<DataComponent>();
comps.Add(new DataComponent());
reorderableList = new ReorderableList(comps, typeof(DataComponent), false, false, false, false);
reorderableList.drawElementCallback += DrawElement;
reorderableList.DoLayoutList();
}
private void DrawElement(Rect rect, int index, bool active, bool focused)
{
EditorGUI.PropertyField(rect, myProperty.GetArrayElementAtIndex(index));
}
}
I dont even know how to get the real list from the property. I tried it like property.isArray, which returns false. If i do property.propertyType i get generic... no clue what to do
Sadly, unity does not support Property attributes on lists. The attribute will apply to the elements in the list.
Not the list itself.
so can you give me a hint what to do next? i'm totally clueless
Sure, you basically have two options. 1. Make a custom editor. 2. Create a wrapper class around your list so that you can either just make a property drawer for it, or so you can user attributes on it.
is a propertydrawer not a custom inspector?
A PropertyDrawer tells unity how to draw a field for a specific type, and are for c# types. While an Editor is for UnityEngne.Object types, and tells unity how to draw it in the inspector.
uhm okay, i just got more questions than before. Nvm dont think i can make it work
Is there a way I can rename these reference file paths in an editor script? It adds "1" since there's multiple characters in the scene in Blender (I assume), I would like to rename these so it isn't marked as missing
I did a bit of research, turns out it's called an "EditorCurveBinding", can I change this path through a script/editor script?
Could anyone follow up
I found this tool called "Animation Hierarchy Editor" but it doesn't work, it has a lot of stuff I don't understand, really, all I just want to do is rename this stuff through an editor script
I feel like I'm so close on this, I can get the editorcurvebinding and their property names, but I don't know how to change their path values, when I try, it doesn't change in the Animation window
Is there a SetCurveBindings?
AnimationUtility has most of the functions you could want https://docs.unity3d.com/ScriptReference/AnimationUtility.html
@serene spear
I don't know what SetCurveBindings is, I've been looking a bit in AnimationUtility is, not sure how to piece it all together though
you need to use GetEditorCurve and SetEditorCurve
SetCurveBindings doesn't exist?
So GetEditorCurve and SetEditorCurve, I'll look into them
If you are replying to what I said. There is a reason I put a question-mark at the end. Sorry it wasn't clearer.
Why "LayerMask" field too hard to add my custom ibspector I tried some methods but they dont work properly do you guys know any method about this
Are you using SerializedProperties?
If so then you can just do a PropertyField I think.
ye I am using SerialzedPropertie.valueInt but ıts not perfect for layers I guess idk
Why not use EditorGUILayout.PropertyField(layerMaskProperty);?
Do you need the actual value for other places in the editor?
I tought this just for enums
I will try thanks
What? EditorGUILayout.PropertyField(...) just draws the default field for the property. A text field for a string type property, a float field for a float type property, an enum field for an enum type property etc.
thanks for explanation
It uses the PropertyDrawer for the provided property if it has one.
I was using "EditorGUILayout.MaskField" but its very very hard to use
its takes tons of parametra
Btw, after a quick google search this Unity answers question came up. It could help you maybe https://answers.unity.com/questions/42996/how-to-create-layermask-field-in-a-custom-editorwi.html
when you switch to play mode every settings gone bcuz of UnityEditorInternal utlities I guess
Well you have to apply the changes and stuff or it won't save.
I was trying to find but U already told me methods so thanks
I advice only using SerializedProperty since it handles undo/redo, and supports prefab variants and stuff.
Is there a way I can make this scrollable, it doesn't show everything on the window at once, also, having all of these labels to show the editor curve bindings is really making Unity lag
Is this your window?
If lagging is the problem I would use UIToolkit instead of IMGUI, and use it's ListView. Or implement your own virtualized list view in IMGUI (not as scary as it sounds, though still not simple either).
there is a scroll view scope you can use for IMGUI
it will lag 😛
the UIToolkit version will probably be less laggy, the non-laggy IMGUI version takes a lot of code to use
The UIToolkit version won't be laggy at all. 😛
likely
I see ScrollView, just wishing I could make it way less laggier, it was lagging a lot in the Animation Window and was tedious to open expand arrays to rename more stuff
when you export from blender to unity and bones have same names, for example, "Root", it renames one to just "Root 1" and then it marks it as missing...
so then you have to manually rename stuff
The TreeView API is the non-laggy IMGUI version of this, but it's a pain in the ass to use https://docs.unity3d.com/Manual/TreeViewAPI.html
I would really recommend what MechWarrior suggests, UIToolkit is very straight forward
the example is even relevant looking https://docs.unity3d.com/ScriptReference/UIElements.ListView.html
other than the list they use, it's almost all what you want
is there a way to read / write to project user settings ?
Which part?
anywhere i can store data really ( relative to the current projects )
without making scriptable* objects
Not that I'm aware of
unity makes those files in user settings
somehow
ProjectSettings next to Assets
for example XRSettings.asset wasn't in unity5 afaik
and it pops up when u add the package
Yeah you can make those but they're just SOs
Can someone who's knowledgable with 2D collisions and rigidbody2D help me out? I'm trying to program hitboxes but sometimes collisions are not going through.
but they are not store in the assets folder , right ?
Yeah
I can explain more in DM.
sounds good to me
yes
any clues ?
There's SerializeFileAndForget in UnityEditorInternal somewhere
0 results on git
yeah it's not the exact name
If you ask me again tomorrow then I can check the exact name
Oh yeah scriptablesingleton is a thing as well
does it means it will be automatically created ?
I think so but I've never used it
Yep
ill try this , thanks
So fun fact for the day AssetDatabase.GetTypeFromPathAndFileID just return UnityEngine.MonoBehaviour for ScriptableObject assets making it basically useless... yay...
The thing is just straight up broken, it throws an error if the type is a C# file. 👌
Saying that it maybe corrupt or was serialized with a different version of unity.
Subassets are a joke.
Nice I should replace some of my code with that
now i just need to figure out how to listen to editor keyboard events without having the window opened
ill drop a foss link once this script is ready 👌
👍
hmmmm this one is marked Obsolete without any replacement links , any ideas ?
ah nvm found it : EditorSceneManager.OpenScene
When you create a new ListView, which argument controls how big the spacing between the items are?
Would it be itemHeight?
Nvm, it is, but now that's done, how would I be able to change the text contents?
With uss style sheets.
Or manually in C# with element.style.fontSize = 20;
where is that? I tried looking in listView, and just typing element
trying to load package via UPM but its complaining about SemVer ... ?
ah ... nvm Semantic Versioning needs 3 integers
All VisualElements have a .style property which you can use to set inline styles.
I've been trying to look up stuff related to ListView, there's only one video I can find, he doesn't explain anything though unfortunately, the rest of the results are stuff related to Unity's UI and vertical layout group
my package won't be included in the editor for some reason
its a single file , when i remove the package and place the file manually it does work , any ideas ? ( repo link above )
I can't seem to find .style, I copy pasted what was on the documentation and changed a few values @gloomy chasm
Well that would be because makeItem is a delegate, that makes VisualElements, it is not a VisualElement itself.
@serene spear
private VisualElement MakeItem()
{
var labelElement = new Label();
labelElement.style.fontSize = 25;
return labelElement
}
tried updating the version and adding the package as git url again , now its showing there errors ( shows as many errors as there are files in my repo )
ok... so after adding assembly def it seems to work , trying to figure out upm took me longer then it took me to write this editor window smh
I put in the VisualElemnt function, but now I don't know how to put that into a Func
A Func is a delegate, and that is basically either a single reference to a method or methods. So in this case you don't need the Func since you have the method that does the exact same thing. So you just replace the func that you pass as a parameter in to the ListView with the method that you just added.
If you are still not sure, I would recommend looking up C# delegates to learn more. There is a lot of great info on them! 🙂
it tells me that it cannot convert from a UnityEngine.UIElements.VisualElement to a System.Func<UnityEngine.UIElements.VisualElement>;
That is because you are trying to give the ListView a VisualElement when it wants a method/Func that takes 0 parameters and returns a VisualElement. I would really recommend trying to look up some more info about delegates.
yeah, delegates are still a bit foreign to me
I have no where to share this, and I want to because I think it is interesting.
Getting an asset path from a GUID is significantly faster than getting from an object directly.
Calling each method 10k times, on average GetAssetPath took 650 ms, while GUIDToAssetPath was around 75 ms.
Sick, just found out that AssetDatabase.FindAssets() can't find subassets. I'm really trying hard here to support Unity's own sub-assets system. But man does it feel like they really don't want you to mess with it at all...
I guess that make sense since only have one guid... Now I am going to dive in to the black abyss which is the Project Browser source code to see what they do... 😧
They handle it in external code of course... You know what this is too much, even QuickSearch doesn't support sub-assets.
been trying to look up func stuff for a couple of hours now, I don't understand now, I understand a little bit of the other delegate types, but Func is confusing me, it keeps giving me that error that it can't convert VisualElement to System.Func<VisualElement>
I want to just return the func, but also be able to edit the text content
ok well I just messed around and tried stupid stuff, I don't know why this works
Are there any good debugging extensions for Unity to help find out what is going on in spaghetti code?
How do I get a value in this listView so I can then change the text value of it?
a value of what? What thing in the list are you manipulating?
the items are all stored in itemsSource
here's a real world example of list view if it helps https://github.com/CoffeeVampir3/Graphify/blob/main/EditorOnly/Blackboard/NavigationBlackboard.cs
I think, I finally have everything working, but it lags just as bad as the Animation window, although it still is clearer to see, anything I can do to optimise that?
Here's the code I'm using, it's very short
it doesn't rename everything for some reason
Where is this code... is it maybe in the OnGUI method, and not in OnEnable?
Something to know about UIToolkit is that it is what is called a Retained Mode GUI. That basically means it does not update every frame like Immediate Mode
does GUI, GUILayout, etc. in unity are all Immediate Mode, meaning they update every frame, and so need to be put in the OnGUI method which is called every frame(ish).
Retained Mode(UIToolkit) only updates based on certain events. It is heavily event driven. So you only make the UI elements once in OnEnable.
UIToolkit controls have events you can register to.
In your case the most important one is RegisterOnValueChangedEvent. That is called every time the element's value changes.
So in your case you would want to register to that event when you bind an item, so you can do your checks and apply the new value to the source data.
I just randomly searched around on the forums for looking on how to fix this, turns out people have already done what I'm failing to do
Oh yeah? What's that?
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.
joao-cabral has already made it
Well nice for you!
there's like a lot of iterations of the same thing
I should at least study what they did
I got lucky here
is there a way to make the ObjectField filter only asset files ( prefabs ) ?
rn it will pop up with Scene Tab selected by default and the selection is still valid but not for my purposes
ah right
is there a way to check if preview scene is dirty or not ?
EditorSceneManager.GetActiveScene().isDirty seem to work for scenes but not opened prefabs
Hey there! I have an editor program for a conditional field (-> Show/Hide a field depending on other field's value), but doesn't works on arrays and lists. Any ideas of why?
so apparently this is not the same scene :
((Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage()?.scene ?? null) == EditorSceneManager.GetActiveScene()); // always false
but the preview scene stage gets saved automatically regardless
now i just need to figure out how to save none preview stage ( current active scene ) 🤔 ... ( trying : EditorSceneManager.SaveScene )
Not sure if this is the channel for this. I want to change all the compression type for a particular build type for all the images in my project. When I try to search using the t: tag, I realised that it gives the sprite not the meta object with the properties, is there a way to do this in a faster way, then select each sprite and setting property? I am open to writing code for it.
Need some advice...
I have a 'SequenceManager' which is a monobehaviour that just has a list of 'Sequence'. Sequence contains a List<IAction>, which is a polymorphic list. I am using a custom property drawer for Sequence to add an enum field that I am using to add a new value to the IAction list.
Code: https://pastebin.com/NQxwX8x1
The problem is, my property drawer is rendering all messed up inside the inspector array container, and the enum field I added is rendered after the array container, not as a sub element. Anyone got any resources on why this happens?
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.
Don't call base.OnGUI, reserve the height by overriding GetPropertyHeight and don't use GUILayout
Figured out why I hadn't used it before, it's only supported in 2020 and higher
ScriptableSingleton is still a thing before then but the FilePath attribute doesn't exist and thus making it a lot less useful
Or rather it's internal
Thanks for that Navi 🙂 Now just have to figure out why the relative property get is returning null...
Is there a confirmed issue of property drawers not being able to use FindPropertyRelative?
I'm more encline to think you did something wrong
I mean, yeh generally
I tried switching to UIElements and now its not even calling haha
This code is returning "No GUI Implemented", and no debug is called. Can you see an error?
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var container = new VisualElement();
var propField = new PropertyField(property.FindPropertyRelative("actions"));
Debug.Log("propfield: " + (propField == null));
container.Add(propField);
return container;
}
Are you also overriding OnGUI?
I am not. Do I need to if Im overriding CreatePropertyGUI?
I commented out my old code, so only this function is in the property drawer.
2021.1.7f
Does your class have a custom editor?
Nope, just the property drawer
🤔
right?
gonna try chucking a debug just before the prop field get just in case its failing
UIElements only work in PropertyDrawer if the drawer is called from an editor that used UIElements sadly.
ah, that explains that then!
Just the prop field issue to go and I've got this haha
But it should be called from UITK if it's 2021 and they don't have a custom editor
Why would it?
Because Unity has been replacing all editors with UITK
Did they move default to UIToolkit?
I'm not sure but I think I heard that it should work by default in either 2019 or 2020
Nope, just checked and the default drawer still uses IMGUI.
Final one, can anyone see any obvious errors in this? Im running at so much of a loss rn
[CustomPropertyDrawer(typeof(Sequence))]
public class SequenceDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
SerializedProperty prop = property.FindPropertyRelative("actions");
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width - 30, position.height), prop);
var type = (Sequence.ActionType)EditorGUILayout.EnumPopup("Create Sequence: ", Sequence.ActionType.SelectType);
if (type != Sequence.ActionType.SelectType)
{
switch (type)
{
case Sequence.ActionType.SelectType:
break;
case Sequence.ActionType.Debug:
SerializedProperty newAction = prop.GetArrayElementAtIndex(prop.arraySize++);
newAction.managedReferenceValue = new DebugAction();
break;
case Sequence.ActionType.MoveTransform:
break;
}
}
EditorGUI.EndProperty();
}
}
[Serializable]
public class Sequence
{
public enum ActionType
{
SelectType,
Debug,
MoveTransform
}
public bool running;
[SerializeField] private List<IAction> actions = new List<IAction>();
}
What's IAction?
It needs to have the [SerializeReference] attribute or unity will not serialize it
The IAction list I mean.
So, make it public and add SerializeReference?
Just SerializeReference should be enough
IAction is an interface, its a polymorphic list
There you go, use SerializeReference
I had it working with default UI, i just wanted to add a bloody button haha
just to check the placement, this is what you meant?
[SerializeReference] public List<IAction> actions = new List<IAction>();
It can still be private, but yes.
You can make it private if you want
eh, either way works for me
In your code, you are using EditorGUILayout for your enumpopup.
It draws! It draws wrong but it draws!
That would be the draw wrong part i think haha
Tryna make that render inside the list
You shouldn't use the "...Layout" classes in property drawers
Im not sure what term to google here...
Im trying to increase the size of the space alloted to the item in the list?
There are two weird things going on. First, the enum field is being drawn outside of the list area, second when I expand the actions property, no sub elements are being drawn. Do I need to do that? I thought the PropertyField would cover it.
Current view attached, minimised and maximised.
The actions list is making space for the sub elements, as its property height grows when I use the enum to add an action to it. Just cant see the action...
Override GetPropertyHeight
You sent this just as I found an answer saying the same haha
Thank you
Ah, worked!
Except for the invisible subcontent 😠 Its never easy is it
ah, include children !!
You see, not too hardcore 🙂
I would ... LOVE to agree with you Mikilo haha.
But when I expand a child of one of the action lists, all the other sequence elements turn invisible haha.
So thats what im tackling now 😛
Show code
Righto, heres the editor code:
namespace DI_Sequences
{
[CustomPropertyDrawer(typeof(Sequence))]
public class SequenceDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
SerializedProperty prop = property.FindPropertyRelative("actions");
float propHeight = EditorGUI.GetPropertyHeight(prop);
Rect propRect = new Rect(position.x, position.y, position.width, propHeight);
Rect enumRect = new Rect(position.x, position.y + propHeight + EditorGUIUtility.standardVerticalSpacing, position.width, 50);
EditorGUI.PropertyField(propRect, prop, true);
var type = (Sequence.ActionType)EditorGUI.EnumPopup(enumRect, "Create Sequence: ", Sequence.ActionType.SelectType);
if (type != Sequence.ActionType.SelectType)
{
switch (type)
{
case Sequence.ActionType.SelectType:
break;
case Sequence.ActionType.Debug:
SerializedProperty newAction = prop.GetArrayElementAtIndex(prop.arraySize++);
newAction.managedReferenceValue = new DebugAction();
break;
case Sequence.ActionType.MoveTransform:
break;
}
}
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
SerializedProperty prop = property.FindPropertyRelative("actions");
return EditorGUI.GetPropertyHeight(prop) + EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.singleLineHeight * 2;
}
}
}
And heres the data structures
[Serializable]
public class Sequence
{
public enum ActionType
{
SelectType,
Debug,
MoveTransform
}
public bool running;
[SerializeReference] public List<IAction> actions = new List<IAction>();
}
public interface IAction
{
void Begin();
void Complete();
}
[Serializable]
public class DebugAction : IAction
{
[HideInInspector]
public string name;
public bool running;
public string message;
public DebugAction()
{
name = "Debug Action";
}
public void Begin()
{
throw new NotImplementedException();
}
public void Complete()
{
throw new NotImplementedException();
}
}
Hmm, it looks okay
Im wondering if I should be changing anything with prop.isExpanded, but i'll probably only end up using that to hide the enum popup inside
remember you use it in 2 spots
Yep, changed in both.
I feel like the property height is correct now, as the highlighting for the portion seems accurate.
For example. on this shot, you can see where the element finished, one line space under the enum field
Okay, im making no headway. Gonna call it a night.
One more giant thanks for all the help tendered tonight
Hello guys, I am trying to loop thru prefabs and call function from script that inherits from editor. Is there any way I can do this?
I need some help with Unity Editor Window, I am trying to create a ScriptableObject through a tool extension, This is the current code cs public void CreateItem(string Name, int Damage, int Durabillity, ItemRank rank) { Item item = ScriptableObject.CreateInstance(typeof(Item)) as Item; item.ItemRank = rank; item.Name = Name; item.name = Name; item.ItemDamage = Damage; item.ItemDurability = Durabillity; AssetDatabase.CreateAsset(item, "Assets/Preset/Items"); }
public class ItemEditor : EditorWindow
{
string Name;
int Damage;
int Durabillity;
ItemRank Rank;
public static void ShowWindowStats()
{
var window = GetWindow<ItemEditor>();
window.titleContent = new GUIContent("ItemManager");
window.Show();
}
public void CreateItem(string Name, int Damage, int Durabillity, ItemRank rank)
{
Item item = ScriptableObject.CreateInstance(typeof(Item)) as Item;
item.ItemRank = rank;
item.Name = Name;
item.name = Name;
item.ItemDamage = Damage;
item.ItemDurability = Durabillity;
AssetDatabase.CreateAsset(item, "Assets/Preset/Items");
}
void OnGUI()
{
GUILayout.Label("Create your item here and quickly put it into the game!");
GUILayout.Space(2);
Name = GUILayout.TextField(Name);
GUILayout.Label("Item Damage");
Damage = EditorGUILayout.IntField(Damage);
GUILayout.Label("Item Durabillity");
Durabillity = EditorGUILayout.IntField(Durabillity);
Rank = (ItemRank)EditorGUILayout.ObjectField("Rank", Rank, typeof(ItemRank), false);
GUILayout.Space(4);
if (GUILayout.Button("Create New Item"))
{
CreateItem(Name, Damage, Durabillity, Rank);
}
}
}```
Whole Code
Fixed it, the problem was AssetDatabase.CreateAsset(item, "Assets/Preset/Items"); wasn't set to a Format
So if became a Default asset
it was supposed to be .asset in the end ;-;
is it possible to make an editor script that is a typeof all scripts?
nvm, finally found the right phrase to type in google
Try doing [CustomEditor(typeof(Object), true)]. Though I am not sure the results.
@gloomy chasm slow response, but that works! What exactly is the true doing as an overload?
okay, apparently that true makes it always active, but pretty cool!
[CustomEditor(typeof(Object), true)]
[CanEditMultipleObjects]
public class DefaultCustomInspector : Editor
{
string testText;
public override void OnInspectorGUI()
{
testText = Selection.activeObject.name;
EditorGUILayout.LabelField("~~~~~CUSTOM INSPECTOR~~~~~");
testText = EditorGUILayout.TextField(testText);
EditorGUILayout.LabelField("~~~~~CUSTOM INSPECTOR~~~~~");
DrawDefaultInspector();
}
}
for example giving me something like
I noticed though that this customeditor doesn't work on audio clips and animation clips. I thought the base type of everything was Object though?
the more specific editor will always take precedence afaik
okay, I'll try to look more into that. Is there an override for that? Not really important, but, now I'm curious
only if you override them specifically
okay, ty, looking into that now! See what I can find
found a need to cast audioclip as an object
Is anyone aware of any attributes for inspector values that would trim strings?
I wrote one, TrimTextAttribute, but it breaks TextAreaAttribute
I could write TrimTextArea and TrimMultiLine...
Can't... TrimTextAttribute is sealed.
Anyone know of a solution?
you could make a TrimTextAreaAttribute that was also a TextArea
sadly Unity doesn't allow multiple property drawers
I can't inherit from TextAreaAttribute if that's what you're suggesting 😦
You would have to reimplement it
Hey, I've been experimenting with 3d renderers from scratch for the past few days like Raymarcher and raytracers
I'd like to move my Raymarching code to Unity but I want it to run directly in the editor
Meaning I can move around the SceneView's camera to see the objects
In order to do that I need my compute shader to override the image generated by the SceneView camera basically
I found a way on this forum that worked
It involves copying the renderer component from another Camera to the SceneView
But i'd rather directly add components to the SceneView camera. Anyone know a way to do that?
By scenecamera I mean this object
I can get it to work in edit mode by using [ExecuteInEditMode] too
but still, directly adding the components would be better
Because I can also edit the parameters of the script without having to refresh
I am using AssetDatabase.CopyAsset and AssetDatabase.LoadAssetAtPath for generating animation controller using a template animation controller. Is it normal that the scene takes a while now until it starts (there is a loading icon now, when I start)? Can I reduce the loading time?
Profile it
Hey there! I have a custom attribute script (->that Shows/Hides a field depending on other field's value), but doesn't works on arrays and lists. Any ideas of why?
What scripts should i send to get some help?
The attribute is applied to the elements and not the whole list
here is the script itself, i wasn't the one who made it, that's the principal reason i need help lol, because im lost
update: gave my actual script up and searching for a new one to implement. Found that one: https://github.com/Deadcows/MyBox/blob/master/Attributes/ConditionalFieldAttribute.cs
But don't really know how to implement it
oh
do i need to import all tools?
AnimatorController controller = new AnimatorController();
controller.name = $"{_attachToPrefab.name}_movement";
AnimatorControllerLayer layer = new AnimatorControllerLayer();
layer.name = "Base Layer";
controller.AddLayer(layer);
// Create movement tree
BlendTree tree = new BlendTree();
tree.name = "Movement Tree";
tree.AddChild(_moveUp, new Vector2(0, 1));
tree.AddChild(_moveRight, new Vector2(.9f, 0));
tree.AddChild(_moveDown, new Vector2(0, -1));
tree.AddChild(_moveLeft, new Vector2(-.9f, 0));
controller.AddMotion(tree); // Exception
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Animations.AnimatorController.AddMotion (UnityEngine.Motion motion, System.Int32 layerIndex) (at <c77ced6644e541b7ad3d7315a5e92a0a>:0)
UnityEditor.Animations.AnimatorController.AddMotion (UnityEngine.Motion motion) (at <c77ced6644e541b7ad3d7315a5e92a0a>:0)
Why does AddMotion throws aNullReferenceException?
Idk, see if there's anything useful in the reference source
Maybe something on your tree is uninitialized
Did you mean docs? I can't find anything useful there :/
No reference source
Oh thanks, I did not know that
I found the problem 😄
Hey, I've been experimenting with 3d renderers from scratch for the past few days like Raymarcher and raytracers
I'd like to move my Raymarching code to Unity but I want it to run directly in the editor
Meaning I can move around the SceneView's camera to see the objects
In order to do that I need my compute shader to override the image generated by the SceneView camera basically
I found a way on this forum that worked
https://forum.unity.com/threads/image-effect-in-scene-editor-views.102515/
It involves copying the renderer component from another Camera to the SceneView
But i'd rather directly add components to the SceneView camera. Anyone know a way to do that?
By scenecamera I mean this object
I can get it to work in edit mode by using [ExecuteInEditMode] too
but still, directly adding the components would be better
Because I can also edit the parameters of the script without having to refresh
Reposted cause orgiinal got buried
Not sure that's possible, you can try getting the scene view camera and just calling addcomponent
I did
check the csharp extension and inside that omnisharp directory %USERPROFILE%.vscode\extensions\
Thats the method I did and it kinda sucks but its alright
Alright
Now?
so its installed
now go to down and find setting.json , and open it
path is wrong
Ohh
C:\Users\Krampus' Secretary.vscode\extensions\ms-dotnettools.csharp-1.23.12.omnisharp\1.37.10\OmniSharp.exe?
B R U H
Everything else worked
THANK YOU SO MUCH BUT
The csproj problem is still there for some reason
restart the vscode
"omnisharp.useGlobalMono": "always",```
add this in settings.json
not needed
😢
Ahhh god
okay i think we should leave it on vsc
Yeah
I think ill just reinstall later
Thank you so so much for the help
and taking the time to give solutions
Hope I can fix tis oon
I'm trying to make a special scriptable object that I can use as a pointer to a specific Resources folder to help me load resources without hardcoded strings. So right now it literally just stores a string for the asset's current directory, but once I have that working I can reliably use it as a variable, shareable path for loading resources.
[CreateAssetMenu(menuName = "Resource Group")]
public class ResourceGroup : ScriptableObject
{
[SerializeField]
private string resourcesDirectory = null;
public string ResourcesDirectory
{
get => resourcesDirectory;
internal set => resourcesDirectory = value;
}
}
The big challenge is making sure the asset always knows its directory within the Resources folder. To do this, I've created an editor-only class that derives from AssetsModifiedProcessor which sends me the paths of any assets that are created, changed or moved.
Should be straightforward implementation: when file is created or moved, overwrite its resourcesDirectory string with the correct value.
The problem I'm running into is that I need to load the scriptable object to be able to update it. This is normally fine, I just call AssetDatabase.LoadAssetAtPath, however when the scriptable object is moved and I try to load it from the destination path, it often returns as null. I tried loading the scriptable object at the destination and source path but if one fails, so does the other.
I guess sometimes the asset exists in some sort of limbo until I return from the OnAssetsModified callback and Unity finishes the move? It's weird. Sometimes it works, sometimes it doesn't - and I can't find any rhyme or reason.
Does it seem like I'm goin about this the right way, or is this idea sketchy? 😅
src if it helps: https://hastebin.com/noqihugoqo.csharp
Another thing that feels weird about this approach is that I get the callback for every asset. Can't seem to tell unity to only send events for my specific scriptable object. This means whenever any asset is created or moved, I have to load it to check if it's a ResourceGroup
@wispy delta So the ResourceDirectory, is that a path to a folder or a game asset?
And it isn't clear, is that path relative to the resources folder? Or is it a path to a specific resources folder itself?
@gloomy chasm
The path is relative to the Resources folder and is just to the directory that contains the ResourceGroup asset. So the idea is that the string should be usable directly with Resources.LoadAll and other similar methods
Resources.LoadAll<Sprite>(someResourceGroup.ResourcesDirectory);
I'll likely add my own load methods to the resource group so you can do:
someResourceGroup.LoadAll<Sprite>()
I see, why not just assign it when you enter playmode or the like?
idk, on the off chance I use it in edit mode I guess. just trying to make sure the directory is always correct if possible 😄
Would AssetPostprocessor.OnPostProcessAllAssets not work?
yea that's the callback I'm using, but AssetDatabase.LoadAssetAtPath is returning null on the movedAssets paths
I thought you said you used the AssetsModifiedProcessor? Or did you try both?
Could brute force it and set the path everytime it is deserialized 😛
But AssetPostprocessor.OnPostProcessAllAssets should work...
Hmm ok I wasn't aware of AssetPostprocessor, I was using AssetsModifiedProcessor.
They seem to be very similar classes with similar callbacks
AssetsModifiedProcessor.OnAssetsModified(string[] changedAssets, string[] addedAssets, string[] deletedAssets, AssetMoveInfo[] movedAssets)
vs
AssetPostprocessor.OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
I was a bit confused. However after switching to using AssetPostprocessor it seems to work?!
I guess OnPostprocessAllAssets is called after the movement so I can load the asset fine 🤷♂️
Yeah.. there are like 4 or 5 different callbacks for when assets are/have moved/changed...
Yup, exactly. 👌
thank you for your help, glad to get this workin!
Does there happen to be a good way to get the index of an item in a UITK ListView from a mouse position...?
Right now I am looking at using reflection to get the recycle items pool, so I can check which element contains the mouse and then return the index stored in the recycle item...
I am getting this error . Why I cant assign from custom inspector its says you should assign this from original script inspector
#🎥┃cinemachine would be a more appropriate channel where you are more likely to get more/better help. This channel is for discussion around making extensions to the editor (new editor windows, custom inspectors, etc.). Not for general editor related help. 🙂
but its not about cinemachine its doesnt work for any object type its soo its isnt related about cinemachine its dosent work typeof(Camera) or typeof(Gameobject)
Alright, going to need more context for sure then.
Will need to see the code and more details about what you are trying to do and what is not working.
As an example I have this 3 lines of code and and these are for assignment for object types right
but I cant assign from editor script I must write base.OnIspectorGUI and assign from base inspector
Are you calling serializedObject.ApplyModifiedProperties() at the end of the OnInspectorGUI method?
yep
but I cant assign from editor script
What do you mean by this? What happens?
I assume you check that you assigned it right...?
I just figured out but I am embarrassed for that
in base script all variables are "GameObject" but in editor script they has different types
bcuz of that I guess
thanks 😄
Glad you got it worked out!
soo can I ask something
what is difference between "typeof(Object)" and "typeof(GameObject)"
typeof(Object) can have anything that inherits from Object, which is any asset, Component, or GameObject. While typeof(GameObject) is only GameObjects.
oh thanks
How can I give focus to a custom IMGUI control that doesn't use any builtin controls?
I've gotten quite far with my scrolling orbit plugin/script, but there's one issue. I can't figure out how to cancel out Unity's default handling of zoom. e.g, even though I have my vertical orbiting bound to vertical scrolling, it still zooms in and out.
Is there any way to just, block Unity from seeing that scrolling?
I'm trying to store the sceneview camera position & rotation, ```cs
//Store
var cam = SceneView.lastActiveSceneView.camera;
Pos = cam.transform.position;
Rot = cam.transform.rotation;
Piv = SceneView.lastActiveSceneView.pivot;
//Restore
cam.transform.position = Pos;
cam.transform.rotation = Rot;
SceneView.lastActiveSceneView.pivot = Piv;
SceneView.lastActiveSceneView.Repaint();
nvm, i sorted it.
Use the event? Event.current.Use().
IIRC there's a special method to set the sceneview camera pos
This worked for me cs class PositionData { public Vector3 Position; public Quaternion Rotation; } void StoreCamera() { var scene = SceneView.lastActiveSceneView; Pos = new PositionData(scene.pivot, scene.rotation); } void RestoreCamera() { var scene = SceneView.lastActiveSceneView; scene.pivot = Pos.Position; scene.rotation = Pos.Rotation; scene.Repaint(); }
it seems that SceneView.lastActiveSceneView.camera .position & .rotation don't do anything to the scene view camera at all
I'm going to re-ask my question from earlier if thats okay.
I have a IMGUI GridView and I want to be able to give focus to the items in it, and also have them lose focus when another control or window is focused. Any ideas how to do this?
hotcontrol?
I tried, but it doesn't seem to change when selecting other windows.
How did you try?
I think that a great place to start with custom control development is to re-create the GUI.Button and GUILayout.Button controls since these are straightforward to create and helps to establish some of the fundamentals of custom control development. Our custom button implementation will be used in the exact same way as the regular button controls:
Look at the code in those examples
Or this https://blog.unity.com/technology/going-deep-with-imgui-and-editor-customization by the lovely Richard Fine
@waxen sandal Thanks for the links, I am still reading them. But it seems like hotControl is not indented for this. I want to give focus to a control, while hotControl seems to be about capturing mouse input. Maybe I'm wrong?
More like mouse focus as I understand
There's also keyboardControl which is the same as hotControl but with keyboard focus
Maybe I'm misunderstanding what you're trying to do
Basically just trying to replicate the feature of things like the Hierarchy window treeview, where if you select a Gameobject the background is blue, and then if you select/focus anything else it go grey instead.
That's controlled by selection and not really something in imgui
I am only talking about the styling.
I think I got it to work, or at least know how to. I also took a look at the source code for the TreeView and they check to see if the window is focused. So I guess I will have to start passing a reference to the editor window around. Thank you for the help and the links! I have a better understand of it now!
EditorGUIUtility.HasCurrentWindowKeyFocus() why would they make such a useful thing internal...
So... it seems like you can't set Selection in OnEnable because it will not set if you are reloading scripts or entering play mode... Any good workarounds for this?
Sorry, I haven't been in like all day, I'll take a look at that!
How would I apply it in such a context?
would I apply it before I return the current delta?
like so?
Oh derp, that works flawlessly, sorry!
One of these days I'm going to write a hack to turn on toggleOnLabelClick by default for foldouts ._.
you mean like https://docs.unity3d.com/ScriptReference/SerializedProperty-isExpanded.html
I was just looking into doing this and google was full of posts which had some convoluted way of doing it.
Until I found one post which highlighted this, meaning it is saved with the serialized property making it so much simpler!
I think they want an attribute that automatically creates a foldout around a group of properties
how do i build with ar core please help
I'm trying to create a custom editor with graph view and struggling to figure out how to hook into when a edge is disconnected from a port. IEdgeConnectorListener.OnDropOutsidePort doesn't get called for a EdgeConnector manipulator on the port (which, I suppose, make sense). The only way I can think to do it is to subclass Port, which has it's own set of complications. Is there another way that I'm missing?
i'm making a custom editor, and i have problem with scroll view
how come it doesn't set automatically ?
Graph View (the class) has a callback when certain things on the graph change, edges are one of them:
private GraphViewChange OnGraphViewChanged(GraphViewChange changes)
{
if (changes.movedElements != null)
{
ProcessElementMoves(ref changes.movedElements);
}
//Checks for changes related to our nodes.
if (changes.elementsToRemove != null)
{
ProcessElementRemovals(ref changes.elementsToRemove);
}
if (changes.edgesToCreate == null)
return changes;
ProcessEdgesToCreate(ref changes.edgesToCreate);
//...etc
}
You register the callback with
(GraphView).graphViewChanged = OnGraphViewChanged;
I have a full graph view implementation here https://github.com/CoffeeVampir3/Graphify/blob/main/EditorOnly/BaseGraph/GraphifyView.cs
thanks!
I'm working on an a tool for making collections of assets. I have been trying to figure out styling for the cells, and I tried generating custom thumbnails for assets 'without' a background.
Is this a bad idea? It doesn't exactly match with default styling, but I also think it looks pretty nice.
Lgtm
Think it still looks okay in the light theme?
Looks a bit weird but fine tbh
I guess which is better looking? That or normal previews?
The first ones
They look slightly funny in the white theme because they're close in color
Yeah, I can mess with the lighting in the previews to make them a bit darker.
Cool I think I will go with them them. I wish their was a way to render a preview with just no background, but best I can find is just setting the color to be the same as the windows background color.
Also need to figure out how to properly cache the images and delay the generation so it doesn't lag.
Unity did some work with previews in one of the newer versions so they might've improved the api
Really? All I can find is the PreviewRenderUtility. Which works fine, just kind of cumbersome to work with. No way to automatic caching or anything.
I'm using GUIContent to display some textures as buttons on my editorWindow, how can i set the background colour of the texture to transparent?
I'd like the white background to be transparent
Is that just the normal button style?
For reference, here's my code: ```cs
loadProject = Resources.Load<Texture2D>("Icons/Load");
loadButton = new GUIContent(loadProject, "Load Project");
buttonStyle = new GUIStyle(GUI.skin.button);
if (GUILayout.Button(loadButton , ButtonStyle, GUILayout.Width(40)))
{
DoSomething();
}```
I'm copying the button style from GUI.sking.button
Just use a different style? Like the EditorStyles.label?
@gloomy chasmthat works great, thank you
the issue I'm finding now, is that I want it to behave as a button, but it behaves as a label
This does nothing. I'm just using a coloured image for PressedButton.pngcs var bg = Resources.Load<Texture2D>("Icons/PressedButton"); menuButtonStyle = new GUIStyle(GUI.skin.label); menuButtonStyle.background = bg;
in a lot of my editor scripts I include AssetDatabase.SaveAssets(); followed with AssetDatabase.Refresh() follow with a Repaint(). I feel like this is excessive and creating extra unnecessary load(Is that the right word?) in my Editor Windows. So I'm asking if anyone has a better explanation of using this 3? For example, if I use AssetDatabase.CreateAsset() do I need to include saveassets or can I just go straight to refresh?
I hit this problem, I can't click on any objects and the hierarchy and the inspector are gone.
How to fix this
Try clicking to reset layout in the top right corner
thanks
Is there a way to dock non utility editor windows to a utility editorwindow?
I don't think that windows can be docked to Utility windows, but you can try this https://gist.github.com/Jayatubi/f6cafb4d5a5fcb54b537e79be77aa714
Thanks for that. Not exactly what I'm looking for! But instead I think I found a different route to go. I'll have my main window as utility still and I think use EditorWindow.BeginWindows and EditorWindow.EndWindows to position other windows in exactly locations in such a way that they don't necessarily look like other windows
I guess, better yet, have 1 main window that copies the dimensions and stuff of the utility window, but, I can dock things to
so that I'll still get the always on top
can we change the x value in which a editorGUILayout.BeginHorizontal() begins ?
I'm curious if there are any examples out there of using GraphViewEditorWindow and GraphViewEditorWindow.ShowGraphViewWindowWithTools - I seem to be missing something.