#↕️┃editor-extensions
1 messages · Page 75 of 1
it's persisting the InputActionAsset inputAsset just fine, but not the InputActionMap activeMap field. The inputAsset get's updated via SerializedProperty but the activeMap get's updated through target as InputModule.ActiveMap property. That's the one I need to figure out how to persist.
Because you are assigning directly to the target and not through the SerializedObject
I figured, but how can I assign through the SerializedObject? I tried this the first go around, but it would throw errors because the InputActionMap is NOT deriving from UnityEngine.Object so using serializedObject.FindProperty("activeMap").objectReferenceValue = newMap as object as Object; doesn't work.
how can I cast a ray into my scene view on mouse click without changing my selection in the process
is there a way to prevent the selection change event?
someone then suggested I use a C# property to update the value. Which I did here.
I specifically intend to, make a button to enable a tool, the use clicks on some geometry in the scene, and then it shows the results of that click
Because you don't use SerializedObject properly
its for testing path finding
Can you help me figure it out with this field? If I can figure this out, I'd be able to understand how to do it for the rest of my life lol.
Been at this for 2 days now 😦
Intercepting Unity flows is kinda dangerous, but you can delay a frame to reassign the Selection rightafter
no problem
Thx god Discord implemented Answer To
right?
So in the InputModule class, I really don't need ActiveMap property, I only created that to get this custom editor to work. I really just need to serialize and update private InputActionMap activeMap
Did you need me to post the code again?
I mean, interception isn't strictly required
though, I do really look forward to the editor design improvements in 2021
You can't
NNOOO!!!!
Well then just execute your code on a mouse down event and reassign the Selection
activateMap is not even serialized.
It will never be persisted.
Any "workarounds"?
Perhaps I can store string value and have the inspector overwrite the inputMap by the stored string value?
sounds logical no?
I guess that is what you are looking for
Ok. I will try.
Unfortunately, I don't know what are InputActionMap
It's a class from Unity's InputSystem
InputAsset will be persisted, but not the rest
public sealed class InputActionMap : ICloneable, ISerializationCallbackReceiver, IInputActionCollection, IDisposable
Ok
And it actually has [Serializable] in the source code!
So why isn't it serialized?
Yes, but it is private
The class is private?
The field.
Can I put [SerializeField] then and do that?
Hmm..let me try the attribute first lol
Ok. here is result. I at least got one foot in the door now! So I [SerializeField] that field, and as a result, if I "inspect" the prefab (without switching to prefab mode), the value persists, and when making a new instance of it during runtime, the value persists! YAY.
BUT! When I enter prefab mode, the value is reset. And it doesn't matter what I set it to, when I leave Prefab Mode, it doesn't persist to the prefab when I "Inspect" it, and when I go back to Prefab Mode, the value resets.
So it's very strange behavior. What else must be done for it to persist to Prefab Mode?
Because you don't assign the value properly
Ok. How can I assign the value properly? 🙂
You are toying with the target directly instead of SerializedProperty
Oh, back at this are we? lol
In the reality, you can do it both ways
But you are not using SerializedProperty correctly still
Yes
Let me explain
I would MUCH rather prefer using SerializedProperty over target any day, but as I ran into that wall since the InputActionMap is not a UnityEngine.Object 🙂
Well then just get the right SerializedProperty and assign it
That's why I'm using target and doing all this work so I can get around this wall
FindProperty('activeMap.WhateverField') =
Ok. Let me should you what Unity says when I try to do it the proper was (as I have done the first go around) 😛
Type pptr?
Because you don't do it correctly
Ugh.
What do you want? Change an integer?
No. I want to change the entire object
A string?
A InputActionMap
that is [Serializable], but doesn't inherit from UnityEngine.Object
I know how to change integers, strings, and any MB derived class. That's basic 🙂
this line, move it after line 42
Will do. How come?
I was going to explain that earlier
Sorry
When you deal with SerializedObject, you are working on your target, which is a Unity Object.
The SerO is the C# representation, a bridge, to the C++ side where the real data lives.
Ok, this I know so far...
When you toy with target directly , you change the Object in the C# managed side.
But the real data in the C++ side remains unchanged!
Which I don't like anyway.
I understand this.
But I'm trying to get around the pptr exception
while swapping out inputMap through the SerializedProperty route.
By calling Update(), you request C++ to update its representation of the Object from the managed side
Oh. There we go. Now that is new for me 🙂
I will remember this.
So I must UPDATE the managed site, THEN call Update
You can not set the InputMap directly. because it's not a Unity Object but a pure C# class
BUT, SerializedObject of course allows you to set its fields
Yes.
Same for ApplyModifiedProperties()
This one is useless
Because you never actually use any SerializedProperty
ApplyModifiedProperties is like Update, but backwards yeah?
Aha. Ok. Let me try and see if I can tweak this some more 😉
While I understand that Apply is also C# to C++
This one talks directly through the bridge of SerializedObject
And SerializedObject handles undo and stuff
Which is convenient
So Update persists managed to serialized. And Apply from serialized to managed, correct?
Yes
Either choose one path, but avoid doing both, or you just need to correctly understand the principles running behind
Remember that SerializedObject also handles dirtying
Yeah dirtying is something I haven't gotten to learn yet.
Without that, maybe the data won't get saved to disk
Ok, moving Update to where you told me didn't work either. So let's try this 'dirtying' how would I implement this?
No no, better way of checking, read the file directly
Or just dirty the objectthrough code and save to disk
and check the content of the file
How do I throw some "dirt" on it?
You know, if Unity doc was exhaustive, I probably wouldn't be here asking you all this 😛
All I understood is that in the case of modifying Prefab itself, I need to mark dirty because it's a non-scene.
Do I just slap SetDirty at the end of the script? Or does I need to meet some condition?
Ok, so basically I will slap this in right before the Update call
The change havn't applied yet
Why would you dirty it if you did touch it?
What if an exception is raised in between?
Ok, let' esee what happens
My MAN!
It works!
@onyx harness Thank you so much, not just for the answer, but for the explanation! You should have Unity pay you to write their docs man! For real.
The day I will release my tutorials, a lot of things like that I will explain
Sign me up!
2 days wasted, when I could've just asked you 😉
Another thing
I was not really into helping you for a simple reason: Your case explanation is shit.
Sorry let me rephrase
I was not really eager to help you
Oh I understand, I didn't make it clear what I wanted. You had to figure out some things along the way? That sort of thing?
If you don't bring fact, code, the situation, what you tried and stuff, I will just feel you are passing and try to grab things as is
And I am really not the type of guys that is going to code for you
Exactly
I feel like if I posted what I tried...it would clog up the chat lol. I normally reset to discord when I can't find useful stuff online for what I want.
I am here willing to "teach" people, not to get points reward (That's why I like Unity Discord, no gamification like other Discord)
Docs first, then Google, then forums, then trial and error, then discord, then baseball bat to the computer.
My goal is for you to never return here, because you will understand what you do, and not just copy paste
I'm actually doing all this to learn the internals myself, not just to run through it.
I wish it was first shot. Many many shots before I talked to you.
Anyways, big thanks again.
You are lucky Gary answered you and you dropped the code
Indeed. Thank you @solid dome you saved the day!
Otherwise I wouldn't have even looked at your case
Keep up the good work and good luck in your journey
Lol glad to have helped I guess!!
@onyx harness I have another question, piggy backing from the previous solution. If my field is [SerializeField] private can I (from the custom editor) update the value using Reflection? If so, would that persist between C# and C++?
I am assuming Reflection is a parallel concept to what SerializeProperty does?
Or is that just bad practice?
yes
Reflection is just toying with the managed side
It is the same as assiging a value to target
Exactly the same
Oh ok, So Reflection doesn't touch C++ at all huh?
Nothing related yep
Understood.
Was just trying to see if I can eliminate the property that set that non Unity object value whilst keeping it private
Eliminating it is easy, you just need to assign its fields directly
In your case, the property is handy
Agreed.
So from what I gathered. I can setup a bunch of items, and if any of them are changed I can make a bool dirty to true. Then at the end I can update, set dirty, and apply? Or do I need to update after each item?
Yes, you can update and dirty at the end
No need to apply, since apply is for SerializedProperty
I added a bool, and it’s not changing. I’m reading it serializedObject.boolValue and setting it the same way with Apply at the end. Now I feel like an idiot because this is basic stuff lol. I won’t bug you with this before I try everything out first though.
Ok, I figured out what the issue was, but I can't understand why.
if I directly do this:
p_isActive.boolValue = EditorGUILayout.Toggle("Is Active", p_isActive.boolValue); The changes persist.
But if I indirectly do this:
bool activeState = EditorGUILayout.Toggle("Is Active", p_isActive.boolValue);
if (activeState != p_isActive.boolValue)
{
p_isActive.boolValue = activeState;
var map = inputMaps[activeMapIndex];
if (activeState)
map.Enable();
else
map.Disable();
dirty = true;
}
The bool doesn't update in inspector. I verified that the if statement actually does get triggered (via debug log), so I know for sure that p_isActive.boolValue = activeState; get's processed. But it doesn't persist!
What is the difference between this and directly doing it?
Keep in mind I need to "watch" this change so I can modify the map state.
FYI, With the indirect option, everything else persists as it should.
Also, another FYI, I am ApplyModifiedProperties at the end as well. That gets called for sure.
I got it to work with the following solution. But I feel it's a bit "dirty", can you suggest something I'm missing, or is this the only way to go about.
bool activeState = p_isActive.boolValue;
p_isActive.boolValue = EditorGUILayout.Toggle("Is Active", p_isActive.boolValue);
serializedObject.ApplyModifiedProperties();
if (activeState != p_isActive.boolValue)
{
var map = inputMaps[activeMapIndex];
if (p_isActive.boolValue)
map.Enable();
else
map.Disable();
dirty = true;
}
Figured it out! So the issue was that it was updating correctly, however when I called serializedObject.Update BEFORE ApplyModifiedProperties(), it would retrieve the serialized state and overwrite the managed side. So I misunderstood the purpose of those two methods. Turns out Update will overwrite the managed state with whatever values are currently stored in the serialized version, and Apply will persist whatever values are in the current managed state overwriting the serialized state.
Ok. New question. I don't really know how to even search for this online. I am using NaughtyAttributes plugin, which has a BoxGroup("GroupA") attribute for a property. How would I keep it's current behavior if I overwrote a class with my own custom editor script? Or does this mean I have to write that behavior myself as well?
Is there a way to 'pass through' existing attribute behavior through my custom editor script without having to reinvent the wheel?
Depends on the implementation of NaughtyAttributes
There's probably something that you can inherit from that'll have the base behaviour for those groups
can someone help with merging asset bundles manifests from different machines (submodules) into one manifest? https://forum.unity.com/threads/combine-manifest-from-asset-bundles-into-one-large-manifest.1011334/
I explained that earlier in our discussion, but glad that you faced it directly and really understand it
Is there any easy error dialogue function in Unity?
Something like JS's window.alert
Just for editor
And it was because of your explanation that I was able to figure it out. Big thanks my man.
I was wrong when I replied "Yes", I misread your statement due to UPDATE and Update()
I mean.... it was right or wrong depending on what you were doing
Yeah I figured. It was because of my miscommunication. And I commend you for admitting mistakes. I have great respect for people like that. 🙂
Hi, I am experiencing a little problem let me explain : I got a struct called AABB, on my code everything work fine, but the unity editor is "drawing" it in the editor as the struct -> https://docs.unity3d.com/Packages/com.unity.entities@0.1/api/Unity.Mathematics.AABB.html rather than my custom struct
Any idea about how to make my struct drawed ?
[Serializable]
public struct AABB
{
public int X;
public int Y;
public int Width;
public int Height;
}```
the struct itself
Are you trying to “overwrite” unity’s AABB struct?
Yes I am
In my code, it is totally fine, c# understand that he need to use my overwritten version
but unity editor don't, and he then draw the original AABB struct
Now, please correct me if I’m wrong, but the unity editor is not reading the struct directly, it is reading the Custom Property Drawer that is referencing the Type AABB. I think you should play around with that and see if it will affect the struct in the inspector.
Haha maybe I should have mentionned that I am not really familiar with how the unity editor handle drawing
If I understood what you said, the editor see that my struct is called "AABB", so it draw the properties of the AABB struct it know, which in my case is not the right one ?
Is it possible to "overwrite" the Custom Property Drawer like you said ?
Yes it is. That’s what that’s there for. Type in unity custom property drawer in google and you’ll get the api description.
There is a little more to it though, you’d have to learn a little about editor customization, it’s not as straightforward was the player monobehavior code structure. But once you grasp it, it’s very simple.
Ok, so I need to create a CustomEditor ?
Fine, I had plan to create one anyway, to learn how CustomEditor work ^^
Thanks for the help !
No. I don’t think you will need custom editor. Custom editor is for customizing the entire component in inspector. You’re just looking to customize the property. If you use custom property drawer, then that property will be drawn your way across ALL components, custom or standard. Does that make sense?
Oh I see, i just went to the doc and I guess it's now clear in my mind
It'll draw for all properties of that type
I've never heard of a property drawing rendering UI for a type with the same name
fields*
^
Anyways, without more context it's hard to know what's going on in your case @near jewel
Unity sometimes lookup for string instead of Type. It happened once for an attribute, I saw that.
But you're right, I don't remember them doing it for PDrawer
@waxen sandal woups I literally forgot the screenshots
Here is how my struct is drawed in the editor
What's probably happening is that your Hitbox field type is resolving to Mathematics.AABB rather than your AABB
There you go, now the experts come out 😛 sorry if I mislead you.
Yes that was my conclusion too, I guess i need to create a custom property drawer to overwrite ?
No, you need to make the type of your field your type rather than the mathematics type
Give it a simple test workaround, just renamed it AABBC
Did it already, work like a charm when renamed
Ok
I have no idea how to do this to be honest
When renamed it look like it should :
Easy way is to remove the unity.mathematics using
The slightly harder way is to do namespace.aabb in the field type definition
Well the problem is that I am not using this namespace
The AABB already have a namespace, even when it is precised, unity editor still draw the wrong "AABB"
Can you post the code to the entity script?
namespace Physic
{
public class Entity : MonoBehaviour
{
// [HITBOX] \\
public AAB hitbox;
public AAB WorldHitbox => hitbox + transform.position; // Represent the hitbox relative to the position
// [COLLISION] \\
public bool Collidable; // Can we collide ?
protected bool IntersectWith (Entity other, Vector2Int offset)
{
return other.Collidable && (WorldHitbox + offset).Intersects(other.WorldHitbox);
}
protected bool IntersectWithAny<T> (Vector2Int offset) where T : Entity
{
return EntityLister.instance.physicEntity.Any(_entity => IntersectWith(_entity, offset));
}
private void OnDrawGizmos ()
{
Gizmos.DrawWireCube(transform.position + new Vector3(hitbox.X, hitbox.Y), new Vector3(hitbox.Width, hitbox.Height));
}
}
[Serializable]
public struct AAB
{
public int X;
public int Y;
public int Width;
public int Height;
public AAB (int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public bool Intersects (AAB rect)
{
//return (X + Width) > rect.X && (rect.X + rect.Width) > X && (Y + Height) > rect.Y &&
// (rect.Y + rect.Height) > Y;
return (Mathf.Abs(X - rect.X) < (Width + rect.Width)) &&
(Mathf.Abs(Y - rect.Y) < (Height + rect.Height)) ;
}
public static AAB operator + (AAB a, Vector2 b)
{
return new AAB(a.X + (int)b.x, a.Y + (int)b.y, a.Width, a.Height);
}
}
}```
I renamed it to AAB to make it usable
What about the usings?
No need for using
I got this behaviour on Unity 2018.4
Any struct named AABB will be drawn like that
The fields inside don't even matter
using System.Linq;
using UnityEngine;
Ah, glad to see I am not the only one
Have you managed to fix this problem ?
Unfortunately it seems to be a bug in Unity side
I suspect propertyType returns Bounds for any fields named "AABB"
Unfortunately, this method is C++ side.
So actually the only solution now is to make a custom property drawer ?
As a fix, just rename your struct and remember to not use a name used by Unity.
CP won't bring you much except having the name AABB
Yeah right, thanks for the help and answers everyone :)
At some point it DID randomly change to left shift though, after it showed joystick7 before. I'm very confused how that happened, and why it doesn't happen now.
How come I cannot access public properties on my ScriptableObject?
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
AttackSO attackSO = (AttackSO)target;
GUILayout.Label("Does this attack depend on direction?");
target.directional
}
public class AttackSO : ScriptableObject
{
public bool directional = false;
directional doesn't exist on target
also how could I serialize something like this
in a custom editor script
I thought I casted it
Instead use attackSO.directional
ohhh
Yeah
So am I limited to the field they provide? Can I not show fields for classes that isn't default unity like ClipState.Transition
You are not limited. If they don't have (by default) what you are looking for, you can create your own. That is the whole point of customizing editor.
Oh well I just want to make a simple show these if this bool is on, and these classes already have stuff that they do when they are serialized
I just want to equivalent of what it looks like when you would normally serialize them but just wrap it in an if statement so they don't always appear
OnInspectorGUI()
{
bool serialziedObject.FindProperty("conditionalToggle").boolValue = EditorGUILayout.Toggle(serializedObject.FindProperty("conditionalToggle").boolValue);
if (conditionalToggle) {
// draw the stuff you want shown here
}
// otherwise they will NOT appear
}
something like this?
Yes, except the opposite, I have the bool field, I just want to draw the properties if that bool field is true
Someone help me out here, am I not understanding this guy correctly or what?
I want to know how to display these
on my scriptable object
in an editor script
I only know how to display stuff like GUILayout.Label, button ect.
Have you tried EditorGUILayout.ObjectField ?
no but that's probably it, I assume serialized property is found using FindProperty?
Yes.
Oh you want the ObjectField to be constricted ONLY to ClipState.Transition objects?
I'm not sure, I just want to draw them, I got close too but the drawing doesn't look like what it does when you serialize them
Canyou give a more specific example of what you mean by "draw" them?
This is how they show up when you put [SerializeField] next to them in a normal script
I just want to be able to show that in my editor script
Then you probably need to look at Custom Property Drawers
Could anyone point me to the API docs for interacting with menus in the top-level ribbon? (File, Edit, Assets, etc.)
Sorry, maybe not. I think that the component it's showing up as has a custom editor that shows it that way.
It's simply a foldout with floats and bool fields
I think I've found the property drawer I need, I'm just not sure how to use it
https://kybernetik.com.au/animancer/api/Animancer.Editor/TransitionDrawer/
I wish there was just an easy function that was like DrawThisLikeInInspector(Property);
lol
You know, that's a great question. Don't settle on my answer, I'm a n00b compared to some experts here (cough @onyx harness cough @mellow oar cough @waxen sandal). So you are trying to write a custom editor but draw an existing property drawer without having to "redraw" it yourself. If you figure this one out, please do let me know, I would sure like to know the answer to this one meself 😉
Doesn't that draw everything though right?
@brittle acorn UnityEditor.Menu
You can specify which properties to exclude when drawing
I've been known to be severely lazy. And to replace like... ALL of my easy to replace properties in INspector... and then to leave things like Array sand other crazy stuff under the DrawDefaultInspector(); function
DrawPropertiesExcluding
@onyx harness has a better answer than I
How much do you want to have custom inspectors?
pressing bool to show more options is fancy
I've done that.
Oh wow, When did they introduce DrawPropertiesExcluding method? That is extremely powerful! @onyx harness
It's so convoluted, maybe it's just inexperience but it's so weird how you cannot just draw a single property like it's shown normally with one function and not an array of every other property
Unity is getting better and better with their Inspectors (though they're still not nearly as good as Odin Inspector)
Since beginning of Unity (https://ngtools.tech/ngunityversioner.php?t=UnityEditor.Editor&m=DrawPropertiesExcluding())
Only reason I didn't buy Odin Inspector this sale is because I saw a tut on UnityEditor basics and I was like "Surely this won't be a weird as hell system and just let me do what I want simply"
lol I failed hhaha
No. It's weird as hell.
❤️ odin
Anytime you're operating outside of Monobehavior, you're going to be burning brain cells on things you swear should be simple. Llike shivers arrays.....
Arrays should not NEARLY be so blooming difficult to show in a custom inspector. But they are....
Anyhow - https://catlikecoding.com/unity/tutorials/editor/ This is a pretty schweet site for learning Editor. Have fun
speaking of simple things, is there an easy way to assign a keyboard shortcut to just open the Asset menu?
You mean the asset store? Because that's Ctrl+9
catlikecoding editor tutorials are a bit old, but still do the job
eg. I'd like to be able to create a new shader without having to touch my mouse, but also without assigning 5 separate hotkeys to surface/unlit/image effect etc.
Oldies but goodies.
Not that I'm aware of.
I assume I'm grossly overlooking something because it seems like a pretty common use-case
Alt + A ? Can it ?
^ that was it
I think I'll just abandon fancy bool expanding
OH you mean the toolbar "Asset" menu. I'm a dunce.
There's also that plugin from Unity that lets you search for actions/assets
I forgot what it's called
Odin Inspector has a Show If attribute too
QuickSearch?
ALL HAIL ODIN!!!!
I know but I already spend like 70 eur on asset store
Okay I'll quit being annoying
cannot get Odin
awww.
Odin isn't that great imo
thanks again @onyx harness
It will always have a warm place in my heart. But I do not discriminate! What do you prefer? And yes the devs are SUPER active in the Odin Discord
^
Odin is great for people that don't want to do editor scripting
Which I'm not
I love doing editor scripting
Before a mod comes here, @mellow oar I have to tell you that meme are not authorized here (not my choice :))
I switch between the two as needed. I just find Odin saves me time. It's the difference between writing maybe two or three attributes in a single script versus having a whole new script with 30+ ;ines of code
Yeah I keep forgetting that. It's dumb. Memes are life.
It's almost a double-edged sword
I want to know why the murdered the memes though.
You realize you can do all this cool stuff "easily" and then you've spent the entire day prettying up your editor and done nothing on your actual product
That too also dependson what you're doing or why you're doing it. My job is specifically to help marry the crazy thins our C++ programmers are doing in the backend to things that psychologist, researchers, and interaction designers can actually understand, so they too can use the tools the programmers are making. And a good Inspector seems key to that
for sure, that's adding real value
If you don’t want to spend money on plugin, you can use NaughtyAttributes plugin. I use it all the time.
but if you're just a solo dev and no one is ever going to see this but you
hypothetically...
true
Well in that case, yeah you're right. I don't do custom inspectors in my own dev work.
Okay maybe a little customization here or there. Actually.
But not like I do at work
Give a try to NG Tools Free, you might discover things
Ads keep getting more intrusive 😛 /s
HAHAHAHA
I knew you would be around XD
Well, as long as it is free 🙂
Yeah for sure, you actually do good work
I don't know if I ever showed you, but I made replacement for Sabresaurus API versioner:
https://ngtools.tech/ngunityversioner.php
Saw it in slack yeah
Navi are you the owner/maker of NGtools?
Oh snap!
And I can't even throw in a meme showing Wayne and Garth bowing down to you @onyx harness
No worry, it's all received 🙂
You know, I tried your api versioner before and somehow I couldn't figure out how to use it. I must be a big dummy
works perfectly now though
Can you replace the current api versioner with @onyx harness's one?
@visual stag ^
n00b question that I probably should be embarassed to ask for but. What do you mean API versioner?
Because I implemented lookup for Type/Member later. It became more intuitive at this point. Before that, you had to type in the Type then the Member, not much more difficult, but less intuitive nevertheless
Ah might've been it, thanks
Very handy for Editor scripters
Turns out it's actually really simple
EditorGUILayout.PropertyField(serializedObject.FindProperty("attackAnim"),true);
You just put true there
and it draws children
Wow I did not know about PropertyField. Thanks for the info! Glad you shared that with me!
how do I have optional dependencies?
i'm working on a package that i want to integrate with a dependency but only if it's available
and i don't want the using definition blowing up those that don't
i'm trying to use CCU
but doesn't seem to work
Hi!! I am using a ReorderableList to show and edit a list of objects (represented by a serializable class)... one of the properties of the objects is a scriptableobject... the list shows everything all right, i can add, remove, reorder without problems.. but the scriptableobject property doesn't work fine, I can drag assets of that type into the field but when I show the object picker and select the asset there nothing works... anyone aware of this problem?
thanks in advance!!
If I disable the editor and use standard list in inspector, the object picker works just fine
Is it possible to show a list of components that can be added adjacent to the selected element (2D)? Like in flowchart editors, draw.io etc.
So you put an element and click on arrows or whatever on its' sides and it will show some list of elements that can be added here. I know how to create an element on scene via extension, but not sure if it is possible to show such menu. Is there any extensions doing something similar?
private void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
{
SerializedProperty deckEntry = _reorderableList.serializedProperty.GetArrayElementAtIndex(index);
rect.y += 2;
SerializedProperty amount = deckEntry.FindPropertyRelative("amount");
SerializedProperty card = deckEntry.FindPropertyRelative("card");
string title = (card.objectReferenceValue == null) ? "Nueva carta" : card.objectReferenceValue.name;
EditorGUI.ObjectField(position:
new Rect(rect.x += 1, rect.y, Screen.width * .8f, height: EditorGUIUtility.singleLineHeight), property:
card, typeof(Card), label: new GUIContent(title));
}
Cant be more simple, there is where I render my scriptable object (Card)
"render my list elements" sorry, the scriptable object is the Object field
good... i will try that
let you know if it works... thanks!!!
mmm card it's a serializedproperty, it looks that Editor.ObjectField returns void
How can I have a free move handle which also track when it's clicked? Using Handles.FreeMoveHandle + Handles.Button doens't work (because one handle is build on top of the other hidding it from the screen)
Probably it was some knid of bug, I was working in 2019.4.13f1 and have upgraded to 201.4.15f1 and now it works correctly
Anyway thanks!!!
This is only when you want to draw ONE specific field.
Of course in your case it works well, but the Excluding is made when you want to handle all but one (I know what I'm writing is obvious)
Yes
Can you remind me why DrawDefault does not work?
Because I don't want to draw everything, and making an array with every other property makes no sense when you can just do this
Should not be capturing when there is a hotcontrol
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
Keep getting this and Google have been unhelpful. It happens when I try to expand my custom component. I'm trying to use inheritance with Unity Editors. But I want to hide away the Camera component that I need completely so it can only be access programmatically. This is because I wanted to originally extend the Camera class, but I can't do that because it's sealed =_=
So this is my abstract class. It just holds all editable fields on a standard Unity Camera. It's my way of getting around the "hide in editor" part.
public abstract class SeeThruInspector : Editor
{
...
public override void OnInspectorGUI()
{
And then I make an editor which can edit the fields of my own code only. This way I can make many different cameras and have them all use the same base editor, because they will all have the same base camera properties...
[CustomEditor(typeof(FreeFlyCamera))]
[CanEditMultipleObjects]
public class FreeFlyCameraInspector : SeeThruInspector
{
...
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
...
serializedObject.ApplyModifiedProperties();
...
What could be the issue?
To hide a Component, wouldn't you just need to set the hideFlags?
I am already successfully hiding the camera
But the issue is that I also want to be able to still edit it via the inspector
So what I came up with was just to make an abstract class that holds all the values a camera normally has exposed in the unity editor
Then make a component that extends it
This works great, but it doesn't hide the actual camera component in the editor
So to get around this, I'd have to do the custom inspector stuff
Sorry I think I don't understand
Can't hiding the Component Camera done via hideFlags?
but it doesn't hide the actual camera component in the editor
Based on that ^
I want to make cameras in unity. A package of different ones like FPS camera, free fly camera, etc.
But I also want it to feel native to Unity. So to do this I'd just extend the Camera component right?
Well I can't do that, because the camera class is sealed. So what's the alternative?
Well the alternative is to hide away the camera component via a custom editor. That should be easy enough right? It is! But the issue is then that I still need to be able to edit the cameras values.
I can't do that since the camera is hidden...so what do? My solution is to simply copy every single field that you can edit on a camera over on my new component, then apply the changes you make to that component in the editor to the hidden camera.
But I run into issues because when I try to change my component values nothing actually changes.
I just get that error all the time
Should not be capturing when there is a hotcontrol
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
Hiding existing settings is exactly what I don't want from a tool. I would recommend against it. Instead, design through composition. Leave the camera as is, add an 'FPS Camera component' that has a nice editor and settings imo.
Bigger picture, if this is for other users you may want to think about working with cinemachine as that's what a lot of people use.
You would still get all of this. That didn't change.
The camera component is just hidden in the inspector
I wouldn't want a script that extends Camera.
Why not?
because I prefer design through composition - the way the rest of Unity works
It's very cluttered
? I'm talking about the arrow you can use to collapse a component
Hm okay
I want the Cameras I make here to feel native to Unity, rather than some addon thing.
what have you seen that's native to Unity that hides existing stuff? Check out cinemachine if you haven't already.
Shapes by Freya
For one
A lot of stuff happens behind the scene when you use those
It's a completely legitimate thing to want for editor extensions
Or rather
Let me rephrase
Shapes feels native to Unity
Oh do you want a collapsible header for unity camera
Exactly because a lot of the stuff you don't have to worry about as a user is hidden away
bingo
I don't
I want it to not be seen in the inspector
just none of it?
I remember someone showed me something, and you can do Editor.show or whatever but specify an array to not show
If you really want to duplicate every important setting in the cameras.. go for it. Sounds like a terrible idea to me personally. Because every setting is important. Especially given the variation between the pipelines and forward/deferred etc.
Well that would just be part of doing this really.
I appreciate that you mention these other things Timboc, but I'd like to try and find a solution to what I am trying to do 🙂
Yesterday, yes.
Custom tools are important. Keeping things uncluttered is great. Hiding existing settings/functionality I'm really not a fan of.
I think you misunderstand then
Because the original functionality is not gone
It's simply put on my component while hiding the camera
The user experience is going to be the same.
You can even drop the component into Camera spots
If you needed to
If you duplicate all existing functionality... why not just leave the Camera component and use composition to add the additional customisation you want.
Because it's cluttered 🙃
how is it more cluttered if you duplicate all the settings? It's less cluttered because you can separately collapse the normal camera settings?
One thing I dislike about Unity's composition approach is that the ordering of things is completely arbitrary and unless you enforce it yourself will end up having a bunch of components all over your gameobjects in no orderly fashion whatsoever.
To lessen the burden of using these more specialised cameras I want to hide away the Camera component that Unity doesn't let me extend.
So from a user perspective it will be just like using the camera you are used to + extra fields for customisation
👍
I mean if I wanted to I could probably just make groups in the inspector and then that would be that no?
Hi! how can i show a property on the editor?
public bool selfShadows
{
set { m_SelfShadows = value; }
get { return m_SelfShadows; }
}
i know i can use a field, but i have to do something when this property changes
So given the below, the actual camera does get hidden from the inspector. Problem is, I can't actually edit my own component. I just keep getting the same error that I posted originally.
Should not be capturing when there is a hotcontrol
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
public virtual void OnEnable()
{
Camera target = serializedObject.targetObject as Camera;
target.hideFlags |= HideFlags.HideInInspector;
}
public virtual void OnDisable()
{
Camera target = serializedObject.targetObject as Camera;
target.hideFlags &= ~HideFlags.HideInInspector;
}
@paper orbit I think GUILayout.BeginChangeCheck() should help with that
Unfortunately for us, you show us code, but so little that it is almost like you shown nothing
Okay, then ask for more code if that's the issue 🙂
Go on
What would you like to see then?
The abstract inspector?
The inspector extending it?
The component I try to make the inspector for?
The abstract component it extends?
There is just quite a bit of code here so I didn't want to bombard the chat
I guess the nature of the bug and perhaps the entire Editor code?
By nature, when you stated "all the time", it needs clarification
Because I read "every frame", but is it?
Or maybe it's on a click? When you unfold? Open a popup? (Like color picker)
When I click the component to expand it or when I click any field in the editor for that component
I get the error
Does it happen on a key down?
It's not every frame it's just every time I click anywhere on the component itself in the editor or try to expand/shrink it
No, nothing triggers on key down
It's your clicking that's causing the error..
What other Component do you have on the GameObject?
You've got some kind of custom editor that relies on mouse event but are modifying it before other scripts can properly address the event.
Show us some Editor code, might ring a bell
Alright, give me a sec
That's why you're receiving the hot control error
Any idea how can I fix that (see picture below)? Fields are not auto-resizing to fit the screen.
I'm using:
try
{
Handles.BeginGUI();
GUILayout.BeginArea(new Rect(0, 0, 300, EditorGUIUtility.currentViewWidth));
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginVertical(GUI.skin.box);
// [...]
EditorGUILayout.LabelField(OBJECT_CONTENT, OBJECT_LABEL);
// [...]
EditorGUILayout.LabelField(PATH_CONTENT, PROPERTY_PATH_LABEL);
// [...]
EditorGUILayout.LabelField(PROPERTY_CONTENT, PROPERTY_NAME_LABEL);
// [...]
EditorGUILayout.PropertyField(selected.serializedProperty, RELATIVE_POSITION_CONTENT);
// [...]
absolutePosition = EditorGUILayout.Vector3Field(ABSOLUTE_POSITION_CONTENT, absolutePosition);
// [...]
EditorGUILayout.Vector3Field(REFERENCE_POSITION_CONTENT, reference);
// [...]
if (GUILayout.Button(CLOSE_BUTTON))
// [...]
}
finally
{
EditorGUILayout.EndVertical();
if (EditorGUI.EndChangeCheck() && selected != default)
selected.serializedProperty.serializedObject.ApplyModifiedProperties();
GUILayout.EndArea();
Handles.EndGUI();
}
I could understand as much from goolgeing as well but I couldn't find any kind of solution to it
You can fix it by providing a GUIOption.Width(EditorGUIUtility.currentViewWidth)
Here is the Abstract Editor - SeeThruInspector: https://pastebin.com/fyaJwqCA
Here is the Extending Editor - FreeFlyCameraInspector: https://pastebin.com/CFuAFLKy
SeeThruCamera is the component I made to hold all the Camera fields. The FlyFreeCamera is one that extends it to add all the extra fields that I want. If you need those too let me know.
You mean remove GUILayout.BeginArea and put that inside EditorGUILayout.BeginVertical? I'll try
Nope, keep BeginArea
@real meadow This chunk will never draw
ChangeCheck is a one time operation.
Which means
(It is not related to your issue above)
GUIOption doesn't exist 😦
Meaning when UseAxis changes, it will draw your Horizontal/VerticalMoveAxis but, just for one frame
@burnt dove GUILayout.Width
@real meadow Reduce your code to one single PropertyField. And uncomment one by one, until you find the culprit
Just to give an image of what it is I'm trying to achieve
Okay will try that @onyx harness
I wasn't able to fix that with GUILayout.Width, thought removing EditorGUILayout.BeginVertical did fix it... but now I don't know how to the background color to gray (previously I was passing GUI.skin.box to that method) 😦
@burnt dove If you just want to draw a background, just use GUI.skin.box.Draw() (on event Repaint only!)
Ok, I'll try
It doesn't seem to matter what I do @onyx harness .
The error keeps popping up
empty one?
It works @onyx harness, thanks!
@real meadow Have you think about drawing Camera's Editor directly into your Editor?
I have tried that yes, but that's a lot more cumbersome than an inspector isn't it?
Well, i feel it is way quicker than your way
You just get the Editor, and call DrawDefaultInspector().
you won't want the default? You call DrawPropertiesExcluding().
When you started to talk about overriding Camera, I thought you did that
And then I saw your code and saw several FindProperty and their PropertyField
Much less sustainable in the long term
So I just discovered something
No matter what I do, the hot control error pops up
I just made an inspector that only hides the camera and nothing else. There is no inheritance used here.
What about unhidding the Camera?
Component
[RequireComponent(typeof(Camera))]
public class FooCamera : MonoBehaviour
{
}
Inspector
[CustomEditor(typeof(FooCamera))]
public class FooCameraInspector : Editor
{
FooCamera self;
public void OnEnable()
{
self = serializedObject.targetObject as FooCamera;
self.GetComponent<Camera>().hideFlags |= HideFlags.HideInInspector;
}
public void OnDisable()
{
self.GetComponent<Camera>().hideFlags &= ~HideFlags.HideInInspector;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
serializedObject.ApplyModifiedProperties();
}
}
This does not work. It gives you the error I pointed out
So I have a suspicion that this is a Unity bug.
Even with OnInspectorGUI totally empty?
yep
Then it works. I can expand and minimise the components
But of course
Now the camera is not hidden anymore
There are other solution
Like directly removing/hidding the Component Camera from Inspector via UI Element.
Not sure what you mean
https://twitter.com/_Mikilo_/status/1261383803060142080
I did this, I inject myself directly into Inspector
Revisiting the Inspector (Poke me to join the future open beta of NG Flow Inspector)
#madewithunity #indiedev @AssetStore #unity3d #gamedev #ngtools https://t.co/gB74rQwqqE
The same way, you can remove/hide (opacity: 0, or height: 0)
So Instead of hiding the camera component with hideflags, it would be hidden by changing the components header opacity to 0?
Because opacity just hide it visually, but the area is still taken
Hm okay. I guess that could be an alternative at least.
Well, if it is not visually clickable, perhaps not
Not a super destructive way either so, that's nice.
yep
How would I do that?
Ah..
Q() is your best friend
Use the UI Toolkit Debugger
Q() is the equivalent method of FindProperty() if you like
So instead of FindProperty() you just write Q(...) ?
Like jQuery $()
Right
$ is the jQuery scope.
But even if that is an alternative to do this, it would still seem that I found a Unity bug which is easy to reproduce.
But thank you for the help @onyx harness
It didn't have a satisfying ending, but at least I know that I'm not insane now
It really does seem to be a Unity bug
report report
I was this was the place to go for my issue... For some reason my Int[] on my scriptableobject keeps getting reset
Got a custom editor?
yeah
Show code
there are a lot of chunks commented out because they don't work
I'm using ProtoTile protoTile = (ProtoTile)target;
I don't have any attributes on the scriptableobject
It's best to use serializedproperties
Use hatebin.com for large code blocks
Not using serializedproperties?
yeah
I know it does save.. most of the time
or is it because I'm not using serializedproperties whatever it's doing is.. unstable?
Your data is sometimes getting saved as a side effect of something else in the editor happening
because when I look into the asset file it's just a long series of non binary numbers
oh, so it's not supposed to work lol
ok, I'll switch it over and see what it looks like
In editor you shouldn't directly modify an object
I see
before I go and do that, I have one more issue
Wait, would questions about the AssetPostProcessor go here too?
Or is there another channel that might be a better pick
Yes, here is fine
So I have this asset post processor
you reimport a sprite sheet, it slices it, then creates a scriptable object
you can ignore the scriptableobject creation bit, the issue is with the sprites
textureImport.spritesheet = metaList.ToArray() throws an exception every time
yet it still works
let me snag the exception
InvalidOperationException: Sequence contains no matching element
System.Linq.Enumerable.First[TSource] (System.Collections.Generic.IEnumerable1[T] source, System.Func2[T,TResult] predicate) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
UnityEditor.U2D.Animation.SpritePostProcess.PostProcessBoneData (UnityEditor.U2D.Sprites.ISpriteEditorDataProvider spriteDataProvider, System.Single definitionScale, UnityEngine.Sprite[] sprites) (at Library/PackageCache/com.unity.2d.animation@4.2.6/Editor/SpritePostProcess.cs:107)
UnityEditor.U2D.Animation.SpritePostProcess.OnPostprocessSprites (UnityEngine.Texture2D texture, UnityEngine.Sprite[] sprites) (at Library/PackageCache/com.unity.2d.animation@4.2.6/Editor/SpritePostProcess.cs:29)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9577ac7a62ef43179789031239ba8798>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <9577ac7a62ef43179789031239ba8798>:0)
UnityEditor.AssetPostprocessingInternal.InvokeMethodIfAvailable (System.Object target, System.String methodName, System.Object[] args) (at <20b79eb59c0f467d8b1106b2110bc953>:0)
UnityEditor.AssetPostprocessingInternal.CallPostProcessMethods (System.String methodName, System.Object[] args) (at <20b79eb59c0f467d8b1106b2110bc953>:0)
UnityEditor.AssetPostprocessingInternal.PostprocessSprites (UnityEngine.Texture2D tex, System.String pathName, UnityEngine.Sprite[] sprites) (at <20b79eb59c0f467d8b1106b2110bc953>:0)
there is something in the internal part of unity that doesn't like that metalist
Is textureImporter.spritesheet empty maybe?
it shouldn't be... (TextureImporter)assetImporter should provide a reference
let me check in debug real quick
You should really just open the source code of that package and see what it's doing at that line
It's expecting some data in an array/list but there isn't any
the array I'm providing it is valid. There must be some sort of optional data I'm not providing it
I need to see what the spriteDataProvider is, but it seems I can't lookup the definition
Yeah that's why it's best to look at the source of SpritePostProcess:107
SpriteRect spriteRect = spriteDataProvider.GetSpriteRects().First(s => { return s.spriteID == guid; });
so I can see that spriteDataProvider has all of the sprites in an array
but I can't see the GetSpriteRects() method
Sounds like you need to do something else with those sprite rects that you have
Not sure what though
That class might be in the reference source on github
reference source?
It's not there unfortunately, but that will be useful for later things
it looks like there is a guid mismatch somehow
the sprite array provided has guids that don't match the sprites in the ISpriteEditorDataProvider
maybe it has to do with the order at which I'm setting this up, I don't see anything I can feed a guid so maybe it's generating it's own because it's not defined somewhere
I'll pick that one back up later, at least I have a better idea of what avanue I need to fix it
now to implement that serializableproperty or whatever it was
Thanks @waxen sandal
If I want to make a Custom Property Drawer, is there a way to specify that if a component has it, that it is always drawn last (at the bottom) in the inspector? Or controlling the order of drawer display is something that can only be managed from Custom Editor?
Only from Editor
Dang. The reason I'm asking is because I am using NaughtyAttributes plugin, and they have an attribute called BoxGroup, and if you box group anything, it gets displayed at the end, where as without it, they are displayed in the middle (if they aren't last in the order). I thought that was cool, and thought if there was a way to do this without a custom editor script.
Oh maybe it's not an Property Drawer type deal, maybe I need some Attribute? If that is not something natively built in, could I make a custom attribute that can do that?
Custom Property Attribute to defer the drawing to the end?
Yeah. I mean how does NaughtyAttributes.BoxGroup get away with it?
I don't know, read the source you might extract some clues
TBH, I don't know where to start looking.
Odin has a feature specifically for this. So I know this is possible.
https://odininspector.com/attributes/property-order-attribute
PropertyOrder is used on any property, and allows for ordering of properties.
Use this to define in which order your properties are shown.
should I not be initializing my arrays on my class and instead initalize them in the CustomEditor?
that and I just don't understand how to use the serializedproperty
I've read a fair amount about it, but it's not clicking
lol
Please don't bring Odin in here, their features are nothing related to Inspector
It's like 2 different worlds
Oh really? They don't use custom drawers / editor?
And draw everything themselves
Oh wow. Ok
Therefore they have this power
Now I understand.
It can be true, but you would need to make your own Editor
lol too much work! haha
And then from there, you'll have the same amount of power as Odin
What Odin does is nothing extraordinary, but they did it well
Have to see if NaughtyAttributes did the same thing, but I have a feeling they didn't. I think they actually used Unity's drawers/editor scripts
They didn't do the same as Odin, as far as I know. I could imagine ways for them to still control ordering, though.
Yeah if someone has any resources or advice on how I can go about property ordering without writing a custom editor for every component, I'd be thrilled to hear it 🙂
You'd need to write a custom editor that is written in such a generic way that it could handle any component.
That's already what NaughtyAttributes does. And what Odin does, though our method of doing it is a bit different.
Hmm...well most of my components derive from UnityComponent which inherits from MB. UnityComponent is my own base class that I use that implements are more dynamic controlled debug logging that I can control on the fly. I have some other features I will be adding to it.
What you're saying is that if I want to do this, then I can write a custom editor for UnityComponent that can take care of that and draw everything else Default?
This is for that class actually, because it had debug toggles (bools) that I want displayed always at the bottom of any component that inherits from this class. So it doesn't interfere with the fields that the inheriting component will declare. Does that make sense?
Yeah, that's possible to do. It would take a bunch of reflection and custom scripting though, depending on how you want to do it. And also if you want to still have something like NaughtyAttributes work.
But maybe there's a reason they haven't done it.
Not sure, to be honest.
Working within the Unity Way of doing things can be tedious in the most surprising ways.
This I learned the hard way, as I'm sure you have.
Well, yes, I found it so tedious that I wrote Odin after all 😄
Well I use NaughtyAttributes BoxGroup specifically to put my debug controls at the bottom. It works great. But the problem is when I create a custom editor for a component that inherits from UnityComponent, and then it doesn't "pass through" the BoxGroup attribute feature.
Unity Inspector lacks of pretty much everything, in every direction, in every way, but it works
It would be a lot easier if there was a way I can like "forward" the NaughtyAttribute.BoxGroup into my custom editor without having to write the same behavior on top.
Modifying the source code of the original is probably the easiest option.
I don't see how that will be a solution as when I CustomEditor it overrides all attributes over that particular component...no?
Well, you'd modify the original to add ordering to it.
Or just ordering for your specific case.
Hmm... 🤔 Ok. I'll see what I can figure out. Thanks for the tip.
How come we talk about Odin and you suddenly appear like you were summoned?
lol
I thought that was perfect timing 🙂
I think they have supernatural dev powers
how do I use complex types like sprite as a serializedproperty?
I imagine I don't cast the resulting object do I?
I lurk in several places, I just happened to come by right now 😄
@naive canopy That's exactly what you do, as far as I know.
like this?
SerializedProperty sprite = serializedObject.FindProperty("Sprite");
(sprite)sprite.objectReferenceValue
Yes
ok that's all setup then
EditorGUILayout.EnumPopup((SocketTypes)sockets.GetArrayElementAtIndex(i).intValue);
it renders the enum correctly
but I can't change it
Gotta get the new value back out of the method. It's the return value.
ohhh
Quickie: Does unity provide a GetSessionID in between each play mode sessions? Or is that something I'll need to cook up?
Just something you can cook up, I think. But I might be wrong.
I think so too, it's easy, I just wanted to make sure I'm not reinventing the wheel.
Maybe you can look at Time
it might restart stuff to 0
Or hook to any event when the game stops
I used GetArrayElementAtIndex to get the value, but I don't see a way to do that for assignment...
No. I have this bug that I'm trying to track down. And apparently gameobject GetInstanceID persists over sessions. So I want a more unique way of identifying if that GO being references is from current session, or from last session. Getting NullReferences, I suspect it's because it's saving them somewhere in memory without wiping them when I exit play mode.
You got it wrong, you do GetArray then uses intValue, you need to reassign on intValue
wait... waht?
Oh InstanceId, this is a different topic, yes this one is unique for the lifetime of the Unity Editor Process
If you restart Unity, it might potentially have a new ID
Yeah I found out. I need an id that's unique for the lifetime of the play session 😛
The EditorApplication.playModeChanged event (I think that was its name) probably makes it easier.
so I'm not on the right track with this line?
sockets.?????.intValue = Convert.ToInt32(EditorGUILayout.EnumPopup((SocketTypes)sockets.GetArrayElementAtIndex(i).intValue));
No, restarting unity will take forever for me to figure this out. I need something faster 😛
My GOs all inherit from UnityComponent, which stores some info for the debug logging. All I gotta do is implement this id and then I'll read in logs which GO is from which session.
do I need to do like var socket = sockets.GetArrayElementAtIndex(i)
and then just assign to that?
Yes
Well that did it
I still find it confusing, but it's less confusing now
Thanks for the help
You cant using GetInstanceID
I know, because they persist between play sessions. I will make my own GetSessionID extension 😉
Or just have the custom logger generate those internally.
It's easy. I just wanted to see if something like that existed is all.
It's why I prefixed the question with Quickie:. Yes or no. 🙂
Just keep a counter in your logger class, increment it per start Play event and save the counter when you log your logs
You got it
Now all I have left is to hunt down the gross AssetPostProcessor bug
Mikilo/Tor, do either of you have experience slicing sprites in OnPostProcessTexture?
Is it possible to display custom icons or emojis in the Debug Console?
Do you mean, slicing a Texture2D to get Sprites?
I don't think you can, only text and markup
Yes
oooo
But it is at your own peril
You know how the HelpBox shows that icon based on MessageType? If you notice the Console logs have the same thing. Are those icons hard coded, or can they be customized?
It's hardcoded
do you mean it doesn't provide enough flexibility? or it's at my own peril since it is in preview/beta
Flexibility, it has several features implemented. But it is so... it's an adventure to go there
@robust mirage If you go easy on it, probably you will like it
For advance stuff, you will google a lot
I had been looking to combine a gradient texture generator tool I have with some sort of texture atlas tool.
But then I discovered this (just now): https://github.com/maxartz15/MA_TextureAtlasser
Is there any way to access additional mouse buttons in the editor?Input.GetKeyDown(KeyCode.Mouse3) works but (e.type == EventType.MouseDown && e.button == 3) does not 😕
@thin fossil What class is e? I don't think it stores button only for mouse. I think it's a generic that stores it for all possible buttons, so KeyCode.Mouse3 doesn't mean that it is int 3 as you are checking for with e.button.
@thin fossil Input and Event are 2 different systems
I don't know how accurate that post is, but if you do log all the events in a Unity window you do get none for mouse 3 and 4
yeah I know they are 2 different systems. Thats the weird thing mousebuttons 3-5 work at runtime with Input.GetKey but they dont work in editor with Events
thats what I tested and it works at runtime 🙄
If you want to handle more than 3 buttons, use :
[DllImport("user32.dll")]
public static extern Int16 GetAsyncKeyState(Int32 virtualKeyCode);
Windows only obviously
Thx I guess thats the way to go then
although I find it weird that unity does not recognize these buttons in edit mode as runtime can do it 😬
@onyx harness are there any constants for the return codes?
What does the doc say?
its just comparing like (GetAsyncKeyState(VK_ESCAPE) & 0x01
was wondering because it also returns another value while the button is down
This method should be called in Update
GetAsyncKeyState is more powerful than just Event.
It gives the state of down, up, hold of any key/mouse button.
just found the important part: "If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState"
hey does anyone know a lot about Photon Pun 2? because I'm having problems
how can I set the selected editor object to an object within prefab mode?
simply setting Selection.objects to a reference to one of the prefab gameobjects does not work
if (GUILayout.Button("Add test object")) {
using (EditPrefabContentsScope editingScope = new EditPrefabContentsScope(assetPath)) {
GameObject root = editingScope.prefabContentsRoot;
GameObject newObj = new GameObject("TEST");
newObj.transform.SetParent(root.transform);
Selection.objects = new Object[] {newObj};
}
}```
@obtuse bone Photon PUN 2 is a networking plugin, not an editor extension plugin. Try your luck here #archived-networking
ahh
how would i for instance grey out a certain field in the inspector ONLY if say a variable called "public bool Camera cam" is null? most-likely using reflection.
someone can help?
Hello, friends. I'm writing a custom editor for a 2D map generator using Scriptable Objects for each biome type. Each biome will have a single TileBase for its background and a TileBase[] for its foreground. I am new to Editor scripting, but I know you can get the values for things like int, float, color, array, etc. However, there doesn't seem to be an option for anything to do with tiles that I can see. Using things like 'object' or 'reference' return an error as it can't cast to those types.
Could someone tag me and let me know what I should put here:
obj = new SerializedObject(biomeData);
[...]
SerializedProperty bgTile = obj.FindProperty("backgroundTile");
EditorGUILayout.PropertyField(bgTile, true);
biomeData.backgroundTile = bgTile._____??```
'BiomeData' is the name of the SO class and 'biomeData' is the name of the target.
There should already be a serializedobject for the target object
And to go into classes you can just find property and then findpropertyrelative on that instance
Tried that. Doesn't seem to work for the part I'm looking for:
If I don't reapply it and just do "FindProperty," I find that if I click off the object and go back, its Inpsector has reset and the changes made aren't stored.
This also doesn't work for the same reason:
Is there an easy way to catch a nevermind - changed approachGenericMenu having been cancelled/closed?
If TileBase is not a Unity Object then you have to use findpropertyrelative multiple times to find the "child" methods
Yeah, I've been looking on Google and YT for hours. Could anyone tell me what I might pass in as an argument there? Like @waxen sandal said I'd have to use FindPropertyRelative, but what exactly am I passing in, since it's not a Game Object or child, it's just a tile.
obj.FindProperty("backgroundTile").FindPropertyRelative("whatever fields TileBase has")
There's no api to get the class instance
Unless it's a unity object in which case it's objectreferencevalue
I made a wrapper class for Debug.Log, and it's working how I need. One thing I didn't foresee is the fact that when the log shows in console, the stack trace includes all the methods inside my wrapper class, which then prevents me from double clicking it and it going straight to the last item that called it, instead it will always go to the wrapper class.
Is there a way for me to exclude a class from the stack track when logging to console? Or I did a big no-no and should've made this in a different way?
🥴
You need a special console for that purpose
Most consoles in the Asset Store handles custom loggers
NG Console Free does it
If you compile as a dll and include that instead of source, that’s one way @quaint zephyr. But as Mikilo says, this has been done many times before should you want an out of the box solution.
Thanks guys. I’ll look into it.
Ok, so I think I found a work-around. Instead of using it with FindProperty, I simply did this:
biomeData.backgroundTile = (TileBase)EditorGUILayout.ObjectField("Background Tile: ", biomeData.backgroundTile, typeof(TileBase), false);
So far, that seems to work. 🙂
Hello all. Does anyone know of any Visual Studio extensions that allow me to select multiple instances of a word ? ( Like CTRL + D in Visual Code )
Should be supported out of the box afaik
You might have better luck in another channlel as this is not the correct one
Oh, 😄
One message removed from a suspended account.
@foggy birch thats a Web browser
One message removed from a suspended account.
Im making extra fields show up when this value changes
It works, but if i open the little circle to select the object, the callback only triggers on the first time it's changed. How can it update everytime?
As in, if i open the object selector via the small circle button, i have to select it once, then change my mind, gotta close the selector window, then select again. I cant just "change my mind" and select stuff in 1 selector window
Unity was not designed to integrate tutorials, I can't make it in there.
Plus, HTML makes it quite easily accessible for everyone in a single click
But if you want rectangle GUI overlay, it is feasible in Unity Editor.
Is it possible to "observe" certain textures? I want to execute a command when a certain texture (out of a list of textures (that is definied dynamically)) got changed from the outside or via the texture importer options.
it doesn't seem possible to use OnPreprocessTexture() / OnPostprocessTexture() for this, at least not reliably
someone can help?
so if i want to disable / re-enable the secondBool based on if the camera is null, how would i do that? right now, i have :
In the main directory :
MyGame.cs :
using System;
using UnityEngine;
public class MyGame : MonoBehaviour {
public Camera cam;
public bool secondBool = false;
}
In the Editor folder :
CustomEditor.cs :
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(MyGame))]
public class MyGameEditor : Editor {
SerializedProperty cam;
SerializedProperty secondBool;
void OnEnable() {
cam = serializedObject.FindProperty ( "cam" );
secondBool = serializedObject.FindProperty ( "secondBool" );
}
public override void OnInspectorGUI ( ) {
EditorGUILayout.PropertyField ( cam );
GUI.enabled = ! cam.boolValue;
EditorGUILayout.PropertyField ( secondBool );
GUI.enabled = true;
serializedObject.ApplyModifiedProperties ( );
serializedObject.Update ( );
}
}
i am getting an error with :
GUI.enabled = ! cam.boolValue;
EditorGUILayout.PropertyField ( secondBool );
GUI.enabled = true;
the error is :
type is not a supported int value
UnityEditor.SerializedProperty:get_boolValue()
Cam is not a Boolean value
It is an Object reference
So compare it's objectReferenceValue to null
@visual stag how would i do this?
exactly like I said, compare it's objectReferenceValue to null
GUI.enabled = cam.objectReferenceValue != null;
@visual stag ok this worked PERFECTLY! Thank you! Only problem is, i'm receiving an error with :
public override void OnInspectorGUI ( ) {
EditorGUILayout.PropertyField ( cam );
GUI.enabled = cam.objectReferenceValue != null;
EditorGUILayout.PropertyField ( hidingBool );
GUI.enabled = ! hidingBool.boolValue;
EditorGUILayout.PropertyField ( secondBool );
GUI.enabled = true;
serializedObject.ApplyModifiedProperties ( );
serializedObject.Update ( );
}
specifically these 2 lines :
EditorGUILayout.PropertyField ( hidingBool );
GUI.enabled = ! hidingBool.boolValue;
I get the error :
type is not a supported int value
UnityEditor.SerializedProperty:get_boolValue()
what is hidingBool
@visual stag in CustomEditor.cs :
void OnEnable() {
cam = serializedObject.FindProperty ( "cam" );
hidingBool = serializedObject.FindProperty ( "hidingBool" );
secondBool = serializedObject.FindProperty ( "secondBool" );
}
in MyGame.cs :
public class MyGame : MonoBehaviour {
public Camera cam;
public bool hidingBool = false;
public bool secondBool = false;
}
no idea then, seems fine
@visual stag well, it's specifically pointing to this line :
EditorGUILayout.PropertyField ( hidingBool );
@visual stag how do i disable something only when both camera & target are not null? :
MyGame.cs :
using System;
using UnityEngine;
public class MyGame : MonoBehaviour {
public Camera cam;
public Transform target;
public bool hidingBool = false;
public bool secondBool = false;
}
CustomEditor.cs :
public class MyGameEditor : Editor {
SerializedProperty cam;
SerializedProperty target;
SerializedProperty hidingBool;
SerializedProperty secondBool;
void OnEnable() {
cam = serializedObject.FindProperty ( "cam" );
hidingBool = serializedObject.FindProperty ( "hidingBool" );
secondBool = serializedObject.FindProperty ( "secondBool" );
}
public override void OnInspectorGUI ( ) {
EditorGUILayout.PropertyField ( cam );
GUI.enabled = cam.objectReferenceValue != null;
EditorGUILayout.PropertyField ( hidingBool );
// GUI.enabled = ! ( target as MyGame ).hidingBool;
EditorGUILayout.PropertyField ( secondBool );
GUI.enabled = true; // ! ( target as MyGame ).secondBool;
serializedObject.ApplyModifiedProperties ( );
serializedObject.Update ( );
}
}
just use basic logic, &&, you know
ok
@visual stag like this?
GUI.enabled = cam.objectReferenceValue != null && target.objectReferenceValue != null;
does it work?
@visual stag no, it gave error :
NullReferenceException: Object reference not set to an instance of an object
MyGameEditor.OnInspectorGUI ()
have you assigned target?
@visual stag this is how i have target in MyGame.cs :
public Transform target;
in the editor though
@visual stag here's how i have CustomEdtior.cs :
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(MyGame))]
public class MyGameEditor : Editor {
SerializedProperty cam;
SerializedProperty target;
SerializedProperty hidingBool;
SerializedProperty secondBool;
void OnEnable() {
cam = serializedObject.FindProperty ( "cam" );
target = serializedObject.FindProperty ( "target" );
hidingBool = serializedObject.FindProperty ( "hidingBool" );
secondBool = serializedObject.FindProperty ( "secondBool" );
}
public override void OnInspectorGUI ( ) {
EditorGUILayout.PropertyField ( cam );
EditorGUILayout.PropertyField ( target );
GUI.enabled = cam.objectReferenceValue != null && target.objectReferenceValue != null;
EditorGUILayout.PropertyField ( hidingBool );
// GUI.enabled = ! ( target as MyGame ).hidingBool;
EditorGUILayout.PropertyField ( secondBool );
GUI.enabled = true; // ! ( target as MyGame ).secondBool;
serializedObject.ApplyModifiedProperties ( );
serializedObject.Update ( );
}
}
it is now erroring on this line :
EditorGUILayout.PropertyField ( cam );
NullReferenceException: Object reference not set to an instance of an object
MyGameEditor.OnInspectorGUI
I have no ideas, either you're doing something really weird or your names don't actually match up
@visual stag it was just a cache glitch. its working now! thank you!
@visual stag : how can i have it where if cam & target aren't both null AND the hidingBool checkbox is selected, it disables everything else?
public override void OnInspectorGUI ( ) {
EditorGUILayout.PropertyField ( cam );
EditorGUILayout.PropertyField ( target );
GUI.enabled = cam.objectReferenceValue != null && target.objectReferenceValue != null;
EditorGUILayout.PropertyField ( hidingBool );
EditorGUILayout.PropertyField ( secondBool );
GUI.enabled = ! hidingBool.boolValue;
GUI.enabled = true;
serializedObject.ApplyModifiedProperties ( );
serializedObject.Update ( );
}
again, it's just basic logic
I really don't want to help with constructing what amounts to "if this and this" statements
How could i run an update method in edit mode? I would like to catch when the editor resolution is changed and the only thing i came of was to check the resolution all the time until it changes
any idea?
yes, that tells you the width, but i want to capture whenever it changes
i think i found it
[ExecuteInEditMode]
i can make a script checking the ScreenWidth there
(ill try)
Oh... okay, didnt know how basic we have to approach this, sorry. Yeah, thats the one to check in edit mode 🙂
👍
EditorApplication.update otherwise
or perhaps hook in main window's some events via UI Toolkit
thanks a lot, ill check both options too
UI toolkit you mean?
im looking for info
didnt even know there was a ui toolkit
cant find it in the package manager
this seems to do what i want
i will take a look to the UI Toolkit if i have some time some day 😅
okay this is nuts
anybody knows why Screen.width gives a different value whenever im moving the mouse around?
is it random? Or is it the width of the hovered window?
those
these 2 are being alternatively shown when moving in the game window which is 2436x1125
That's maybe why i never liked Screen.width
do i have an alternative?
Well my preferred way is Main window via UI Toolkit
nnonono
i want the Game window
sorry for the mis...
miss....
shit my english is fading
im tired
🤣
Have you looked at Screen.resolutions?
yeah but screen resolution doesnt even change when i change from that tag
i suspect is taking the monitor resolution
yep, it gives available resolution
You want the real physical Game window size?
Or the rendered?
the one selected here:
it changes briefly to other values but when stop moving comes back to the correct one
oh
its bothering but maybe i can work with that
the rendered one
damn i would never think this would become such a trouble
In total honesty, it's really not that easy
Maybe I missed the normal way
But the Reflection way contains 3 4 layers
FYI, you need:
GameView.selectedSizeIndex & GameView.currentSizeGroupType
In the picture above, you need group.GetGameViewSize()
how to assign a sprite to prefab, without using resource.load? , through script, it should basically point to normal asset folder like Assets/Sprites/Monkey
Woah @onyx harness I just realized that you're the author of NG Tools! Bravo!
wow, thanks a lot Mikilo
has anyone else had issues with reorderable list and context menus in Unity 2019 specifically?
my use case is a color field property in a reorderable list element
right click -> copy/paste is broken, but only in Unity 2019 - it works fine in 2018 and 2020
the color field is drawn using Unity's color field property attribute
broken as in, it doesn't copy/paste anything when you press copy/paste
is that really you? the youtuber? @blissful burrow
yeah i thought so.. but also thought why would want someone impersonate her
I'm kidding, of course it's them, why are you asking?
i didnt know she was that famous...
ah really?
no nothing, her face looks familiar, and then i googled and seems i saw some of her maths video once and find it entertaining, nothingelse
im not too much intto social media so i dont know if shes popular or ....
I've not seen anything in particular, is there some small test code that might highlight the issue? I assume it's as simple as just a Color field in a list
I don't have code in isolation to test it with, but yeah, ReorderableList, drawElementCallback with an EditorGUI.PropertyField with a property that is marked with the color field attribute
oh, probably yes!
By Color field attribute do you mean ColorUsage?
yeah!
although lemme double check something
I might have done some shenanigans
yeah, no shenanigans
should work fine
Seems to work fine here
Ah sorry, looking at wrong Unity version, I'll try 2019.4
seems to be some input/GUI event related thing - in 2019, clicking copy/paste selects the reorderable element instead of acting on the context menu
Oh yeah, it doesn't work at all, the copy doesn't go through
Unity please 
It's fun that you can copy it from 2020
seeing as it is text
and paste it into another field
you just cannot paste it into the color fields
oh - it works in 2020 just fine for me
Yup, 2020 is great, I mean you can copy from 2020 to 2019
Yeah pretty sure I ran into the same issue
