#↕️┃editor-extensions
1 messages · Page 73 of 1
Like I said, for making a pins bar. Like the bar on the bottom ("Error List", "Output") and the left ("Toolbox").
Could do ones on the left and right without too much trouble, but doing one on the bottom with a header would make it pretty bulky.
Am I missing something obvious? Extending Editor has UI elements support but EditorWindow does not
there's none of the UITK callbacks you need
in the Editor Window you just add to the rootVisualElement
In OnEnable
PSA: Don't remove the sibling of rootVisualElement or your computer may very well bluescreen, lol.
Really? That sounds like a very mean bug
lol
@visual stag Yeah, the rootVisualElement I can add to but there's no callbacks supported like the editor has.
public override VisualElement CreateInspectorGUI()
{
return base.CreateInspectorGUI();
}
Editor window is missing these
Yeah, it's not great. I mean I didn't test it again, but the project was empty so I think it should happen every time. I reported it with the suggestion that it close the editor window or simply not be able to be removed.
@civic river
private void OnEnable()
{
rootVisualElement.Add(new Label("My Label"));
}
rootVisualElement is a property of EditorWindow
OnEnable has race conditions with initialziation
It can be any where, the important part is rootVisualElement
You can add/remove stuff from it at any time.
there's no way to know when it's safe to add/remove stuff though
it doesn't give a callback when it's done constructing
like the editor does
I am confused, I don't have any race conditions
What exactly are you having trouble with?
If I do something like this
private void GenerateMiniMap()
{
var miniMap = new MiniMap{anchored = true};
var spawnCoord = graphView.contentViewContainer.WorldToLocal(
new Vector2( graphView.contentViewContainer.layout.width - 20, 45));
Debug.Log(spawnCoord.x);
miniMap.SetPosition(new Rect(spawnCoord.x, spawnCoord.y, 200, 140));
graphView.Add(miniMap);
}
graphView.contentViewContainer.layout.width isin't constructed yet OnEnable
so you have to just guess when it's created
graphView.schedule.Execute(ConstructGUIAfterRepaint).StartingIn(100);
When are you calling the method?
OnEnable
I mean after or before your graphView stuff? And is it a different window?
this is OnEnable for the editor window
how do i use this code for my game? <iframe width="560" height="315" src="https://musiclab.chromeexperiments.com/Song-Maker/embed/6329166260600832" frameborder="0" allowfullscreen></iframe>
@civic river Is GenerateMiniMap() being called in the same script that you are constructing your graphview?
private void OnEnable()
{
graphView = new BaseGraphView
{
name = "Coffee Behaviour Graph"
};
graphView.StretchToParentSize();
rootVisualElement.Add(graphView);
graphView.schedule.Execute(ConstructGUIAfterRepaint).StartingIn(100);
}
So where is GenerateMiniMap being called in relation to that code?
it's in the execute call
private void ConstructGUIAfterRepaint()
{
GenerateToolbar();
GenerateMiniMap();
GenerateBlackboard();
}
You should be able to call it directly there, with no need for the schedule execute
You mean graphView.contentViewContainer.layout.width is Nan?
Would not going so deep work? (I don't remember the API for it so I honestly don't know)
nothing gets initialized until the next frame I stepped through with the debugger
and maxSize is some rediculous nonsense value for some reason on the editor window
I am about to go to bed, so I can't look through it right now. But I would say if you haven't already look at the shader graph, or vfx code to see how they do it.
are those open source?
Yeah, it has been great. Warning though, as far as I can tell, a lot of the shader graph code was written while the graph API was still new, so things have changed and it does some things it self that the graph api does now. Also the vfx graph and shader graph implement things really differently.
I find the shader graph easier to read and follow in general, bit less complex.
it looks like they just rig an event to it
graphView.RegisterCallback<AttachToPanelEvent>(OnEnterPanel);
seems simple enough
is it possible to just receive 1 mousemove event per frame in UI Elements (in an inspector?)
i'm receiving lots of them.. I just want the last one
i'm using these callbacks to add the event (added in a VisualElement constructor after loading the container from UXML):
shapeContainer = root.Q<IMGUIContainer>(name = "ShapeContainer");
shapeContainer.onGUIHandler += OnGUI;
shapeContainer.RegisterCallback<MouseDownEvent>(HandleMouseDown);
shapeContainer.RegisterCallback<MouseMoveEvent>(HandleMouseMove);
shapeContainer.RegisterCallback<MouseUpEvent>(HandleMouseUp);```
each event also calls my OnGUI for the IMGUIContainer function at least twice, resulting in it being run up to 100 times each frame
ah calling event.StopPropagation() seems to have fixed it
hey guys, How do I show a field to drop an enum class into?
What?
From what I understood this person wants to create a field in a custom editor/inspector window. This field should accept enum files...
What is an enum file? What are not in Unreal X)
It's a file that contains an enum I assume
Doesn't sound too weird too me. Such an input does sound weird to me though
I created a script that just has this: public enum Direction{X = 0,Y = 1,Z = 2}
You need to read about DragAndDrop
And I want to be able to allow only the enum scripts to be used...
Mikilo you were right
The list lost his reference because i was drawing it every frame
100%
Anyone have some insight how I can solve some UI elements issues. The alignment of my first element seems to be ignored(?) I don't really know what's going on here. And when there's too many elements trying to expand it just dies horribly
@civic river For the too many elements expanding thing, I think you need to look at your styling on the parent of those elements. Not sure what is going on with the rest of it.
Have you tried looking at it with the UI Toolkit debugger window?
yeah I didin't find anything that looked compelling
there's some sort of hidden margin on the first element that isint inherited but I can't seem to find out what it is
can you explain a bit about the styling thing?
I don't really understand the style sheets at all
If I create an empty foldout the alignment is fine... I just don't get it
I've done it, I have gone too deep. I broke unity (the project loads like this and it is not possible to open windows)
If the whole UI is not responding, go there:
C:\Users\{USER}\AppData\Roaming\Unity\Editor-5.x\Preferences\Layouts
and remove the LastLayout.dwlt
Cool, but yeah, it works. What I had done was remove the Toolbar, but it seems it removed the dock view as well for some reason. I mean, it had totally broke the editor when I removed the toolbar so I had to close and reopen the editor to get it to look like that.
Because a lot of things are linked intrinsically, and they don't expect to be null
Well, yeah.
And when you closed Unity Editor, obviously they saved the layout
Don't remove Unity stuff, hide them.
0 height, 0 width, or stuff like that
I am not surprised. I am mostly just playing around seeing what can be done. Sadly that doesn't work for the toolbar, and when adding ui elements to it, if they have rounded corners they seem to just be all white for some reason.
At least if they are a child of the rootVisualElement.
Are you using the root or the IMGUIContainer?
Ah, I'm using VisualElement controls, I bet that is why.
Hey guys, anyone know how I can get the actual Rect position of a button and not it's relative position?
GetLastRect does not give me the actual position within the EditorWindow...
Sorry but this is not #↕️┃editor-extensions
Having trouble where changing Text Mesh Pro text options, like color, etc is effecting all Text Mesh Pro elements in the UI. What caused them all to be linked together?
Sorry but this is not #↕️┃editor-extensions
Oh i thought extensions means not built in features
This channel is specific for extending Unity Editor
I am not sure I know the word extension. Like in for Google Chrome, and Edge, it means a feature provided by an outside programmer
This channel's description targets very specifically Editor and things you could write to extend.
Yes, kinda
"Outside" is optionnal, but it's really just about extending your Unity Editor
oh its for creating new extensions, not using existing ones, I see
Yep
got it!
Good luck
I'm having a hard time finding out how to/if there is a way to create a prefab from an existing prefab, then modify that independently without adding it to a scene. Is there a way to do this? All of the PrefabUtility stuff seems to require adding it to a scene before modifying it.
PrefabUtility.LoadPrefabContents seems like it might be relevant but is a bit confusing, as it still loads the prefab into an "isolated scene":
https://docs.unity3d.com/ScriptReference/PrefabUtility.LoadPrefabContents.html
Anyone know how to save the ScriptableObject tied to an inspector? Created / drawing with CurrentInspector = Editor.CreateEditor(Current);
Then trying to save it by marking Current as dirty, and calling SaveAssets / Refresh on the AssetDatabase, but not working.
@marble oriole modifiying a scriptableObject instance in project through a serializedObject seems to save the values.
Used it in a settings provider
@stray hemlock yeah not sure what was going on, kept working in the area and it seems to be working fine now?
Lol cool
Can anyone suggest a way to undo data local to an editor window.
By that I mean some field used only in editor window
Using UI Toolkit if u wanted to know that
Change the icon when the asset is being created.
Hi guys I'm looking to create a custom slider inside a PropertyDrawer.
I want to get rid of the value display at the end which comes as standard when using EditorGUI.Slider.
Any ideas how to only show the slider component?
Tag me if you reply 🙂 cheers
EditorGUI.Slider? @frozen cove
Yeah, that's what I'm using and I get the result above,
Green = my other fields
Orange = EgidorGUI.Slider
I see thx
This is my aspiration:
ok...
I think it is trigger at width > 55 + EditorGUIUtility.fieldWidth
I set it to 90, previously it was flexible
If you want to know, the code executed is this one EditorGUI.DoSlider(Rect position, Rect dragZonePosition, int id, float value, float sliderMin, float sliderMax, string formatString, float textFieldMin, float textFieldMax, float power, GUIStyle textfieldStyle, GUIStyle sliderStyle, GUIStyle thumbStyle, Texture2D sliderBackground, GUIStyle thumbStyleExtent)
yeah I'd pulled the source code and it half scared me to death
creating it from a texture2D etc 😳
I'm hoping to not have to take that route.
I think I have not much hope for hiding this one
It doesn't have options to hide it
Have you tried GUI.Slider?
yeah it's a tricky one..
I just tried drawing the other field over the top of the slider field part, visually it looks correct, however the click input is now trying to access the slider, not my float
I havent.. will take a look now
Hey guys, anyone know of a way to get all the indexes of a unityevent?
What is an index in there?
these? @mild reef
@onyx harness Legend!
target.range = GUI.HorizontalSlider(rangeRect, target.range, target.min, target.max);
@frozen cove Yes...
I want to get the those indexes...
@onyx harness That doesn't give me access to the indexes?
Sorry but indexes mean nothing to me
On your UnityEvent you have GetPersistentEventCount()
This will give you the total, but what then?
beat me too it :)
UnityEvent.GetPersistentEventCount();
than access index with UnityEvent.GetPersistentTarget(0). ...
@mild reef ^
Thanks guys...I needed it to see if I can adjust the layout between gui depending on how many in the unityevent box so it doesnt overlap other gui...
Lol, this is very far from needing the indexes
Getting the height of a UnityEvent is more appropriate
Sorry, I meant the count...for now...
Ok thanks I will try that...
@onyx harness Actually, how do I get height lol?
How do you draw?
EditorGUI.PropertyField(new Rect(guiDefaultPosition.x + 110, guiDefaultPosition.y, 160, 20), serializedObject.FindProperty("MenuAction"));
Perfect thanks!
Does this one solve your earlier question?
On a custom PropertyDrawer I'm using the following code:
EditorGUI.BeginChangeCheck();
float newRange = GUI.HorizontalSlider(rangeRect, target.range, target.min, target.max);
if (EditorGUI.EndChangeCheck())
target.range = newRange;
This works for setting the value.
However the MonoBehaviour with the custom PropertyDrawer doesn't have OnValidate called.
How can I force OnValidate to be called?
Not sure, but maybe because you modified the target directly, instead of the SerializedObject
The change is not reflected
I had to because the GUI.HorizontalSlider doesnt take the SerializedObject
Invalidate the Serialized Object
You guided me to the right solution! ...
EditorGUI.BeginChangeCheck();
float newRange = GUI.HorizontalSlider(rangeRect, target.range, target.min, target.max);
if (EditorGUI.EndChangeCheck())
range.floatValue = newRange;
(Last Line) range is my serialized property 🙂
@onyx harness hey
Yes?
do u know how to update scene gizmos ?
from within onInspectorGUI
force exec sceneView.repaint
Didn't you just write it?
it won't work
bool repaint = false;
void OnEnable() => SceneView.duringSceneGui += OnSceneGUI;
void OnDisable() => SceneView.duringSceneGui -= OnSceneGUI;
void OnSceneGUI(SceneView sv)
{
//var script = ( MapData3D ) target;
//sv.drawGizmos = true;
if( repaint )
{
sv.Repaint();
repaint = false;
}
}
I set repaint = true in OnInspectorGUI when a value is changed
Hum... i read this is the wrong way of doing
OnSceenGUI gets exec'd only when focused ?
Because duringSceneGui will only be triggered on the SceneView repaint, isn't it?
which will just repaint a 2nd time due to your Repaint
ah ye
SceneView.currentDrawingSceneView was returning null
guess ill capture it on the sceneGUI and use the ref instead
I guess it is null because when you use it, you are in a OnGUI or something and not a scene repaint
Those are very contextual
The name is not "lastDrawingSceneview" but "current"
There are equivalent for Inspector and others
context menu yield only SceneView.currentDrawingSceneView
anyhow i used the ref
seems to do the trick 🙂
void OnSceneGUI(SceneView sv) => view = sv;
public override void OnInspectorGUI( )
{
using( var change = new EditorGUI.ChangeCheckScope() )
// ...
if( change.changed ) view?.Repaint();
If it works, it works 🙂
exactly lol
k
SceneView.lastActiveSceneView
nope
Doesnt work?
Resources.FindObjectOfTypeAll(typeof(SceneView))
Hum... this last is very surprising
that what i tried btw :
if( change.changed ) ( (SceneView) Resources.FindObjectsOfTypeAll(typeof(SceneView)).FirstOrDefault() )?.Repaint();
This is my most reliable way of finding any Object
Ok ok, I'll keep that in a corner of my mind
it is not null tho
im getting out (UnityEditor.SceneView) as log
So what is not working then?
it works
only when focused
so i change the slider and it won't repaint
but when using void OnSceneGUI(SceneView sv) => view = sv; it does forces it to repaint for some reason
idk
Strange
var val = (SceneView) Resources.FindObjectsOfTypeAll(typeof(SceneView)).FirstOrDefault();
//Debug.Log( val );
if(change.changed) val.Repaint();
vs
if( change.changed ) view.Repaint();
oof..
that one also stopped working
D:
Restart
yep now ( 2/3 ) works lol
broke:
if(change.changed) SceneView.currentDrawingSceneView?.Repaint();
work:
if(change.changed) catched_view_ref?.Repaint( ); ( from OnSceneGUI )
if(change.changed) ( ( SceneView ) Resources.FindObjectsOfTypeAll( typeof( SceneView ) ).FirstOrDefault( ) )?.Repaint( );
1st
i move a slider and a gizmo cube size is changed
on OnDrawGizmosSelected
guess ill use OnSceneGUI instead :/ ?
(FYI Resources.FindObjectsOfTypeAll<SceneView>())
Is there a way to hide the static methods in the UnityEvents inspector and only show the dynamic ones?
You must reimplement the drawer
@onyx harness Is that response for me?
yes
SerializedProperty property = serializedObject.FindProperty("unityEventPropertyField"); EditorGUI.PropertyField(new Rect(guiDefaultPosition.x + 110, guiDefaultPosition.y, 160, 20), property);
I have this, where should I start?
Either you redraw the whole UnityEvent manually
Or you reimplement a PropertyDrawer
Which will also need to redraw the UnityEvent manually
Not sure what you mean by redraw...
Using EditorGUI/GUI to mimic what Unity have done for UnityEvent
So create my own UnityEvent GUI?
Yes exactly
Sounds like too much work lol, I'll figure something out...
Oh yeah, if you have no idea how to do that, it becomes much more difficult
do float[ , , ] get serialized ?
This a multi-dimensional array, nope
uhh time for a index shift hax
i think i gotit
just dropping it here if anyone would need this ( i hope it works ... )
/// <summary> Convert 3D index into 1D </summary>
public int Index3D1D( Index3 index ) => index.z * ( x * y ) + index.y * x + index.x;
/// <summary> Convert 1D index into 3D </summary>
public Index3 Index1D3D( int index ) => Index3.Floor( index % x , index / x, index / ( x * y ) );
( where this . x,y,z is the grid size )
Out of curiosity, is there any drawback to putting assets (scriptable objects, prefabs, etc) in Resources, but not loading them? I put some in there for my game editor, but never load them in the actual game.
Very bad
@onyx harness that isn't an answer. :P
@marble oriole The only drawback is that they would be included in the build of the game, meaning it would unneededly increase the size of it. I think that if a Resources folder is inside of a Editor folder, it will not be included, or maybe the other way around, could be wrong though.
Got it, thanks @gloomy chasm , that makes sense. I'll look into moving it elsewhere. Early enough in development that it's ok to do small refactors 🙂
@marble oriole Having those folders embedded in build is one thing, having them loaded in memory while the user is never gonna use them is way worse
Because Resources are loaded at startup, which increases loading time for nothing.
Because Resources are loaded at startup, which increases loading time for nothing.
This is what I was wondering about.
Could be nothing, negligeable, but bad practice
@patent river IDE configuration is pinned to #💻┃code-beginner
I ended up figuring out by reading all those pesky error messages
It was only a matter of finding the correct installs
Thanks anyways
Guys what would be the best way to have an undoable field in an editorwindow which shows data local to the editor window, I mean like its not binding data from some other object but rather its just a private float field or something in the editorwindow class.
Heya, I can't seem to find how to make a (UI toolkit) visual element resize to fit it's content container
My css goto resize does not seem to exist in unity CSS land
.charImgStyle {
height: auto;
position: absolute;
-unity-background-scale-mode: scale-to-fit;
width: auto;
flex-direction: column;
flex-shrink: 1;
flex-basis: 100%;
}
Just doesn't seem to do the trick
goal is to keep the apsect ratio the same but keep the content completely in view
Have a play with the UIElements debugger
it's much easier to get things working and see the bounds of the rects you're dealing with
Yeah I tried playing with pretty much every setting I could think of, it seems like pretty much none of the settings do anything
absolute position might not be resizeable maybe
I can set up similar things in UI builder and it seems to resize them fine
but yeah add absolute position and it seems to be a buzz kill
🤔
I've conceded to just making a mouse drag manipulator
this css stuff is too much for my smooth brain
@civic river Sorry for the late reply. flex-grow: 1 should do for you.
not sure if this is the correct section for this but I really need some help with setting up snippets for unity in vsc
I installed the extension and the instruction say I need to pop this command in the command palette: ext install kleber-swf.unity-code-snippets to install the extension
but when I try to do so I just get this
does anyone know how to fix this?
I want to draw handles, but in the same way the unity label icons are rendered.
I tried faffing about with the sceneview camera's cameraToWorld and inverse matrices, but somehow I can't get to the right behaviour.
The ">" in each of these should at some time be the endpoint for a spline that goes to another object.
These are drawn with "Handle.Label" right now, with newlines (because I can't space the lines myself correctly - this is part of my problem)
Nuuuu.
is Handles.DrawAAPolyLine broken ?
var top_right = view.camera.ScreenToWorldPoint( screenSize );
var bottom_left = view.camera.ScreenToWorldPoint( Vector3.zero );
Handles.color = Color.red;
Handles.DrawAAPolyLine( 2f, Vector3.zero, top_right );
Handles.color = Color.green;
Handles.DrawAAPolyLine( 2f, Vector3.zero, bottom_left );
Handles.color = Color.white;
Handles.DrawAAPolyLine( 2f, bottom_left, top_right );
ah... ok it doesn't like z shifts , fixed by adding this :
bottom_left.z = top_right.z = 0f;
So I have a horizontal layout group with 2 elements and the second one is a small button. So far everything is fit nicely. But if I change the second element to a vertical layout group because I want 2 small buttons on top of each other it adds a lot of padding to the second element. Why is that and how do I change that?
No nested vertical layout group
@deep wyvern To be honest, I'm not sure, especially without seeing the code.
I guess using GUILayoutOption.ExpandWidth(false) might help @deep wyvern
@onyx harness I think thats what I was missing. Used a different workaround for now. Thanks!
Hello , i was wondering , why is the reorderable list so laggy when i add a good amount of items to the list.
Might depend
How much is "good amount", how heavy is your GUI
And of course, I'm not sure ReorderableList is well optimized
40 items is maximum then it takes like 2-3 seconds until the gui reacts
i just disabled the custom editor script and everything works very fast so it must have to do with the custom editor/reorderable list
what do you mean with "how heavy is the Gui" Mikilo
Sorry, but you are not qualified to state if it is much 🙂
on top of that, you have a GetPropertyHeight right?
And I think I can say yes, this is heavy
40 elements, multiply by 5., 200 elements minimum in a single Editor
allright. i will see what i can do there. thanks
And i have to add double the size actually :/
items have a few more fields
how do I detect the available width of an editorwindow, adjusting for the scrollbar if its present?
Hardcore
Use GUILayout.Space() and get last rect, to extract the width
Or something similar
Or go deep and dive into GUIView and clipping
eep
I assumed it would be rather simple, given I can see it happening in the inspector for default inspectors xD
You talk manually or using Layout?
im using layouts
cuz I made an editor grid view
and the scrollbar is being drawn on top of it
public static void CreateGrid<T>(this List<T> data, Vector2Int size) where T: Object
{
if (data == null || data.Count == 0)
{
return;
}
var width = Screen.width - 45;
for (var i = 0; i < size.x * size.y; i++)
{
if (i % size.x == 0) GUILayout.BeginHorizontal();
data[i] = EditorGUILayout.ObjectField(data[i], typeof(T), false,
GUILayout.Height(Mathf.Floor(width / (float)size.x)), GUILayout.Width(Mathf.Floor(width / (float)size.x))) as T;
if (i % size.x == size.x - 1) GUILayout.EndHorizontal();
}
}
yeah ok, thats a good point
Just before going into BeginHorizontal
Draw an invisible line
Or just GetRect with full expand width
hmm
GetRect with full expand width
im not sure I understand what that means GUILayoutUtility.GetRect(GUIContent.none, new GUIStyle());
this sets the value to the width and after it just decides to set it to 1 somehow
var width = GUILayoutUtility.GetRect(GUIContent.none, new GUIStyle()).width;
guess its the repaint and layout event being annoying
ah
Sorry wrong word, you must use the width from Repaint only
😬
private static float width = 0;
public static void CreateGrid<T>(this List<T> data, Vector2Int size) where T: Object
{
if (data == null || data.Count == 0) return;
if (Event.current.OnRepaint())
{
width = GUILayoutUtility.GetLastRect().width - 10;
}
Debug.Log(width);
for (var i = 0; i < size.x * size.y; i++)
{
if (i % size.x == 0) GUILayout.BeginHorizontal();
data[i] = EditorGUILayout.ObjectField(data[i], typeof(T), false,
GUILayout.Height(Mathf.Floor(width / size.x)), GUILayout.Width(Mathf.Floor(width / size.x))) as T;
if (i % size.x == size.x - 1) GUILayout.EndHorizontal();
}
}
@onyx harness is it literally redrawing after the scrollbar is there and thinking it fits on there making it jitter like that lol
Sorry it is not suppose to be like that
The "width ="
Rect r = GUILayoutUtility.GetLastRect();
if (Event.current.OnRepaint())
{
width = r.width - 10;
}
``` @steady crest
More something like that
oh wait...
You must draw something before using GetLastRect
Or it will give you the rect of the last thing
and I don't know what it is
Would that be something above it in the inspector or could it be some other random ui element?
The last thing drawn above it is a horizontal group with a slider and a button
The available width if I log it is just constantly changing between x and x-15 which would be the width of the scrollbar
What is if (Event.current.OnRepaint())?
type == EventType.Repaint?
Why don't use your GUILayout.MinWidth()?
And skip the whole complexification
From what j found on the docs they should be equivalent
Oh y actually minwidth should do it
Gonna be some trial and error to find the right layout stuff rly
And pre-detect if you are bigger than the (width-15)
Probably a good idea, ima try it in a few different ways. Interestingly each of the types has one of those boolean checks
I dont know why they exist if you can just check the enum types, but they do
Hey frens, more UI elements confusion from me. I don't know why this TemplateContainer exists in my editor window, it is created malsized and seems to be the default container for the rest of the XML document.
the xml in question https://hatebin.com/ttdpjjnnqw
If I resize the template container in the debugger it works as expected
But I'm not really sure why that's a neccesary step
Is their some way I can get rid of it?
(also is this a bug that should be reported or am I just dumb)
Hello friends, how can I do this same re-import via code?
I am trying
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport & ImportAssetOptions.ForceUpdate);
But it doesnt seem to have the same effect
what's the relation of the scene view camera position to its draw size ? so i figured out by trial and error that the view.cameraDistance is proportional to 1 unity unit when its value is 1 and a cube will occupy the smaller size of the screen completely , when its value is 2 the cube size will be at 50% , etc , but i can't seem to see how to calc the position
... ahh nvm i'll use sceneView.camera.WorldToScreenPoint
how would I make rect that contains multiple rects, basicly something like
@tribal skiff In that picture, the red rectangle is a little bigger than it needs to be, right?
um... its just for better looking i think
Whats the best way to draw EditorWindow changes without overloading and crashing Unity?
??
So crickets?...
No crickets, just no a comprehensible question
how to make serializable asset reference in scriptable objects ?
( i want it to have something like public List<Object> references;
@tough cairn I don't quite understand what you mean. But if you want that field to serialize, you should be able just put [SerializeReference] on it.
[System.Serializable]
public class GridTileSettings : ScriptableObject
{
[System.Serializable]
public struct TileData
{
public int width;
public int height;
}
public List<Object> references;
public List<TileData> tiles;
now when i do cs [SerializeReference] public GridTileSettings settings; in a MonoBehaviour it won't serialize
Won't serialize as in assigning a GridTileSettings asset to the field will not save the value? Or as in the field it self does not show up in the MonoBehaviour?
the last one
ah nvm
i think i have some other problem
one sec
yep it wasn't creating the object to begin with lol
public static GridTileSettings Create( string prefix )
{
var data = ScriptableObject.CreateInstance<GridTileSettings>();
var path = "Assets/" + prefix + "_" + (typeof(GridTileSettings).Name.Replace(" ", "") + ".asset");
AssetDatabase.CreateAsset( data, path );
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
// Selection.activeObject = data;
return data;
}
and i call it on :
void OnEnable()
{
if( tileSettings == null )
{
var scene_name = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
tileSettings = GridTileSettings.Create( scene_name );
}
}
Nice. Just so you know, ScriptableObjects don't need System.Serializable attribute on them.
So did you get it working then?
lol, well glad you got it to work. Also, Unity supports polymorphic serialization for fields of the ScriptableObject type, so [SerializeReference] is not needed there 🙂
Yeah, I figured that may the case (I do that too), but thought I would make sure.
hi, are there any way to implement particlesystem.minmaxcurve to a custom editor ?
or any minmax curve in general
has anyone here reflected a method and used invoke in OnGUI? I think it is crashing Unity for me constantly. I need to figure out why...
That works just fine
Log, log, log
Is there any soloution for my problem. As soon as i have more than 20 items drawn it lags very hard. 5-6 seconds delay and more
i am using a reorderable list
maybe using a Changecheck codeblock. no clue if that would help 😉
if anyone could help me with that (https://discordapp.com/channels/489222168727519232/497874004401586176/767017310401331210) i'd really appreciate it
Would be really nice if someone has a working soloution for me. I can not publish this asset like that.
Use the profiler to see what's taking long?
Might just be too many elements at once
Or too many findproperties etc
Pre calculate your rects
That sounds good. Thank you.
Could also add expanders to the individual items to reduce the amount of items being drawn
I already told you thing, but you don't seem to listen
how do I detect the available width of an editorwindow, adjusting for the scrollbar if its present?
@steady crest https://docs.unity3d.com/ScriptReference/EditorGUIUtility-currentViewWidth.html might be what you want
Is there a way to draw the content of a editor window inside of another? I feel like there was, but now I can't find it for the life of me.
It's a tricky intent
EditorWindow are not supposed to be drawn inside one another
The state might be unpredictable
Depending on the EditorWindow
But technically, calling OnGUI should suffice
Alright, will give that a try, thanks. I am trying to draw an inspector inside of a custom window.
Well, I tried to just loop through the components and create an editor for each, but that broke, so now I am trying this 😛
You are doing something wrong then
https://twitter.com/_Mikilo_/status/1261383803060142080
Here I just create Editor from the Selection and draw them
Of course, there are many tricks in Inspector you have to handle to mimic it correctly
But this is the way
Drawing InspectorWindow in a EditorWindow is kinda dangerous
You need to perfectly handle its state, like enabling/disabling, focus, blur, etc.
There is only one drawback I know when mimicking via Editor.
Sometime the GUI requires the window to be specifically an InspectorWindow. There you are doomed.
Mikilo i just scrolled up and i can not see any tips you gave me to optimize the code.
I already told you thing, but you don't seem to listen
@onyx harness
Do you want me to code for you?
I stated too heavy GUI.
You said "not much"
If you never used the Profiler, the first move must be there
Navi is right
Check first
(Btw you used GUILayout in your drawer)
true
Profiler with Deep Profile
ok. i will inspect the code.
I don't know what is your aim about Editor scripting, but if you want to go deeper, farther, whatever, you need to know how to deal with the Profiler
One day or another, you'll have to face it
Yes sir?
I'm use the Unity: 2018.4.28f1 @onyx harness
And i'm download the new Unity Collab @onyx harness
I hope for you that the question is related to #↕️┃editor-extensions
I Need TeamMembers @onyx harness to help me work on TheSwampForest
What is this? I don't even know what it is @whole steppe
I guess I will be of no use on this matter
Well i'm use the new Scene Fusion on Unity 2018 @onyx harness
Hi there. Has anyone come across a problem when embedded Unity icons are missing? I'm using Hub 2.4.1, Unity 2020.1.7f1.
Tried reinstalling the editor, didn't help.
Lol, what have you done to your Unity
That just looks like a shitty drawer
Rather than missing icons?
Oh wait I'm looking at it wrong
They probably just renamed them?
Were do they store those icons? In a dll somewhere?
Nope, built-ins in the installation folder
unity_builtin_extra, default, editor, etc.
Thanks. Will investigate further
hello! i want to know are the editor custom inspectors to get better looking stuff is good even if i am doing a game alone?
vscode is showing errors that worked when i last opened project
WorldGenerator definately exists
i just cant get it to work
[Preserve]
public new class UxmlFactory : UxmlFactory<Listy, UxmlTraits> { }
[Preserve]
public new class UxmlTraits : VisualElement.UxmlTraits
{
readonly UxmlStringAttributeDescription foldout = new UxmlStringAttributeDescription { name = "FoldoutText", defaultValue = "Foldout" };
////
}
private readonly Foldout foldout;
public string FoldoutText //name = "FoldoutText" links directly with this field
{
get => this.Q<Foldout>("ListFoldout").text;
set => this.Q<Foldout>("ListFoldout").text = value;
}
Hey guys, sorta dumb question but I haven't stumbled on an answer if anyone's aware of one. Unity automagically names your field in the UIE builder/XML based on the field name you've declared, but the name doesn't appear to be mutable so it looks really horrendous but other fields don't look nearly as bad. Is their some way to change the display name for the UIE?
Here's an example of what I mean
Hello, I am wondering if anyone knows how to properly make UnityEvents shown on the Inspector, using EditorScripts, It looks like a simple PropertyField won't do the job, the elements shown just doesn't respond with clicking
I have encountered this before, but on ReorderableList, which I can cache it as a private variable, however I find little info on how to properly "cache" this.
you need to Apply your scriptable object when changes are made
Hello ! I'm trying to replace '@' with '/' in the AnimationClip's internal name, and it works great on asset creation/move :
Problem is it doesn't work when I'm just renaming assets. Here is the code :
I tried a bunch of solutions (SerializedObject, AssetModificationProcessor, ForceReserializeAssets, GetPostprocessOrder) but none of them work. Any idea ?
Why each time I modify a gameobject's component in the inspector the component is serialized several times? I just put ISerializationCallbackReceiver and a Debug.Log("Hi") and I noticed that the message is logged 15 times when I modify the component... not 1
Is it in a custom editor?
@waxen sandal Yes, but actually it usesDrawDefaultInspector+ one button
I'd just check the input after and round it but not sure if there's an official way
Hello Guys! Any idea why my Project Preferences show um like that? How can i fix it?
show up*
Is there a way to costumize that ? like adding icons ,buttons ?
@uncut snow EditorApplication.hierarchyWindowItemOnGUI
thx^^
Sorry if this is not the right channel. How can I get a scrollbar on the inspector window? I have many elements in my 'indices' component but I can't scroll down to see all of them
it's not
Yeah something is fucking with your editor
Fixed. it was the imported project that caused this
Is there a way to find all references to an instance of a SO ?
I wanted to do it via script
So I can have a button in my inspector that makes a popup to show where it is being referenced
No API available
yeah I figured this is going to be a ride ^^
I provide an API in NG Asset Finder, but it's not quite direct and straightforward
You have to implement some stuff to scan
There's https://docs.unity3d.com/ScriptReference/AssetDatabase.GetDependencies.html or https://docs.unity3d.com/ScriptReference/EditorUtility.CollectDependencies.html that might be up your alley
@waxen sandal If I understand correctly that would get me every object of the type of SO that I am looking for?
Not at all
It collects dependencies
You are looking for references
Exactly the opposite
yeah
I tried it and it only got me the script and the instance so its not what I am looking for
https://answers.unity.com/questions/155746/how-do-i-find-which-objects-are-referencing-anothe.html#answer-1175570 I found this. This finds components but I think this gets me on the right track.
very basic but related none the less, how would i get the worldspace position of the editor camera? i've gotten the rotation just fine, but the position is a rect?
very basic but related none the less, how would i get the worldspace position of the editor camera? i've gotten the rotation just fine, but the position is a rect?
@barren elk solved,SceneView.lastActiveSceneView.camera.transform.position;
Hey there, is there a way I can make use of PropertyField to draw my own UEventFloat that derives from UnityEvent<float>?
Oh never mind, just add [Serializable] on top of the class
Anyone ever ran into this while starting a coroutine right after starting Unity?
Couldn't extract exception string from exception of type StackOverflowException (another exception of class 'NullReferenceException' was thrown while processing the stack trace)
In a DelayCall of course
It hits that on the first yield
is there any way to swap assets and keep properties, i have this game and I want to swap this cube out for a car model, can I do that? and how
ReleaseAllScriptCaches did not release all script caches!
Does anybody know why this pops up when I open the editor?
Sometimes it appears, sometimes it doesn't, but regardless, the project I'm working on runs fine. Still--I can't help but feel that my project is fucked in some way.
Does anyone know why GetWindow creates a new instance of the window even though the description of GetWindow says it will look for an instance first?
This only happens if the window is docked...
Did something change in 2020 that you cannot pass in a enum serializedProp into a prop field anymore?
Nvm I just had some super weird VS bug
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
Anyone knows how can I check if a gameobject is a prefab or not?
Like between the blue and gray box
I guess I use this? https://docs.unity3d.com/ScriptReference/EditorUtility.IsPersistent.html
Doesn't seems to be working
Oh I'm dealing with nested prefab btw
Why do I even waste my time answering
?
Guys can anyone help me out with this??
https://forum.unity.com/threads/whats-the-best-way-to-display-propertyfields-of-serializedfields-of-an-editorwindow-class.992965/
Its regarding a problem with Undoing a propertyfield
Plssssss
At some point (no idea when) Undo.RecordObject stopped working for me. I have no idea what could be causing it but it just doesn't record the action now. No error or anything. It just... doesn't do anything. Any ideas?
i need to run some code when the unity editor is saved.
public class SaveHandler : UnityEditor.AssetModificationProcessor {
public delegate void Notify();
public event Notify UnitySaved;
public static string[] OnWillSaveAssets(string[] paths) {
string scenePath = string.Empty;
string sceneName = string.Empty;
foreach (string path in paths) {
if (path.Contains(".unity")) {
scenePath = Path.GetDirectoryName(path);
sceneName = Path.GetFileNameWithoutExtension(path);
}
}
if (sceneName.Length == 0) return paths;
return paths;
}
}```
that unfortunately is static, so i cant add the event that i made at the top of the class
is there a non static alternative or a workaround?
i need to call a method in a editor script when the project is saved
ping me please
Make your event static?
Can somebody lead me trough how to make a game like Scrutinized or Welcome to the game 2
So if I use Resources.FindObjectsOfTypeAll it seems to find every object in the scene but only assets from the project folders if I have selected them once during the session. Is there a way around it so I can find all objects regardless of having selected them before?
@deep wyvern AssetDatabase methods
what does this mean "In Editor, this searches the Scene view by default. If you want to find an object in the Prefab stage, see the StageUtility APIs." ? What the stageUtility being used for? and what exactly IS "prefab stage"?
i set the prefab as dirty with EditorSceneManager.MarkSceneDirty(prefabStage.scene)
how do i force-click the 'Save' button from script?
One message removed from a suspended account.
One message removed from a suspended account.
hello guys, today is my first day doing Editor Scripting, I made a small editor but can align things properly in it
How do I align all the options on the red line?
Like the first option
anyone have any ideas on how i can embed the unity animation preview window into my own custom editor?
@crude horizon show us some code
EditorGUILayout.BeginHorizontal();
GUILayout.Label("GameObject containing Text Component(s)", GUILayout.Height(20));
go = (GameObject)EditorGUILayout.ObjectField(go, typeof(GameObject), true);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
GUILayout.Label("Match Color", GUILayout.Height(20));
matchColor = EditorGUILayout.Toggle(matchColor);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
GUILayout.Label("Match Size", GUILayout.Height(20));
matchSize = EditorGUILayout.Toggle(matchSize);
EditorGUILayout.EndHorizontal();
if (!matchSize)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Label("Font Size", GUILayout.Height(20));
fontSize = EditorGUILayout.FloatField(fontSize);
EditorGUILayout.EndHorizontal();
}
@onyx harness This is how I arranged everything
or any pointers on how to make a similar functional preview window appreciated too
I advise you to use label from ObjectField and Toggle
instead of drawing the label yourself
Sorry I didn't catch you
Methods ObjectField(), there are many overloads
Use the one providing a label
and use EditorGUIUtility.labelWidth to adjust the width of the label
Can you write me one small example?
ObjectField("GameObject containing Text", go, typeof(GameObject), true)
Did that
Yep, that's the way
labelWidth, like stated above
no no, before
it sets the width
the right way
1/ Is to save it to a variable.
2/ Set your intended width.
3/ Draw.
3/ Restore the width
In UIToolkit, how do you have an element that doesn't affect vertical layout but still expands horizontally?
I want basically to make a background out of several elements.
Hi, is there any way to convert a single binary saved scene to text based scene ?
i'm trying to validate a variable and want to show a message in the inspector when it fails, how can i do this please? google isn't throwing me anything useful
OnValidate doesn't seem to be overrideable in an Editor script
is there an equivalent of the AssetPostProcessor but for when assets are deleted from the project?
nevermind - found it ... AssetModificationProcessor
Hey @visual stag, sorry to ping you, but can I DM you?
Sure
i have a mesh that i want to paint in the editor, how would i do that
i already have the collision detection and raycasting from the editor, i just need the actual mesh painting to work
What's the idiomatic way to manage cached data that is derived from project assets. I would like to create assets within the Library/ folder as Unity does, but I'm not sure what the best way to go about this is. Should I just be calling AssetDatabase.CreateAsset(myCache, "Library/MyExtensionName/MyCache.asset")?
Yes
Some very nice scene tooling things are being cooked for Unity 2021. See videos: https://t.co/BsYrHRDWm2 and https://t.co/MX8Grr443z, and a forum thread https://t.co/DAmtAZpFNE
Looks nice
what's the recommended way of handling multi-selectable VisualElements? Ideally there'd be something like a custom pseudo-class, but it doesn't seem like that's possible...
Is there a way to remove a file created in the library folder with InternalEditorUtility.SaveToSerializedFileAndForget?
AssetDatabase?
Save To Serialized is useful for assets outside the project, since Library is inside, there's no use @waxen sandal
And SaveTo is kinda dangerous if you don't grasp correctly it's behaviour
CreateAsset doesn't work in Library, perhaps in newer versions but I'm on 2018.4
Sounds strange
So I assume other things don't work either
I don't recall ever seeing assetdatabase working outside of assets/packages
AssetDatabase works at the root project level
Assets is just one folder inside
That's why you have to prefix all your paths with 'Assets/'
Because you can write to ProjectSettings and others
That doesn't explain the error I get 😛
Which error?
Don't have the project open atm, will let you know in a bit
@onyx harness
Startup failed: UnityEngine.UnityException: Creating asset at path Library/test.asset failed.
at (wrapper managed-to-native) UnityEditor.AssetDatabase.CreateAsset(UnityEngine.Object,string)```
with AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<ModifiedReferencesData>(), "Library/test.asset");
Let me give it a try in 2018.4 as well
@waxen sandal looks like you are right! Creating seems forbidden, while loading is fine
Interesting...
The fuck Unity
Ah well, I'll just keep my SaveToSerializedFileAndForget
SaveToSerialized will create an Object that will survive domain reload! Be careful with it
Thanks 👍
Trying to piece together how to make custom editor, and I can't seam to figure out how to make EditorGUILayout.Toggle clickable to change the class's boolean property "controlsEnabled"
[CustomEditor(typeof(PlayerController))]
public class PlayerControllerEditor : Editor {
public override void OnInspectorGUI() {
PlayerController controller = (PlayerController)target;
if (controller.controlsEnabled) {
EditorGUILayout.Toggle("Controls Enabled", controller.controlsEnabled);
} else {
EditorGUILayout.Toggle("Controls Disabled", controller.controlsEnabled);
}
}
}
Trying to piece together how to make custom editor, and I can't seam to figure out how to make EditorGUILayout.Toggle clickable to change the class's boolean property "controlsEnabled"
[CustomEditor(typeof(PlayerController))] public class PlayerControllerEditor : Editor { public override void OnInspectorGUI() { PlayerController controller = (PlayerController)target; if (controller.controlsEnabled) { EditorGUILayout.Toggle("Controls Enabled", controller.controlsEnabled); } else { EditorGUILayout.Toggle("Controls Disabled", controller.controlsEnabled); } } }
@chrome dock
shouldn't it be:
controller.controlsEnabled = EditorGUILayout.Toggle("Controls Enabled", controller.controlsEnabled);
That does work, and somewhat make sense. (I am very new to custom editors)
Yeah it's a bit confusing. Took me hours to figure it out the first time too lol
and I have to eventually get to the point to use a reorderable list of inherited classes 😓
but gotta start small with the easier scripts that could use an editor overhaul
I keep getting an error on
if (controller.controlsEnabled) {
Saying
“Mismatched types in GetValue - return value is junk. UnityEditor.SerializedProperty:get_vector3value()”
It works as expected in editor, but throws an error afterwords
Um... is controlsEnabled a boolean?
yes
I wonder if your controller is being destroyed before oninspectorgui is being called, I'd try adding if(controller != null) before and see if that fixes it
I am just utterly confused. I slapped that around the entire oninspectorgui right after controller = (PlayerController)target, and the error stopped. I removed that if statement, and the error doesn't come back... (Yes, it was saved before doing if(controller != null) when originally giving error)
Well, there's a lot of things that /could/ be wrong, but off the top of my head the two major issues could be the old script was cached and unity didn't update it after the save, or there was an instance of the old script running that shared the same memory as the new one and when you updated the script with the if statement unity killed that instance
[Header("Insert_Thing_Here")]
How do I change Alpha of a TTMPRo text using LeanTween?
Hello.
does anybody know if one can change the background color of a game object preview created like described here: https://docs.unity3d.com/ScriptReference/Editor.OnPreviewGUI.html
it works, but I don't like the black background
I tried assigning a new BG color style with GUIStyle bgColor = new GUIStyle(); bgColor.normal.background = EditorGUIUtility.whiteTexture;
But it didn't do anything
UIToolkit pros ... have you found a way to find out the size (especially "height", but width would be great too) of text elements in UIToolkit / UIElements?
...the obvious method (MeasureTextSize) is useless when building UI (not documented, but according to a Unity forums post: it only works AFTER you've displayed the UI).
In UnityUI this was fiddly but worked - is that the best workaround, to generate UnityUI objects and use them to calculate size instead?
Look at the source?
Um. It's native code. How do I see the source?
OK, so ... using UnityUI instead of UIToolkit actually works - but you have to guess a font + font-size (I don't know how to read the default font + font-size in UIToolkit, but if you try to read them back from a plain Label you get null data):
TextGenerator textGen = new TextGenerator();
Font unityFont = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).font;
TextGenerationSettings generationSettings = new TextGenerationSettings()
{
font = unityFont,
fontSize = 14,
fontStyle = FontStyle.Normal,
lineSpacing = 1f,
pivot = Vector2.zero,
scaleFactor = 1f,
horizontalOverflow = HorizontalWrapMode.Overflow,
};
float labelHeight = textGen.GetPreferredHeight(""+item.cssPadding.top, generationSettings);
If anyone knows how to read the current / default / global stylesheet info, I could update that to have correct values, but ... I can't find a way to access them (I've just re-read the full UIToolkit docs again, and done a lot of google searches, but nothing)
weird question maybe, but is there a way to have two different project windows (where you view files etc.) that aren't linked together in the editor?
I wanna be able to view my scenes at all times, but if create two project windows and double click an item they both sync up
yes
how would you go about that?
I finally got to the point of using the baked in (still lack of documentation) ReorderableList, but i’m a bit unsure on this new (to me) EditorGUI. Every tutorial ive found tells me to use EditorGui.PropertField, but for one variable I need a TextArea. Is it ok to use them, or is there some issue with doing so like it not connecting to the variable to update from editor?
You could use a PropertyField and just add a [TextArea] attribute to your field
oh, ok
that definite;y seams to work.
One other question. I have class Dialogue (Which is used on its own) that I created a custom editor for (which has a reorderable list), and then I have DialogueAction, which uses Dialogue class as a property. I have been searching on google, but maybe the words I am using aren't the right ones. But how do I use the existing editor for Dialogue in my DialogueAction so that I don't have to repeat all the ReorderableList stuff again (and update all places its used from one source)?
I could go back to what I was doing before, where i just made DialogueAction require Dialogue to be on gameobject with [requirecomponent] and automatically grab it on awake, but i kinda want to have it all in one nice panel if possible.
(I kinda need to have it in same panel, because in future, I need to implement a similar feature, for a reorderablelist that can use multiple classes that originate from Action- which will have to run the classes in order)
I'm not quite sure I follow (I have no idea what all your class names mean) but - have you looked at Custom Property Drawers? Sounds like that's what you're looking for (they have a lot of ... um ... "design flaws" ... so they don't quite work the same as everything else, most of which I consider "bugs", but most people have now memorized the differences + workarounds for the differences, so ... we just suck it down these days :))
(and for the most part they work great, to be clear. It's just there are edge cases that work badly)
What exactly?
Im displaying a grid of buttons. And trying to surround if with beginScrollview, but when the buttons get too big, it expands my element
ill make a screenshot
{
GUIStyle textureButtonStyle = new GUIStyle() { margin = new RectOffset(1, 1, 1, 1)};
int widthCount = _voxelPalette.width;
int heightCount = _voxelPalette.height;
subTextureSelectionScroller = EditorGUILayout.BeginScrollView(subTextureSelectionScroller);
int buttonSize = 128;
GUILayout.BeginHorizontal(GUILayout.MaxWidth(380));
for (int x = 0; x < widthCount; x++)
{
GUILayout.BeginVertical(GUILayout.MaxHeight(230));
for (int y = heightCount - 1; y >= 0; y--)
{
if (GUILayout.Button(_subTextures[x + y * widthCount], textureButtonStyle, GUILayout.Width(buttonSize), GUILayout.Height(buttonSize)))
{
int id = x + y * widthCount;
_voxelPalette.voxelTypes[_selectionGridIndexVoxelTypes].textures[_selectedSubTextureSide] = id;
UpdatePreviewObject();
HideSubTextureSelectionWindow();
};
}
GUILayout.EndVertical();
}
EditorGUILayout.EndHorizontal();
GUILayout.EndScrollView();
}```
but I want the width to be as wide as the box above
for that i need to specify a rect though, dont i?
Or, you can try to put a flexible space at the end of each row
i dont know why this type of editor extension is so complicated to understand
i worked with the experimental grid feature a few months ago
and it was completely different
but so much better
lol actually maybe I should
i didnt think about that because when just looking to make editor extensions, every tutorial tells me to use this stuff
in the new thing, every element is a flex box
which is so handy and easy to understand
but maybe thats me because I use them in webdevelopment too
One message removed from a suspended account.
One message removed from a suspended account.
Stick with it then 🙂
One message removed from a suspended account.
then give more details
One message removed from a suspended account.
One message removed from a suspended account.
So this code works right?
One message removed from a suspended account.
One message removed from a suspended account.
Print the output
Try with very simple case
Make sure it works the way it should for simple stuff
One message removed from a suspended account.
One message removed from a suspended account.
🙂
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
yeah because restart I hear restarting a process, which in this case nothing survive 🙂
One message removed from a suspended account.
Oh you meant persistent then
Sorry, wording is a bitch, but they have precise definition to avoid confusion 🧙
One message removed from a suspended account.
Where do yall save your project and preference settings? I can't figure out a good way to do it without hardcoding in the path. :/
One message removed from a suspended account.
One message removed from a suspended account.
EditorPrefs, SessionState & Local AppData for global stuff
One message removed from a suspended account.
One message removed from a suspended account.
Oh yeah, that is cool. Didn't know it was a thing!
It's a reliable way to store data that must survive for the process lifetime
Nothing very special about it
What about Project settings? What do you do for those?
Data :
- for plugin-level : use ProjectSettings (or AppData for global)
- Editor/EditorWindow/PropertyDrawer-level : EditorPrefs
- SessionState anywhere you need data that doesnt last but must survive domain reload
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
I try my best to stay away from those, as it bothers users
But I'm a publisher, needs are different I understand
I will assume it is me just not getting it. But I want things to be stored per-project, so like they are included on github and stuff. I don't quite understand how one would do that.
One message removed from a suspended account.
One message removed from a suspended account.
Yes yes, it is a good place
What do you do @onyx harness if you don't put things in the ProjectSettings folder? Or do you?
I use InternalEditorUtility.LoadSerializedFileAndForget to load an asset in the AppData
One message removed from a suspended account.
I use it for global yes that's correct
but maybe thats me because I use them in webdevelopment too
@drifting forge Not just you. Flexbox is literally 30 years ahead of Unity's own layouting systems (Unity's layout architecture was already 10+ years behind the idnustry standard when they first implemented it :))
One message removed from a suspended account.
Uh ... or you could read the context. Ruby was saying that they thought Unity's new layout - UIToolkit - was easier to understand than the old one. I agree. I've been writing IMGUI editors for Unity since 2013 and I can do it in my sleep now, but I still recommend people use UIToolkit instead for inspectors.
i got lead down a completely new path of editor making now
found out there is a UI builder package
lowkey orgasming
One message removed from a suspended account.
What about Project settings? What do you do for those?
@gloomy chasm There's a lot of options here. There's a long forum thread about it. Depends what kind of project-settings you want to store, and what you're going to do with them :). For editor-extensions ... I tried all the clever stuff, and it all failed sooner or later (edge cases in Unity, things that are poorly integrated), so now I do:
- ScriptableObject with all the per-project settings
- Write code to prevent there being more than one copy of that file
- For Editor: auto-detect it at startup but NEVER use Resources.FindObjectsOfTypeAll (it's fundamentally broken for this, even though lots of people try to use it for this). Have to do more of a manual search using the Editor-only APIs
- For runtime: Fresources.FOOTA is fine.
@remote yarrow For using ScriptableObjects. How do you find them? Because of course, the user can move them.
One message removed from a suspended account.
I making a thing where the user can make collections of assets.
So I need to save each collection and all the assets in that collection. This is for editor only.
One message removed from a suspended account.
No, I store the asset GUIDs, not the actual assets or their paths.
I just need to know where a single ScriptableObject is located that stores all the collections.
One message removed from a suspended account.
What do you mean?
Oh, do you mean like how you set the scriptable render pipeline asset in the project settings?
One message removed from a suspended account.
I never thought of that. Now I am blanking on how you access Project settings data... :/
You can't reference it in projectesettings because projectsettings has no persistence - you have to write your own code to de-persis
What I do at the moment is a combination of Object.Find methods - hang on, I'll dig out a recent example
public static List<MySettings> findAllPossibleProjectSettings
{
get
{
string[] guids = AssetDatabase.FindAssets( "t:" + nameof(MySettings) ); //FindAssets uses tags check documentation for more info
List<MySettings> @return = new List<MySettings>();
for( int i = 0; i < guids.Length; i++ )
{
string path = AssetDatabase.GUIDToAssetPath( guids[i] );
@return.Add( AssetDatabase.LoadAssetAtPath<MySettings>( path ) );
}
return @return;
}
}
...a lot of trial-and-error went into that, and some bug reports submitted to Unity for e.g. "FindAssets" is currently undocumented and doesn't work unless you know the magic strings (I had to go in the Unity source to find them)
(but there's now a thread in the forums where unity team has given their input and asked for feedback on how we'd like it to behave in future, so I'm optimistic the API will get improved soon)
Oh, that isn't too bad ( I mean besides that it is a property and not a method :P
). Something like that is probably what I was going to do. Good to know I was on the right track!Thank you.
One message removed from a suspended account.
you still need to handle what to do when it finds more than one result 😉 (I wrote a popup dialog that "strongly encourages" the user to delete one of them, since results are undefined otherwise)
One message removed from a suspended account.
Ah! When you said Project Settings I thought you meant the feature in the editor, not the magic folder 🙂 - sorry!
No, I meant just in general. You answered exactly what I was asking! 🙂
One message removed from a suspended account.
I would avoid using ProjectSettings folder because it has the same problem as all the other "smart" solutions: I fear it fails with core Unity features. Off the top of my head: isn't it impossible to have an AssetStore asset that has files in that folder? (because the assetstoretools package won't let you upload from it)
One message removed from a suspended account.
One message removed from a suspended account.
I don't know. But I also can't find docs on the ProjectSettings folder, so that immediately makes me suspicious of it 🙂
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
...a lot of trial-and-error went into that, and some bug reports submitted to Unity for e.g. "FindAssets" is currently undocumented and doesn't work unless you know the magic strings (I had to go in the Unity source to find them)
@remote yarrow Stop spreading shit https://docs.unity3d.com/ScriptReference/AssetDatabase.FindAssets.html
Last updated 4 days ago. That's probably an update from my bug report.
I mean I know I have used FindAssets before. And at least some of those docs were there.
Off the top of my head: in source code there were 4-5 magic strings. I do not see 4 strings documented on that page.
One message removed from a suspended account.
What sort of magic strings?
these "t:", "name:" etc
they control how FindAssets works
They cause Unity to instantiate an internal class that has some very useful methods on it that let you directly control what's being searched for
Off the top of my head: there's one for "include/exclude prefabs", and one for "only include assets, do NOT include scene objeects (or vice versa)"
If you feel it's fully documented, then great. I don't.
That is because it uses the same search that the project window uses
Last updated 4 days ago. That's probably an update from my bug report.
@remote yarrow lol are you being serious?
Off the top of my head: it's not exactly the same, it uses the same internal hidden class, but it uses it slightly differently.
(but go dig in the source to see for yourself)
@remote yarrow lol are you being serious?
@onyx harness Honestly? When someone starts with swearing at me and calling me a liar? I lose interest fast.
If I cared ... I'd dig out the Unity bug reprot with Unity's repsonses, and we coudl go through in precise detail exactly what was missing. But ... see above comment. I don't really care.
"t:" was there since the beginning, when you type "t:AnyMonoBehaviour" in the Hierarchy, it behaves exactly the same, the doc is clear
Woah...
Liar?
You're welcome to ignore me and e.g. use "Resources.FindObjectsOfTypeAll", because a lot of people believe it works (people who haven't tested it)
Da fuck you are talking about, i never talked about that
And we already had this discussion on the publisher forum
One message removed from a suspended account.
@whole steppe This is a channel for extending Unity editor. You can find VS and VS Code installation instructions in #💻┃code-beginner pinned on top right.
I have no idea how to automatically change icons for ScriptableObjects/Scripts depending on current theme
@foggy birch Not easy task
You must go through a SerializedObject
One message removed from a suspended account.
One message removed from a suspended account.
Oh I see, my bad, I thought you were talking about changing a Script's icon
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
I'm not sure if this belongs here so apologies in advance, but I've been trying to code a custom editor based off tutorial, and it's not drawing anything on screen
https://hastebin.com/ugurugoxub.csharp
there should be a circle around the red cube to indicate the viewRadius
ping me if you have a solution :P
@fading monolith ui in OnSceneGui is not capitalized, it needs to be.
So it should be private void OnSceneGUI() {}
Oh thanks!
that fixed it xD
I kinda knew it had to be a typo because it was exactly the same as the tutorial
So how would I make this rotate with the object it's attatched to?
I think changing from using the vector forward to using the target's transform.forward should do.
oh nice, and to keep the angle centered on the front of it?
Generally you can recognize Unity's reserved methods names being blue colored in VS.
So it works fine but the arc doesn't line up with the lines https://hastebin.com/abidijegix.properties
fixed it xP
If a Serialized Property is of an int value how do I get a reference to that value to pass into EditorGUI.IntField
I'm trying to make a PropertyDrawer that will change the names of a generic int[] from Element0 to what I want it to say. I made the attribute already and can change the names using EditorGUI.ObjectFiled but that doesn't work since they are ints
{
try
{
var elementProperty = property.GetArrayElementAtIndex(0);
int someX = 0;
int pos = int.Parse(property.propertyPath.Split('[', ']')[1]);
EditorGUI.IntField(position, new GUIContent(((ArrayNameAttribute)attribute).elementNames[pos]),someX);
}
catch
{
EditorGUI.ObjectField(position, property, label);
}
}```
I need someX to be the actual reference to the int[x]
The renaming works fine. EditorGUI.IntField use to EditorGUI.ObjectField but that made the Inspector have an spot to drag an Object which didn't work
You have a member intValue in SerializedProperty
Yeah I tried this:
EditorGUI.IntField(position, new GUIContent(((ArrayNameAttribute)attribute).elementNames[pos]),property.intValue);```
And it does generate text boxes to put in ints.. It starts out as 0 then if i type 10 and hit enter. . it instantly changes back to 0
weird then why does it take a property.intValue to assign to.. if I have to do the assigning 🙂
Wrong statement
it takes the intValue as argument
It's an integer, which implies a value type
Oh i see
🙂
So it keeps displaying the current value
Show me the change
Yeah that works correctly now
property.intValue = EditorGUI.IntField(position, new GUIContent(((ArrayNameAttribute)attribute).elementNames[pos]),property.intValue);```
Good job
Is there way to get the type that a property is. So i could switch on it and have EditorGUI.FloatField, or EditorGUI.Toggle as approperiate
if its an int, float, bool whatever
propertyType
Hello there, is there a way I can mark a PropertyField as ReadOnly?
ReadOnly as in the field in the inspector is not editable?
Yep
Is this UIToolkit/UIElements or IMGUI
EditorGUILayout.PropertyField(config.FindPropertyRelative("size"), new GUIContent("Font Size"));
do you guys know if it would be possible in a simple way to somehow reuse the unitys prefab environment scene thing for other stuff? i mean creating a custom tool/extension, that could grab any gameobject (not necessarily a prefab), temporarily move it/isolate it into a seperate mini-scene to do some work and then just return it back to the normal scenes environment?
with emphasis on 'simple' here, so possibly existing unity API that would allow for this (one they already use for prefab workflow)?
It's called prefabstage
Not sure if the api is generic yet but that was their plan iirc
What is a good way of drawing a plain sprite in the OnInspectorGUI()?
GUI.texture?
That works... but I am looking for an auto layout option
if(sprite.objectReferenceValue != null) GUILayout.Label(((Sprite)sprite.objectReferenceValue).texture);
Currently I am casting the objectReferenceValue into Sprite, but the Texture property of a sprite is the whole texture sheet it belongs to, rather than the specific cut...
Guess I need to find a way of slicing that whole texture sheet and re-assemble the pixel back into a separate texture
okay the heck
EditorGUILayout.PropertyField( x, GUIContent.none ); is usually my strat for making a labelless field
but for some reason it's not working in this context, I get an invisible label with a fixed width that I can still drag my mouse over to change values
anyone know what might be the reason?
remove the label ?
what?
Use the override without a GUIcontent
using the one without GUIContent will add the default label
no, usually it works by shoving in GUIContent.none
but in this case I get an invisible label that is still interactable and is taking up space
Did it happen suddenly? or after a Unity version change?
no, it's in a specific situation where it doesn't work
nothing changed temporally!
I wonder if it's the indent level that might be messing it up
yep! that was it
indent level is applied to all GUILayout.things it seems
Good job
I had them in a horizontal layout so things got fucky
IndentLevle is only applied to editorguilayout things iirc
Which is really annoying since buttons don't have an EditorGUILayout equivelant
Oh I found it
GUILayout.Label(AssetPreview.GetAssetPreview((Sprite)sprite.objectReferenceValue));
Good job

