#↕️┃editor-extensions

1 messages · Page 111 of 1

crude relic
#

Concur

cosmic inlet
#

ok I'm gonna keep track of the Port class you told me to create in the script that handles loading the View of graph view

crude relic
#

Sounds good

cosmic inlet
#

ok so now I can add them here no problem

crude relic
#

Yap

cosmic inlet
#

wtf is fieldinfo tho

crude relic
#

It's like memberinfo but only for fields

#

You do getfields instead of getmembers

cosmic inlet
#

wait what changing member info to field info just worked???

crude relic
#

?

cosmic inlet
#

nothing, it worked

crude relic
#

Cool

cosmic inlet
#

so now every single Node class has a list of variables and ports linked to each other

#

so now in this function I have the parent port and the child port, along with the nodes that correspond to both of them

crude relic
#

Sure

cosmic inlet
#

ok one last issue and this is done

#

I made this function here

#

and I want to reference it here and I have no idea why it doesn't show up

#

ok nvm now I know why

#

well now that I'm using FieldInfo instead of MemberInfo it doesn't seem to get any of the PortAttributeInfo correctly-

zenith estuary
#

What does the code look like currently?

cosmic inlet
#

now it just doesn't create the ports correctly

zenith estuary
#

You need to use GetFields, not GetMembers

cosmic inlet
#

I did change it to that

#

then I saw that using fields doesn't work for some reason

#

went back to memberinfo

#

and now it's still broken

#

just like my brain after all of this

zenith estuary
#

Which parts did you change to use FieldInfo?

crude relic
#

Then that wasn't the issue

zenith estuary
#

There's no reason that GetCustomAttribute will fail for FieldInfo and not for MemberInfo

#

Chances are you might have accidentally missed a spot to change

cosmic inlet
#

so now I'm getting the Fields at the top

zenith estuary
#

You don't need the field.CustomAttributes.ToArray().Length > 0 btw

cosmic inlet
#

yes

#

omg I know what the issue is

#

omg I may be stupid, as you could probably already tell

zenith estuary
#

Also

#

field.FieldType

#

not field.GetType()

cosmic inlet
#

ok

zenith estuary
#

foreach (FieldInfo field in node.GetType().GetFields(flags))
{
    var attribute = field.GetCustomAttribute<PortAttribute>();

    if (attribute == null)
        continue;

    var info = new PortAttributeInfo(field, attribute);
    var port = InstantiatePort(Orientation.Horizontal, attribute.direction, attribute.capacity, field.FieldType);
    // etc.
}
crude relic
#

What's the point of the portattributinfo class

cosmic inlet
#

to get info for whether or not the port should be input or output, and to determine it's capacity

#

is that needed anymore?

#

cause it doesn't seem to work anyway

zenith estuary
#

It doesn't seem to have much use from the code samples shown

cosmic inlet
#

It's just for this Port newPort = InstantiatePort(Orientation.Horizontal, info.portAttribute.direction, info.portAttribute.capacity, field.FieldType);

zenith estuary
#

Yeah you can just pass in the values from the attribute directly

#

attribute.direction would be the same as info.portAttribute.direction so there's little point in PortAttributeInfo existing if that's all it's used for

cosmic inlet
#

I keep messing up the variables and then being shocked why they don't work

#

ok cool

#

so now I have a list of all the variables and the ports that correspond to them, and I need to specify them where the selected line is

#

I have a list of all the nodes in the tree which I can access from this script

#

and then those nodes inside the node tree have a list of ports and variables that correspond to them

#

so now I need to make the links

#

I have the parent port and the child port

#

ok so now I just need a function that gets me the variable from the port it corresponds to

#

and my brain has decided it should just fry and die

#

so now I can get the variables in a read format, aaaand I need to be able to set them

#

...

cosmic inlet
#

ok so apparently this did work

#

I changed the type to object and reanalyzed the code a bit

#

and now when I add a link between them

#

I get an object from the variable of the first node, and one for the second node

#

only issue is-

#

it's an object

#

cause I needed it to be of reference type

#

and I don't only need strings so I couldn't use that, even if it was also a reference type

#

I just need to cast this as the type of the variable

#

so kept track of the type but it doesn't let me use it

slim zinc
#

just cast it.

#

(also, always prefer casting over as)

cosmic inlet
#

uhh

#

one issue

#

I can't just cast it using a variable

#

so I have no reference to the original variable

#

and variables can be either strings, gameobject, literally anything

#

so I can't just go parentObject as string

#

cause it could be something else

#

so I keep track of it's Type as well

#

but I can't dynamically cast it like that apparently

#

it gives me a red line if I do so

slim zinc
#

yeah no that doesn't work, but it's also kinda useless if you don't know at all what type you'll be working on. what types could it be?

cosmic inlet
#

well

#

it's really hard to explain-

#

but rn I have objects that need to be casted

#

there really isn't any other way I can get the type except by using a variable

slim zinc
#

i'll have to read the previous posts a bit

cosmic inlet
#

ok I found a function

#

Convert.ChangeType

#

I hope it works

#

nope

#

it does not

#

apparently Expressions can help-

slim zinc
#

ok, i read your posts. why do you need the variable as the correct type?

cosmic inlet
#

because I need to pass data using reference types

#

so instead of creating a copy of the variable

#

it creates a reference to the original

#

and to do that I need to use the object type of variable

#

but then when I assign that variable, it's not gonna be read as a string or gameobject, just, object

#

so I can't debug.log it and stuff for my nodes to work

#

I can keep track of the type of variable I need it to be at runtime

#

and I just need to somehow cast it from an object to that type at runtime

slim zinc
#

yeah, i faced a similar problem before. if you have relatively few object possibilities, you could use If(object is GameObject obj) => Log(obj);

cosmic inlet
#

ok so apparently I can't just use an object and then cast it later

#

so I need to somehow store the data in binary and then load it-

#

right?

crude relic
#

You need to use reflection to set the variables

#

Since you don't know their type at runtime

#

You can use the field info you saved to do this

#

Fieldinfo.setvalue

#

You can't pass value types as reference types this way

cosmic inlet
#

I get this in return from the object

cosmic inlet
#

I changed it to object

crude relic
#

?

cosmic inlet
#

I didn't know how to use FieldInfo

#

cause I needed to pass the variable

#

so, I changed it to object from FieldInfo, because I needed it to be a reference type of variable

crude relic
#

Wut

cosmic inlet
#

ok I changed it back

#

just

crude relic
#

You cast fieldinfo to object?

cosmic inlet
#

forget I said anything

crude relic
#

Lol

cosmic inlet
#

no

crude relic
#

You need both, tbe

cosmic inlet
#

I changed the class that held the info for the port and the variable

#

I changed this to object

crude relic
#

The reference to the class and the field info

cosmic inlet
#

from FieldInfo

crude relic
#

In order to set the value via reflection

cosmic inlet
#

ok so now I have a reference to the field info of the variable from the start port, end the end port

#

so now I need to convert it from a FieldInfo to the variable it was originally

crude relic
#

Remind me what you're trying to do

#

Specifically

cosmic inlet
#

so I kept track of the ports and the variables that correspond to them in a class

#

originally the "variable" one was of type FieldInfo

#

so now, I have a reference

#

to both the variables of the start port and the end port

#

and I just need to set the variable from the end port to be equal to the variable from the start port

#

so I get a reference of the first variable string stringToOutput

crude relic
#

Ok, so use the fieldinfo of the start port to get the value (boxed as object)

cosmic inlet
#

and of the one from the next node string stringToDebug

#

yes

crude relic
#

Then use the fieldinfo of the end port to set the value

cosmic inlet
#

I boxed them as object

#

like this?

crude relic
#

Almost

cosmic inlet
#

ok cause it was giving me an error lmao

crude relic
#

Yah that's not correct

cosmic inlet
#

then how-

crude relic
#

Should look something like this

Endportfieldinfo.setvalue(endport, startportfieldinfo.getvalue( startport) );

#

I'm on phone so forgive the pseudo code

cosmic inlet
#

yeah it's fine

#
Parameter name: obj```
crude relic
#

You need to get the field info for both the start and the end port

cosmic inlet
#

wait one sec

#

wait what did I get wrong-

#

but I have them-

crude relic
#

Show coee

#

Cide

cosmic inlet
crude relic
#

Code 😓

#

You're passing the field info as the object reference

#

You need to pass the port object

#

Not the field info

#

Read my pseudo code again

cosmic inlet
#

ohhh

#

childFieldInfo.SetValue(edge.output.node, parentFieldInfo.GetValue(edge.input.node));

#

like this?

#

nope

#

nope

#

why would it work

#

I wrote .node

#

I am an idiot

#

Field stringToOutput defined on type String_Node is not a field on the target object which is of type

#

UnityEditor.Experimental.GraphView.Port

crude relic
#

That's my bad, I meant to write the node

#

Replace start port and end port with start node and end node

cosmic inlet
#

now it looks like this

#

childFieldInfo.SetValue(parentView.node, parentFieldInfo.GetValue(childView.node));

#

shouldn't it be like

#

the other way round-

#

cause it's the childFieldInfo I need to be set to the parent

crude relic
#

Yes it should be the other way around

cosmic inlet
#

I don't understand the node part

crude relic
#

Child with child, parent with parent

cosmic inlet
#

parentFieldInfo.SetValue(parentView.node, childFieldInfo.GetValue(childView.node));

crude relic
#

that's better

#

Which is the parent and which is the child

#

Is it flowing parent to child

#

Or child to parent

cosmic inlet
#

from parent to child

#

the data needs to be passed from parent to child

#

the first node to the second

#

and all I have are the FieldInfos of the variables

#

both being boxed

crude relic
#

Then you need to switch the parent and child

cosmic inlet
#

as FieldInfo or object I have no idea anymore

crude relic
#

But switch both parts

cosmic inlet
#

ok it still won't work

#

wait what

#

wait WHAT

#

IT WORKED???

#

of course it works the moment I lose all hope

#

of course it does then, like always

crude relic
#

Told you

cosmic inlet
#

I like how I made the string be equal to absolute pain

#

it's been like 2 weeks

crude relic
#

Remember that code will always do exactly what it tells you to

cosmic inlet
#

and I'm almost finally done with this stupid graph

crude relic
#

Not what you want it to 😄

cosmic inlet
#

yes

#

exactly

#

there's just one more thing to fix now and it's finished

#

thank you smmm

#

oh god what if I change the first one tho-

#

if I change the first variable it has no way of knowing to change the second

#

ok this will take more time but thank you lol

#

I'm gonna go take a break because I've worked like 6 hours on this today-

#

gets up from chair and crumbles into a million lego pieces

crude relic
#

That's why you do it while you're executing the graph

#

You don't need to sync it at all times, that's a waste

#

It only matters when you're actively doing something with it

cosmic inlet
#

yeah but this is the only script that can sync it-

#

I think I can like

#

change it

#

but that part of the code is still messed up

#

I will be back tomorrow I guess lmao

#

there's a system for this already online but it didn't work for me, and plus, I made it this far so

#

NodeGraphProcessor on Github

#

but it didn't work for me

crude relic
#

Okie

slate cliff
#

Is there a way to render a struct inside of an OnGUI call (readonly is fine)?

crude relic
#

Yes

#

Is it serializable

slate cliff
#

Yes

#

This is outside of a unity serialization context though

#

I just want to display the values inside a struct the way unity would display them

crude relic
#

Since it's serialized you can get the serializedproperty and use editorgui.propertyfield

slate cliff
#

But it isn't being serialized anywhere

crude relic
#

Where does it exist

#

Need some more context

slate cliff
#

new StructType();

#

I want to display the contents of that in an OnGUI call

crude relic
#

You're creating it in th editor?

slate cliff
#

It's just on the stack, e.g. inside the OnGUI method

crude relic
#

You can manually draw the field values using guilayout.label

slate cliff
#

I don't know the structs type, it's just an object

slate cliff
#

I think I'll just call ToString for now and just override that for visualization purposes

crude relic
#

ok 😄

#

KISS principle at work

slate cliff
#

Yeah it's just for debugging purposes

#

The reason I have such weird requirements is I want to display the ECS component values of an entity, and those aren't serialized in the usual unity sense

crude relic
#

ah, I see

cedar condor
#

So I understand that you can draw a box handle for editing objects using UnityEditor.IMGUI.Controls BoxBoundsHandle, but is there any way to round the corners?

#

Or to draw a curved line for the corners

#

The curve doesn’t necessarily need to be editable with handles but I just would like some way to attach it to the boxes on the corners

cedar condor
#

Any help with this would be great

gloomy chasm
#

If you want what I think you do, then you will most likely need to draw the whole thing yourself using the Graphics API

cedar condor
#

Well it’s only necessary to have in the editor

#

So I’d use gizmo’s/handles in the OnSceneGUI method to draw it

#

Just wondering if there’s a simple way

gloomy chasm
gloomy chasm
cedar condor
#

I’m away from my PC at the moment so I can’t give a code example but the thing the closest would be the BoxCollider2D

#

The BoxCollider2D is able to support rounded corners

#

I was just wondering how it is able to do that

gloomy chasm
cedar condor
cedar condor
humble crystal
#

can you still get kite

peak bloom
#

Any idea why I cant see the edges, the port successfully connected
e.outputPort.ConnectTo(t.inputPort);

#

but no edges being drawn

#

in the context of connecting ports programmatically if that will help

#

checking all edges in the graphview var edges = graphView.edges.ToList(); returns 0, meaning the edges weren't created at all

peak bloom
#

Managed to do this. I was a dumbass, I didn't add the newly created Edges to the graphview 🥲

#

in case anybody wants to connect their graphview programmatically, it's quite simple :

                        var edge = e.outputPort.ConnectTo(t.inputPort);
                        e.outputPort.Connect(edge);
                        graphView.Add(edge);
                        edge.MarkDirtyRepaint();
peak bloom
#

I just found out that GraphView api is deprecated in favor of Graph Tool Foundation, like damn, i've spent many hours with this.. like dayum

gloomy chasm
#

Also GTF won't be out until at the very earliest 2022.2, more likely 2023.x though

peak bloom
#

the exposed APIs are very nice to look at too, also

gloomy chasm
#

You can think of GTF much like that NodeProcessor github project

peak bloom
#

if you see the example of GFT, it doesn't look like custom editor tool at all

peak bloom
#

see how they did it in the example, hard to explain as english isn't my 1st language

#

long story-short, it doesn't look like customEditor code

gloomy chasm
visual stag
#

the best part about looking about the graphtools foundation package docs is the billion namespaces and 3 of them say GTFO

peak bloom
#

it's just feel a bit clunky after toying around with it for the past two hours

gloomy chasm
#

It is a pretty bad API and also doesn't have the same structure as existing APIs

peak bloom
#

well, whether we like it or not, they will replace what used in ShaderGraph, Bolt etc with GFT soon (see the link below, after this!)

peak bloom
#

such a big word, I know XD ....

gloomy chasm
#

I am looking forward to seeing the roadmap from GDC to see if they say anything about it

peak bloom
#

the staff themselves said that in the link above(proly from other thread, just see if it's there if I'm not mistaken)

visual stag
#

Not that I doubt it will be, but the above thread that claim is just from some random

gloomy chasm
peak bloom
#

I don't blame them if they wanted to deprecate graphview tho, it's been stale since 2018

#

on the other hand, I don't think Unity would just deprecate it either, like, they invested so much money into it.. ya know

peak bloom
#

@gloomy chasm @visual stag been searching the thread about 'graphview' being deprecated which i saw earlier today, see this, its unity employee who said it.. https://github.com/alelievr/NodeGraphProcessor/issues/73#issuecomment-671071879

GitHub

Just jotting down some thoughts as I see you're working on the relay node and this might have some relationship with that task. Currently playing with Mixture and I find myself frequently c...

#

And sorry for the ping 🙃

#

Yeah, kinda sucks tho... It has so much potential

visual stag
#

As long as something in this form exists and does the job then I'm happy

#

and as long as I'm not working for Unity and having to deal with whatever internal pain caused them to reevaluate

gloomy chasm
#

My only concern with GTF would be that it would cause limitations in creation graph views due to being more data oriented instead of strictly view like GraphView is.

#

Will just have to wait and see I guess.

wispy delta
#

Thank you, that's perfect! (sorry for delayed response) Only thing I'm still struggling with is getting the source value so I can check if the modification is redundant. I'm using PrefabUtility.LoadPrefabContents to load the prefab I'm checking property modifications on, but when I call PrefabUtility.GetCorrespondingObjectFromSource() on the modification's target object I always get null returned. I can't revert all of the modifications, just the redundant ones, so I somehow need to find the corresponding value in the parent prefab

#

GetCorrespondingObjectFromSource is the only function that sounds like what I want, but I guess it isn't. Perhaps I need to get the parent prefab via the variant's root and manually find the matching object by path in the hierarchy of something?? hmmm

gloomy chasm
wispy delta
#

Good q. For context, I'm working on a UI styling system. You can bind styles to component values via UnityEvents. So when you apply a style you're essentially invoking a bunch on UnityEvents that can change arbitrary properties on a prefab.

I'm trying to make the styles apply in the editor, but if you have a prefab with a style component on it, and a prefab variant, and I apply the style on both, the prefab variant will set the same properties as the parent prefab, but the changes will be property overrides which is not ideal considering it's the same values as the parent prefab.

Then there's the case where you might override/add specific bindings on a variant and those changes should persist as property modifications.

So tldr: there's basically just a ton of edge-cases when making a tool that can write to arbitrary properties and my best attempt at a solution is to see all property modifications on a prefab variant after applying a style and revert the ones whose values are unchanged from the parent prefab

#

(sorry for the text dump. no sweat if that doesn't make any sense!)

gloomy chasm
wispy delta
#

just use UITK
yea ikr 😭
would love to, but it's still missing world-space and custom shader support which is needed on my current project

getting a SerializedObject of the parent prefab('s component)
yea that's what I was thinking, but getting that parent component is what's stumping me. wasn't sure if there was a clean way in the api. any component on any object in a prefab could have modifications so i need to find a way to get the corresponding object on the parent.
PrefabUtility.GetCorrespondingObjectFromSource() seems to be for prefab instances, but I'm crawling over every prefab asset in the project.

#

idk if this is helpful, but this is the structure of the function

private static void ApplyPrefabStyleBindings(string prefabPath)
{
    var prefabRoot = PrefabUtility.LoadPrefabContents(prefabPath);
    
    try
    {
        var stylables = prefabRoot.GetComponentsInChildren<Stylable>();
        if (!stylables.Any())
            return;
        foreach (var stylable in stylables)
        {
            // If this is stylable part of a variant we need to do some complex shit to avoid redundant property modifications
            if (PrefabUtility.IsPartOfPrefabInstance(stylable))
            { 
              // this is the tricky bit
            }
            // Otherwise we can just apply the style cuz this is an "original" stylable
            // and any changes it makes should propagate to variants automatically
            else
                stylable.ApplyStyle();
        }
        PrefabUtility.SaveAsPrefabAsset(prefabRoot, prefabPath);
    }
    finally
    {
        PrefabUtility.UnloadPrefabContents(prefabRoot);
    }
}
#

Perhaps PrefabUtility.GetCorrespondingObjectFromSource() isn't working because I'm calling it on the game-objects returned by PrefabUtility.LoadPrefabContents(prefabPath). If that function is just writing plain ol game-objects into an isolated scene with no link to the actual prefab asset that would explain why GetCorrespondingObjectFromSource only returns something for nested prefab instances since those would still be linked to their source prefab 🤔

wispy delta
#

OH SHOOT. propertyModification.target is on the parent prefab 🤡

tough cairn
#

is there a way to get individual sprites ? Im trying to create Sprite component and pass it the relevant tiles

crude relic
#

@tough cairn I'm not sure if there's a way to load a specific sprite by name but you can use AssetDatabse to load everything from the file and then filter that list to the one you want

#

then unload everything else

gloomy chasm
crude relic
#

gtk

gloomy chasm
#

Also, as far as I know if a main asset is loaded, all of its subassets are as well.

crude relic
#

that doesn't make sense to me, how would one access them once they're loaded

crude relic
#

if you load the main asset you don't also retrieve a reference to the other assets in the file

#

so they'd be pointlessly loaded in that case

gloomy chasm
crude relic
#

that makes sense -- if you're loading a sprite it's referencing the main texture

#

so that would have to become loaded

cobalt tiger
#

I am making a custom inspector to hide/show a couple of properties based on the state of an enum. It works great, but writing the custom inspector is very verbose, because I have to call EditorGUILayout.PropertyField(abcdef); for every single serialized field in the class... which means I have to retrieve and store a SerializedProperty reference for every single field... is there some other way?

#

At the very least is there some way to generate these from a given monobehavior automatically, since they're always identical boilerplate

#

Perhaps... I can use reflection to walk through the fields on the monoB and only operate on the ones I want that way... dayHmm

cedar condor
gloomy chasm
cedar condor
#

You can iterate through them with some fancy code, but almost everybody just does it this way

#

If it's a small custom inspector it won't be worth it, but if it has tons of variables it might be worth trying

cobalt tiger
#

I'm pretty sure i am on to something with the reflection option... will report back

cobalt tiger
#

No need for reflection it'll just list them

vapid prism
#

Can I use Gizmos in OnSceneGUI() somehow? If not, is there an alternative to Gizmos.DrawSphere() that I can use in a UnityEditor.Editor?

cobalt tiger
#

Hmm I don't see a way in serializedObject to just get all of them

cobalt tiger
#

in FindProperty()

gloomy chasm
gloomy chasm
cobalt tiger
vapid prism
# karmic ginkgo Handles class

The only relevant one I can find is SphereHandleCap, but doesn't that include interactivity? I'm looking for drawing a simple "gizmo" for purely visual feedback

tough cairn
#

how can i use Shader.Find with a shader graph asset in editor script ? ❓

#

or should i just rather use AssetDatabase ?

cobalt tiger
#

@gloomy chasm Hmm do you know of some way to differentiate between the properties that would actually show in default inspector drawing?

#

The iterator is returning lots of hidden properties that I assume are just part of MonoBehavior

cobalt tiger
#

Oh duh

#

lol

#

Good one thanks 😛

vapid prism
# cobalt tiger Good one thanks 😛

Just a heads up that the field for m_Script will be picked up by NextVisible(), but the default Unity MonoBehaviour drawer will draws that field as disabled. So you have to manually look for it and draw it as disabled if you want to match their style.

cobalt tiger
#

Yup already skipped it

#

😄

#

This works GREAT btw thanks for the pointers

#

Now I can just loop in OnInspectorGUI and check for name of specific property to modify how it appears

#

Now to make this generic 😛

tough cairn
#

nvm i fugured it out - added the shader to project settings in Always include shaders and now i can use Shader.Find

whole steppe
#

can i get editing tools in unity

peak bloom
#

Due to my concern of GraphView being deprecated in favor of GTF, after closely inspecting the internals of GTF, I can savely assume that they won't deprecate it !?(at least, not as soon) turns out GTF heavily relies on the GraphView, like literally running on top of it

#

so fingerCrossed 🥲 or else I'm wasting my time integrating vroid with the graphview for the past months👀

#

Either way, I should've researched on this before starting the project 😵‍💫

naive thorn
#

so i want to replicate something like this where select objects become colored and appear in the hierarchy, tried searching around but no luck, how could I pull this off?

velvet lark
#

Hi guys. I want to write an editor script to upgrade UI.Button to my custom controller. I need to move button.onClick to my controller (gbtc) which has a UnityEvent activeEvents type field. How can I move that?

for (int i = 0; i < button.onClick.GetPersistentEventCount(); i++)
{
    Debug.Log("Button onClick " + i + ": " + button.onClick.GetPersistentTarget(i) + " " + button.onClick.GetPersistentMethodName(i));
    gbtc.activeEvents.AddListener(???); //UnityAction is expected here
}

This is printing fine the targets and methods. But how do I convert it to a UnityAction type which I could then add to the UnityEvent?

short tiger
velvet lark
#

Yep you are right. I got it working with AddVoidPersistentListener like this:

UnityAction action = (UnityAction)Delegate.CreateDelegate(typeof(UnityAction), button.onClick.GetPersistentTarget(i), button.onClick.GetPersistentMethodName(i));
UnityEventTools.AddVoidPersistentListener(gbtc.activeEvents, action);
glacial sail
#

Is it possible to create some sort of virtual scene?

#

The use case is that, I'm making my own UI framework and would like to preview each component in editor by running it, as if it was the real game.

short tiger
#

There are preview scenes, but they don't have their own play mode separate from the regular play mode.

#

Do you need it to be in play mode to preview it?

glacial sail
#

No sorry if I didn't make it clear, I want to preview without going into play mode.

#

Currently what I have is that, each UI component is just a simple .cs script, and the editor extension mounts it onto an editor window and emulate what it probably looks like in play mode

#

But as you can imagine it's a bit problematic, I'd like to have a real virtual scene to mount the component in instead, so I can look at things like hierarchy, click on the mounted game objects and inspect the components, etc.

short tiger
#

You mean like what you get when you open a prefab?

glacial sail
#

Yeah.

short tiger
glacial sail
#

Nice, seems to be what I'm looking for.

#

Is there a quick example somewhere to get started with it, or I just have to read through the docs and piece together how it works?

short tiger
#

I've never used this API, so I'm not sure.

glacial sail
#

Ah okay, thanks still 😄

#

If my base class has ExecuteAlways attribute, does subclassing it inherit that as well, or do I have to add that to all my subclasses?

junior drum
#

Hi all, have a super simple class here tagged with [System.Serializable], and trying to display them inside an array / list in the inspector, but the ui isn't scaling to the actual number of properties
Do I need to write a specific editor script for this/could someone point me in a direction I can look?
Thanks

junior drum
#

actually it's only element 0 that's acting strangely, element 1+ seems to work fine

vapid prism
visual stag
#

Shouldn't make any difference

#

If there isn't an Editor or Property Drawer here, this just seems like a bug

tranquil sage
#

A couple useful tools in there. Surprisingly he didn't include the serializable dictionary

cosmic inlet
#

ok so I have an OnGUI function that checks for input, and whenever I press the spacebar it opens a menu, but it doesn't work if I do it while hovering over the graph view

#

also, my graph view doesn't display if I scale it on auto-

#

on the height

peak bloom
#

for the size you can try setttoparentsize StretchToParentSize

cosmic inlet
#

oh ok

cosmic inlet
peak bloom
#

make layers, so you don't have to parent all uielements in one container

cosmic inlet
#

nvm it just doesn't scale at all on the y axis

#

even though the flex is set to 1

#

I just can't set the height to auto

peak bloom
#

thats weird stretchtoparentsize should do that for you

#

make sure your graphview is at the bottom-most of the rootvisualelement

#

e.g:

            graphView.StretchToParentSize();
            rootVisualElement.Add(graphViewInstance);
            rootVisualElement.schedule.Execute(()=>SetToolbar());
cosmic inlet
#

it appears normal in the ui builder if I just use the standard tools, but doesn't actually display in the editor window

peak bloom
#

you don't even need to adjust the flex with stretchtoparentsize

#

after you set all, try to Repaint the editorWindow then MarkDirtyRepaint to the graphview

cosmic inlet
#

ok

#

yeah, it doesn't work more than 500 px

#

no matter what

#

either 500, or it just doesn't display

#
UnityEditor.UIElements.DefaultEditorWindowBackend.RecreateWindow ()```
peak bloom
#

well, try to make a clean editorwindow then add just the graphview with nothing else, see if it works

cosmic inlet
#

ok why doesn't this work as well-

#

a splitview-

peak bloom
#

it should work or else people will throw rocks at Unity 🙂

#

You just need to play along with it, I mean, learn how to use it

cosmic inlet
#

omg it works-

peak bloom
#

see 🙂

cosmic inlet
#

ok now tell me

#

if it was already added

#

root.Add(splitView);

#

WHY DO I NEED THIS-

#

omg now even scaling on auto works-

#

6 years and this program still manages to give me rollercoasters of anger

peak bloom
cosmic inlet
#

I-

peak bloom
#

try to avoid it while you still at the early stage of your project

cosmic inlet
#

...........

cosmic inlet
#

why, in the hell, is it not marked as deprecated

#

is it available already?

#

can I make the switch now?

peak bloom
#

still a rumour, but one of the employee of Unity stated that they are no longer maintaining it

cosmic inlet
#

oh cool

#

makes sense considering you can still link ports that are of different types

peak bloom
#

yes, but do note, there are ZERO documentation on how to use it. Your best bet is to tinker with the (clunky and buggy)examples that come with it

cosmic inlet
#

aight

#

of course there's no documentation

#

whatever

#

it's not like I would've understood it anyway lmao-

peak bloom
#

good luck!

cosmic inlet
#

thank you-

#

I-

#

am scared lol

#

everything graph view related is just dialogue system-

peak bloom
#

you can make your own vscripting with it, just like BOLT

cosmic inlet
#

that's what I'm trying to make

#

I don't really see a reason to switch tho-

#

like, I can do undo/redo system myself

#

and I know how this one works

#

so

#

the only issue is the fact that for some reason you can connect a port of type gameobject, for say, with one of type string-

junior drum
coarse zealot
#

Anybody worked in mirror unity?

waxen sandal
#

Wat

clear kite
coarse zealot
clear kite
coarse zealot
#

Cool then thanx

atomic vine
#

Does anyone here know how you would set grid settings in the editor via code? I'm not sure where to start looking for this.

waxen sandal
earnest talon
#

Would it be possible to remove the dock window and create your own window dock for a Custom Editor?

waxen sandal
#

What dock window?

earnest talon
gloomy chasm
#

You mean show one editor window inside of another?

earnest talon
#

no not at all

#

I want to remove the entire window part for a borderless-like window.

#

so I can do a more customized full curved UI design

earnest talon
#

thanks

#

I take it I'll have to entirely create the draggability and resizeable functions

gloomy chasm
#

What Navi linked, but with that said, you can't curve the border of the window. And also, just as a note, it is better to always try to have your editor/window have the same styling/design/ux as the default editor

earnest talon
#

I had an idea that I could override the default style with a custom scaleable image for the background.

gloomy chasm
#

Best case scenario you could get the background of the window to show as black. But Editor Windows don't support transparency of specific areas.

#

iirc if you dig deep enough in to the source code there is a method to set the alpha of the window, but that is the whole window and I think it doesn't work on Mac

earnest talon
#

yeah I think Macintosh overall doesn't support that due to finder limitations

#

I can live without the external window curve

#

some in-editor panels I may do curved.

gloomy chasm
#

Please don't

#

(I mean it is your thing you can do what you want. But if you plan on sharing it, it makes it a lot harder for others to use)

earnest talon
#

the main reason I want to do a custom design is so I can use different colors and do a custom top-bar.

#

curved is more or less not necessary anyway

#

plus this isn't going to be shared as I'm just trying to see how far I can take Editor Window design before I do anything further with the concept

#

like Editor Window Animations.

#

better to experiment and rule out than to never have experimented at all

gloomy chasm
#

There is almost never any need to add special coloring to controls in the editor. Simple labels and or icons work basically all of the time and allow for a consistent editor experience

earnest talon
#

That may be the case for a lot of examples.

#

but again, experimenting is better than never trying at all.

#

Popup windows are still a handy thing and even if I find I don't want to do this idea further, I will have learnt more than I will have if I didn't.

#

Thanks for the conjecture too, I'll keep it in mind for UI/UX.

placid finch
#

How come editor classes don't need to have the ExecuteInEditMode attribute?

#

I'm really new to editor scripting

waxen sandal
#

Because Unity calls methods in Editor classes outside of playmode

placid finch
waxen sandal
#

Yes

#

It's called whenever the inspector is redrawn

placid finch
waxen sandal
#

No

#

It can be, but most of the time it isn't

placid finch
#

oh, so does pressing an editor button redraw the inspector?

waxen sandal
#

Yes

#

Whenever anything in the ui changes

placid finch
#

I see! Thank you

placid finch
waxen sandal
#

Window specific

#

The inspector isn't redrawn when something unrelated is changed

placid finch
earnest talon
#

also if you want to do it every frame (which can be inefficient on a case-by-case basis)

#

you can just use the update void and call Repaint() repeatedly.

#

not recommended but it's an option....

cosmic inlet
#

quick question, is there a way to delete an edge? like a function in graph view?

supple swift
#

Heya. Is it possible to draw properties just like the inspector would draw them in an editor window if you have the serialized object of the type you want to be drawn in the editor window. I can't quite get this to work like the inspector. The closest I get is by using serializedObject.GetIterator() but that looks more like all the properties are in a big array and not like the inspector would do.

gloomy chasm
gloomy chasm
#

Is there any case where a UnityEngine.Object could be referenced by an serialized field of an asset and not have a GUID?

#

(debating storing string references to ObjectReferences via asset GUID instead of GlobalObjectID)

lapis drum
#

what does it take to get the Unity Editor to display properties of array members in the array list?

visual stag
lapis drum
#

I have a MonoBehavior that has an array of objects that has properties including and int and a Sprite

visual stag
#

If that object is marked as serializable its members will appear as long as they are also serializable

lapis drum
#

when I add a new object to the array, it just shows me a blank text box

#

with @Serializable?

#

sorry, @SerializeField

visual stag
#

[Serializable] on the class, and the members have the usual public/[SerializeField] requirement

lapis drum
#

okay, I think I was missing the []

#

hmm, autocomplete still isn't giving me Serializable

visual stag
#

it's in the System namespace

lapis drum
#

yeah, I just found it

#

thanks!

#

sometimes it's the obvious stuff

#

hmm, still not showing anything

#

This should be all I need, right?

[Serializable]
public class GameTiles : MonoBehaviour
{
[SerializeField]
public GameTile[] gameTiles;
}

[Serializable]

public class GameTile : MonoBehaviour
{
[SerializeField]
public int weight = 0;
[SerializeField]
public Sprite sprite;
}

visual stag
#

MonoBehaviours are inherently serializable, so the attribute is redundant.
[SerializeField] on a public variable is redundant.
Having GameTile be a MonoBehaviour means that you'll just see an Object field in the list, where you drag and drop components into the slots.

#

If you just want classes in that list without objects in the scene then that type shouldn't inherit from MonoBehaviour

lapis drum
#

should it just be standalone then?

visual stag
#
public class GameTiles : MonoBehaviour
{
    public GameTile[] gameTiles;
}

[Serializable]
public class GameTile
{
    public int weight = 0;
    public Sprite sprite;
}```
#

If you need GameTile to be in the scene on different objects then this is not the setup

lapis drum
#

I'm going to use GameTile in a script for match-3 blocks

#

the weight determines how likely a given tile is to be selected

#

Yay! It works now!

#

thanks again

#

that should make it so I can edit the weights on different levels

lapis drum
#

is there any way to make subclasses of the specified parent class selectable in the above array list?

supple willow
#

hey, do we have Odin experts here? wanted 2 know how to draw parts of an OdinEditorWindow manually

#

something like EditorGUILayout.PropertyField(SerializedObject(this).FindProperty("MyInt")); but in Odin style

vapid prism
#

Is there some way to have an "OnEnable" or "OnCreate" for a property drawer using IMGUI? I need to configure a GenericMenu whenever my property drawer is first created. If not, bad hack solutions are also welcome

supple willow
vapid prism
#

Wait constuctors are allowed? Interesting. This should fix it for me, thanks 🙂

supple willow
#

@vapid prism not entirely. But u mentioned hacky solutions are allowed

peak bloom
#

Any idea how to disable mouse events on the edges in the GraphView?

supple willow
#

Don't remembered what it exactly was tho

orchid rover
#

Does anyone remember how to call the this window, but with their own text? I once saw a friend find it, but now I can't find it.

peak bloom
#

but I guess overriding the HandleEvent for any mouse events should do the job, but i thought there's something builtIn for this

supple willow
supple willow
peak bloom
supple willow
peak bloom
#

aight, I'll see what i can do with it, thanks a ton!👍

#

proly I can just intercept it on TrickleDown instead ?... hmmm

#

well, it works

edge.RegisterCallback<MouseDownEvent>(e => e.StopImmediatePropagation(), TrickleDown.TrickleDown);
flint hinge
#

Can someone help me figure out a solution to my problem?
The custom inspector serializedObject.FindProperty() wont work with a variable that has a Getter/Setter

misty relic
#

I've updated my Unity Project from 2020.1.0f1 to 2021.2.17f1, also the packages JetBrains Rider Editor and Visual Studio Code Editor. since then Reload Script Assembles takes 3~4 sec from previously ~1 sec.

gloomy chasm
flint hinge
#

Thx

supple willow
pure siren
#

Does anyone know if there is a list somewhere of what the built in USS class names are?

soft creek
#

how drunk was this guy when he wrote this

gloomy chasm
gloomy chasm
soft creek
#

nexting

#

bruh

gloomy chasm
#

property.Next(..)

#

nexting

soft creek
#

I know

#

2021.2 doc much better

#

also "to iterator"

#

I to dog sometimes too

gloomy chasm
gloomy chasm
soft creek
#

anyone know my ide literally dies on this line? theres obviously nothing wrong and when I comment out that line - no errors

gloomy chasm
soft creek
#

thanks

#

🙂 c# really needs better compile errors

pure siren
gloomy chasm
mint dragon
#

Is there a better way to add custom behavior to the "+" button in the Editor array list view than to implement a reordable list in a custom editor display and assign the custom behavior in ReorderableList.onAddCallback?
I specifically only want to add a GenericMenu with some pre-built options for things to add to the list on top of adding a custom item.

glacial sail
#

Is it possible to customize this part of the inspector when I select a script file asset?

supple willow
waxen sandal
#

You can probabyl create a generic monoscript editor but I would suggest not to do that

carmine quiver
# glacial sail Is it possible to customize this part of the inspector when I select a script fi...

https://github.com/Unity-Technologies/UnityCsReference/blob/d0fe81a19ce788fd1d94f826cf797aafc37db8ea/Editor/Mono/Inspector/MonoScriptInspector.cs
fyi this is the script for that. Possibly if you make a new customeditor with that attribute it will work

GitHub

Unity C# reference source code. Contribute to Unity-Technologies/UnityCsReference development by creating an account on GitHub.

waxen sandal
#

Because it'll apply to all Monoscripts and thus you might fuck up something

glacial sail
#

Thanks.

#

Well I'm not using it to modify the script, but I just want to be able to use reflection and do some logic

#

Check if the script contains a subclass of a base class, and if so add a "preview" button to that side of the panel that opens up a prefab stage and mount that script.

#

I don't think that could mess anything up?

karmic ginkgo
#

@glacial sail

        [UnityEditor.MenuItem("CONTEXT/MonoScript/test")]
        public static void test()
#

this works

glacial sail
karmic ginkgo
#

three dots as well

glacial sail
#

I mostly want it on the inspector view because I can also add fields to let me setup values for the preview.

#

My second option would be to have my own editor window and have it detect selection change (but that requires an extra click to switch to the window, or have it permanently take up screen space)

#

Third option would be to bring up this window via a menu item/keybind.

#

Would be nice if I could just append to the current inspector, or whatever the term is.

karmic ginkgo
#

you can do it

#

afaik you can grab existing editor windows and position yours, did that long ago

#

tho just keeping it as a tab is also an options

#

we have lots of those

glacial sail
#

Hmm yeah

#

I guess it's not worth the hassle to save that 1 click.

#

I'll just make it in my own editor window and dock it as a tab somewhere.

delicate pivot
#

Hey, need your help guys
I want to make a tool where my colleagues reference all components to reorder under a category

exemple: I want to add a "Camera" category, where any gameobject implementing any of the red-arrow components will be under

#

what I have:

#

what I want:

#

problem: I reference "monoscript" in my list but I want any component, wheter it is implemented by Unity (Camera/Transform/etc.) or by the team (any of the monobehaviour scripts we write) is it possible?

#

for now I have ```cs
m_scripts[_index] = EditorGUI.ObjectField(_rect, m_scripts[_index], typeof(MonoScript), false) as MonoScript;

delicate pivot
#

nah that's not the problem

#

i dont want to reference only monoscript

#

but any component from unity

#

whether it is a monobehaviour or anything we implement

#

any of these

carmine quiver
#

var allComponentTypes = UnityEditor.TypeCache.GetTypesDerivedFrom<Component>();?

delicate pivot
carmine quiver
#

I dont know what the type collection is

delicate pivot
#

GetTypesDerivedFrom<Component>() returns a typecollection

carmine quiver
#

What is your question exactly?

delicate pivot
#

when I click here, I want to reference any component like when you click the "add component" button in a gameObject

delicate pivot
#

but add it to my list

carmine quiver
#

Ok cool, use var allComponentTypes = UnityEditor.TypeCache.GetTypesDerivedFrom<Component>() to get all the types.

#

Are you confused how to add the elements of a TypeCollection to a List?

delicate pivot
#

no, i am confused about what to put here

#

because you cant put a TypeCollection here

carmine quiver
#

And thats not what you want either right, you dont want a collection of types there. You want a single type

delicate pivot
#

yes

carmine quiver
#

So you have an ObjectField, which can show UnityEngine.Object. This cannot show a System.Type, which the type collection contains

afaik there is no UnityEngine.Object for the type of Camera.

#

Why dont you do a Popup, with the types?

delicate pivot
#

that's.. actually not a bad idea

carmine quiver
#

In case you are interested how Unity does it

delicate pivot
#

thx

peak bloom
#

reorderable ListView doesn't support for multiple items reordering at once?

#

it has listV.selectionType = SelectionType.Multiple; but when dragged, only single item actually reordered

#

also in the context when listV.reorderable set to true

peak bloom
#

so basically we can create our own custom shapes for our UIs...

#

dayum Unity, you're in the right direction.. for once, at least

cosmic inlet
#

how can I call the Initialize phase before OnCreateGUI()?

#

I need to create a custom window and pass a variable to it, before OnCreateGUI() is called

#

like a constructor

waxen sandal
#

Call it in your ShowExample method

#

Since you have the instance

cosmic inlet
#

but I can't pass the data from another script then

waxen sandal
#

Are you not calling ShowExample from another script?

cosmic inlet
#

it doesn't work

#

no

#

it's a built in function

#

even if I do this it doesn't work

waxen sandal
#

Then ShowExample has to find the object and use the data somehow

cosmic inlet
#

yeah

#

and I can't figure out a way

#

ok I solved it

craggy latch
#

How can I prevent the scene view camera from zooming on scrolling? I've tried this with directly setting it back to little success (at best it jitters), and I've tried eating the event but that's just too destructive to other editor stuff. Any advice?

craggy latch
#

.
Scratch that, from some more digging I think it's straight up not possible so I've just got to pick my poison. New problem.
How can I set the active object in the hierarchy? I've used Selection.activeGameObject and activeTransfrom and the like, and they do select the object I want. It doesn't show that properly in the hierarchy though. Any idea why?

crude relic
#

@craggy latch wasn't I talking to you about this problem before?

#

it's definitely possible

craggy latch
#

Not without either eating the event or setting it back after it happens.

crude relic
#

you can eat the event without it being "destructive to other editor stuff"

craggy latch
#

Oh?

crude relic
#

here, let me rustle up some of my code

craggy latch
#

I thought it was either that the event existed and so would be used to zoom, or didn't and nothing could use it.

crude relic
#

I mean, if you override zoom then you won't be able to zoom

#

that's a given

#

but you can conditionally control that

craggy latch
#

Ye but I mean things like OnSceneGUI also get eaten if you use the event up.

crude relic
#

that is not the case lol

#

you're doing something wrong then

craggy latch
crude relic
#

yes I know that

#

you can't eat all of the events

#

you need to only eat the event you're using

#

here's a method overriding left mouse click (arguably more important than scroll wheel)

private void HandleMouse ( Event evt ) {
    if( evt.type == EventType.MouseDown && evt.button == 0 ) {
        var worldMouse = GUIExtras.GUIToWorldPoint( evt.mousePosition );
        var gridMouse = new Vector2Int( Mathf.FloorToInt( worldMouse.x ), Mathf.FloorToInt( worldMouse.y ) );
        SetCursorLocation( gridMouse );
        evt.Use();
    }
}
#
private void BeforeSceneGUI ( SceneView scene ) {
    activeScene = scene;

    var evt = Event.current;

    toolId = GUIUtility.GetControlID( FocusType.Passive );

    if( evt.type != EventType.Repaint ) {
        DoToolbar( activeScene );
    }

    if( evt.isKey ) {
        HandleKeys( evt );
    } else if ( evt.isMouse ) {
        HandleMouse( evt );
    }
}

here's the BeforeSceneGUI callback

craggy latch
#

I think I'm treating events a little too much like frames in my head then if eating on doesn't really matter beyond the specific thing that's happening.

crude relic
#

this is directly plugged into beforeSceneGui

#

in the first snippet I am eating the event

#

but I'm only eating it if it is specifically a MouseDown event with the left mouse button (that's what button == 0 means)

#

if I were to just put Event.current.Use() at the end of my BeforeSceneGUI method, then yah I'd be eating layout, repaint, mouse, and keyboard events

#

that would give you the symptoms you're describing

craggy latch
#

Ah, I see my mistake then.

crude relic
#

everything shares the same Event.current

#

it's like one of those conveyer belt sushi places

#

you can pick up and eat the sushi you want -- as long as you get to it first -- but if you eat every sushi you come across there's nothing left for anyone after you

craggy latch
#

TIL - I shouldn't eat all the sushi.

crude relic
#

nope, you'll get sick

#

There's also some things you should understand about hotControl, but I'm not sure you need it for just overriding scroll behavior

#

so that can be a topic for another day

mint dragon
#

If you have a non dyanmic Font in unity is there a way to stop the editor from spamming warnings when you assign that font to a GUIStyle? If you don't set it in the style it won't render; but if you do unity logs Font size and style overrides are only supported for dynamic fonts.

nova condor
#

Anyone happen to know a way to tell, for a prefab variant you have selected in the project, if a given property on a given component is overridden from the base?

mint dragon
#

So I've found where the warning for my non dynamic font sizes is coming from in the source code

        {
            if (settings.font != null && settings.font.dynamic)
                return settings;

            if (settings.fontSize != 0 || settings.fontStyle != FontStyle.Normal)
            {
                if (settings.font != null)
                    Debug.LogWarningFormat(settings.font, "Font size and style overrides are only supported for dynamic fonts. Font '{0}' is not dynamic.", settings.font.name);
                settings.fontSize = 0;
                settings.fontStyle = FontStyle.Normal;
            }```
I tried force assigning the fontSize and fontStyle in the GUIStyle to match the statement and even put an if block in the GUI update to not render the GUI element if the values aren't assigned correctly like this
```if (_buttonStyle.fontSize == 0 && _buttonStyle.fontStyle == FontStyle.Normal)
                {
                    if (GUI.Button(position, new GUIContent(label), _buttonStyle));
                    {
                        ShowPicker();
                      
                    }
                }```
and I'm STILL seeing the warning when the Button renders.
silver phoenix
#

I am trying to write an editor that has a property field to select assets from the project(no scene) When i set the type and try to select an asset there is nothing listed. I was hoping to be able to select a prefab by component. Is it at all possible. Currently i can assign the values but have to manually drag it in. This is using the UI Builder

gloomy chasm
supple swift
#

Is it possible to split inhering classes into different serlized objects. Lets say we have 2 classes. Class2 that inherits from Class1. When class 2 gets a serlized object it will have data from both Class2 and Class1. Would it be possible to make 2 new serlized object one of which only contains the properties for Class1 and one which only contasin the properties for Class2?

gloomy chasm
#

What is the goal/reason for wanting to do that? Maybe I can suggest an alternative solution?

dense agate
#

Hi everyone.
I have a problem with a Custom Inspector for my current project. I Would need a SerializeReference and Subclass Selector for a Generic type.

        [SerializeReference, SubclassSelector]
        public IAbilityDataScore<IAbilityScoreContainer>[] m_AiScores = Array.Empty<IAbilityDataScore<IAbilityScoreContainer>>();

This is how it looks inside the Code. Does anyone of you has a quick idea if its even possible to get a prober Selector here ?

gloomy chasm
dense agate
gloomy chasm
dense agate
dense agate
#

i think im trying to get data thats impossible to reach.

#

okay nvm ... GetType().UnderlyingSystemType.BaseType.GetGenericArguments() gives me the answer but DAMN This looks messy.

crude relic
#

welcome to reflection

#

it gets messy

digital spoke
#

want to draw a list of classes and have those classes have a custom property drawer but this happens..

#
[CustomPropertyDrawer(typeof(Option))]
public class OptionDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        EditorGUILayout.PropertyField(property);
        EditorGUI.EndProperty();
    }
}

Option being the type of the class in the list

#

why aren't they drawing in the correct place

digital spoke
#

anyone know anything about xNode?
For options, I want to have a port for when the option condition returns true and when it returns false

I have a list of 'option's and option is just a simple class

public class Option
{
    public string text;
    //If true, condition(s) will act as a roll. You'll be able to choose this option but will go to a different result based on if it's true or false
    public bool isRoll;
    //Conditions needed to be able to choose this option
    public OptionCondition[] conditions;
    //Only used/set by AdventureEngineParser. If false, button is disabled and cannot be chosen.
    public bool canChoose;
    [Output] 
    public Node onTrue;
    [Output]
    public Node onFalse;
}
#

however not sure how to turn these specific fields into ports

#

since the Option is contained in a list
I have to draw the list and then draw Option and draw those two fields as ports

supple swift
# gloomy chasm What is the goal/reason for wanting to do that? Maybe I can suggest an alternati...

so I made an editor script that goes through properties of a class and splits them into menus based on property attributes to easier edit a large section of properties on a script. The thing is though that this breaks when using inheritance since the editor script will get the serlized properties it need to draw the property in the editor window and the fields it needs to detect attributes in different orders. The serlized properties start at the base class where as the fields start at the child class.

soft creek
#

Is there any way to call a method from a serialized property? for example I'd like to call the GetArgs() method on the serialized field foo:

[Serializable]
public class Foo {
    [SerializeField] float f;

    public float GetArgs() {
        return f;
    }
}

[Serializable]
public struct Bar {
    [SerializeField] Foo foo;
}

#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(Bar))]
public class BarDrawer : PropertyDrawer {
   public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
      EditorGUI.BeginProperty();
      if (GUI.Button(position, "Run Bar")) {
         var foo = property.FindPropertyRelative("foo").objectReferenceValue as Foo;
         var args = foo.GetArgs();
         // do something with args
      }

      EditorGUI.EndProperty();
   }
}
#endif
#

but I get the error: "Der Typ "UnityEngine.Object" kann nicht mit einer Verweiskonvertierung, einer Boxing-Konvertierung, einer Unboxing-Konvertierung, einer Umbruchkonvertierung oder einer NULL-Typkonvertierung in "Foo" konvertiert werden. [Assembly-CSharp]"
basically you can't convert from UnityEngine.Object to Foo

#

also how do change the language of the error messges? I changed all language packs in vs installer to english?

waxen sandal
#

You can't

#

You can find it though through reflection and the property.serializedObject.targetObject field

#

Language is probably based on your currentculture

tough cairn
#

is it possible to inject a drop down element inside all shader graph nodes ?

glacial sail
#

I feel like I'm missing something, I have a ExecuteAlways MB and Update does work, but it doesn't seem like IPointerClickHandler works?

#

For context, I'm trying to make my own UI button and make it also work in editor where I can click it in scene view and it will do something.

cosmic inlet
#

Ok so I might have just messed up. I've been informed that Unity's Graph View is no longer being developed, and is being replaced instead with another system, that has no documentation. Is there any way I can keep that package in future Unity versions?

cosmic inlet
#

Ok great!

#

So what the fuck do I use then

#

I just, wasted a month.

#

Gotta fucking love Unity sometimes!

cosmic inlet
#

Wait but

#

Someone from Unity posted a github page for it-

#

Incase it isn't safe to use anymore

slim zinc
cosmic inlet
#

I mean

#

I did

#

I don't need more than what it does

#

Idk, there's no documentation on anything else

#

And I know how to use this one

slim zinc
#

don't ever think that you definitely never will extend your tool

slim zinc
cosmic inlet
#

And I know another package that has all the features I could ever possibly need that uses the old system

#

I think it uses that one

cosmic inlet
#

I'll try to look into it more

slim zinc
#

the off doc docs (as i like to call these) are imo always much better understandable than the standard unity docs

cosmic inlet
#

I genuinely don't know if Graph View is actually deprecated

#

I can't find anything about it online cause there's like so little resources

gloomy chasm
#

@cosmic inlet There is no official word on GraphView, and it is being 'widely' used (numerus unity packages and asset store assets use it) so it is still safe to use. I don't see it going any where for at least a couple of years.

#

That is assuming that it even is 'deprecated' internally

slim zinc
cosmic inlet
#

Yeah I saw someone mention that they thought it was a bad idea to use it because of the "Experimental" part

gloomy chasm
cosmic inlet
#

So then they snet a link to the github page in case something were to happen

#

Ok well, at least I don't have to stress now

slim zinc
gloomy chasm
#

ReorderableList is in the internal namespace but has been in for years and is widely used

#

So just because something is in a 'experimental' or 'internal' namespace doesn't actually mean that much

cosmic inlet
#

Ok thank you!!

tough cairn
#

isn't shader graph is build on Graph View API ?

slim zinc
#

still. people, update your api's damnit. technical debt and long deprecated features are a cancer of development

gloomy chasm
gloomy chasm
tough cairn
#

🙂 that's a question lol

tough cairn
gloomy chasm
#

Just get the node and traverse it's ancestors (or children)

#

simple UITK stuff

tough cairn
#

sounds like difference in opinions rather then fact

#

maybe seek other plugins / assets from the store that have long term support ?

gloomy chasm
#

Well, they have documentation on it, so regardless of anything else, it is 'intended' for public use which means they will not remove it hastily

slim zinc
tough cairn
#

@gloomy chasm u know how to inject UI ?

slim zinc
gloomy chasm
tough cairn
#

will that work without modyfing shader graph source code ?

gloomy chasm
tough cairn
#

i like IMGUI

gloomy chasm
tough cairn
#

i want to add drop down on top each shader graph node

slim zinc
gloomy chasm
# tough cairn i like IMGUI

That is fine, I like IMGUI too, but I like UITK better. And it is simply a fact that UITK is the future of all editor tooling UI in Unity.

gloomy chasm
tough cairn
#

¯_(ツ)_/¯

slim zinc
#

don't use 3rd party assets for things you can do natively in unity......

gloomy chasm
gloomy chasm
tough cairn
peak bloom
#

is there any callback in the Editor for when the name of a gameObject was changed?

quartz nebula
# peak bloom is there any callback in the Editor for when the name of a gameObject was change...

Not that I'm personally aware of, I just use a janky Update() check for when the current name and last seen name of a derived class are not equal, and then raise my own event if necessary. Possibly useful, here's a stackoverflow post about a library called Harmony. https://stackoverflow.com/questions/4538017/monkey-patching-in-c-sharp

peak bloom
#

Just remembered there's OnValidate function, which I can utilize just for this use case

peak bloom
#

also see this

#
Actions that trigger this event include creating, renaming, reparenting, or destroying objects in the current hierarchy, as well as loading, unloading, renaming, or reordering loaded Scenes.
karmic ginkgo
#

well thats a big thanks, didnt know about renaming

peak bloom
#

me too, kinda handy

strange light
#

I have this script to create diferent files in the Asset folder. But the TextFields doesn't work, they don't update and i dont undestand why. Thanks for the help.

using UnityEditor;
using UnityEngine;
using System.IO;
public class CreateFile : EditorWindow
{
    public string editorWindowText = "Choose a file name: ";
    public string editorWindowTermination = "Choose a file extension: ";
    string newFileName = "New File";
    string newFileTermination = ".txt";


    static void Create(string name, string term)
    {
        Debug.Log(name + term);
        string copyPath = "Assets/" + name + term;
        if (File.Exists(copyPath) == false) // do not overwrite
            using (StreamWriter outfile = new StreamWriter(copyPath))
                outfile.WriteLine(" "); //File written

        AssetDatabase.Refresh();
    }

    void OnGUI()
    {
        string inputName = EditorGUILayout.TextField(editorWindowText, newFileName);
        string inputTermination = EditorGUILayout.TextField(editorWindowTermination, newFileTermination);

        if (GUILayout.Button("Create new file")) 
        {
            Create(inputName, inputTermination);

            Debug.Log(inputName + inputTermination);
        }


        if (GUILayout.Button("Cancel"))
            Close();

        this.Repaint();
    }

    [MenuItem("Assets/Create/Text File")]
    static void CreateProjectCreationWindow()
    {
        CreateFile window = new CreateFile();
        window.ShowUtility();
    }
}
karmic ginkgo
#

you have to use the same string as param and return

strange light
#

what do you mean?

karmic ginkgo
#

TextField accepts a string

#

that string will be available in the ui to edit

#

after you edit it, it will return a new string

#

to continue editing the same string, you have to supply it next frame

#

the same string

strange light
#

But I have inputName as the return value, right?

karmic ginkgo
#

the new string is returned every frame

#

you have "hello world" you type D it returns "hello worldD"

#

and since you are giving it the string that doesnt change, it will display the same thing in the field every frame

strange light
#

🤔

#

And how to I change it?

karmic ginkgo
#

its not that hard, just give it the same string as i said earlier

#

same reference

strange light
#

I'll try

#

Thanks

#

okay i'm stupid

#

thanks

gloomy chasm
# tough cairn but possible with reflection somehow ?

Its complicated. iirc the GraphView will 'destroy'/'unload' nodes once they go out of the view a certain amount. So it isn't as simple as just finding the node and adding an element to it. However if it was, then all you would need to do is to get the shadergraph window via reflection and Resources.FindAllObjectsOfType, and then traverse the rootVisualElement until you find the node you want and then add it to that element

tough cairn
gloomy chasm
#

But if you can do something 'normally' you can do it via reflection

tough cairn
#

scanning the whole tree 2 times per second shouldn't be too expensive im assuming

gloomy chasm
#

Open up the UITK debugger and inspector the SG window to figure out the hierarchy and the 'path' to the element you want

tough cairn
#

true

#

is there a way to get all opened shader graph windows somehow ?

gloomy chasm
tough cairn
#

that method is really a life saver

#

wait so FindAllObjectsOfType will only work for the elements inside the window , or rather it can also find the window itself ?

gloomy chasm
tough cairn
#

i see , so it should do the trick then

gloomy chasm
#

Yup, it is actually the only way to find editor windows if you are not referencing them

#

GetWindow(..) actually uses that internally to get the window

gloomy chasm
tough cairn
#

lol

#

ill try this way

#

thanks

gloomy chasm
#

Good call haha

quartz nebula
deep light
#

silly question, but how would I be able to group several script fields into a dropdown like this one, with a custom inspector?

tough cairn
#

it will automatically do the grouping of the parameters

deep light
#

yeah I know bout that, but I was wondering if it could be done via a custom inspector, since I'm not really up to change every single reference to have the class infront

tough cairn
#

sounds like you need a custom attribute

gloomy chasm
deep light
#

oh my

#

alright will give it a shot rn

tough cairn
#

trying to add child at index 0 with no luck ...

var title = container.Children().First(); container.RemoveAt( 0 );
var contents = container.Children().First(); container.RemoveAt( 0 );

var btn = new UnityEngine.UIElements.Button();

btn.AddToClassList("profile-node-dropdown");
btn.text = "injected";

contents.Add( btn );
container.Add( title );
container.Add( contents );
gloomy chasm
#

You need to use element.hierarchy.Add(..) instead

#

Also, you can use both the indexer or ElementAt(..) to get a child at an index

tough cairn
#

what's an indexer ?

gloomy chasm
#

something[index]

#

it is the [ ]

tough cairn
#

element.hierarchy[0] ?

gloomy chasm
#

Yup

gloomy chasm
# tough cairn `element.hierarchy[0]` ?

Just in a general sense, not UITK specific. Like how lists and arrays work, you can actually implement an indexer in your own classes and they can take any value, not just int.

// Mock spline class...
public class Spline
{
  // get a position along the spline given a time value.
  public Vector3 this[float t]
  {
    get { return _curve.Evaluate(t);
    set { _curve.AddPoint(t, value);
  }
}
tough cairn
#

oh i though that the indexer parameter was limited to int

#

looks like i might use that later , thanks 🙂

gloomy chasm
tough cairn
tough cairn
#

actually looks ok im my case

gloomy chasm
#

Well if it works for you!

tough cairn
#

is there UI Elements way to add icons ?
i got it working with a IMGUI so far :

var button = new Button();
button.Add( new IMGUIContainer( () => 
  GUILayout.Label( EditorGUIUtility.IconContent("d_Toolbar Plus") ) ) );
gloomy chasm
#

If you just want a 'icon button' (a clickable icon) I normally just use an Image and add the Clickable manipulator to it

tough cairn
#

cheers

button.Add( new Image { image = EditorGUIUtility.IconContent("d_Toolbar Plus").image, tooltip = "Create new profile" } );
glacial sail
#

Editor folder can be nested anywhere and doesn't have to be directly under Assets, right?

crude relic
#

correct

#

If you use assembly definition files it doesn't even have to be called Editor

#

@glacial sail ping in case you missed it

glacial sail
#

Thanks.

gloomy chasm
crude relic
#

yah, but that's way less fun

#

😄

glacial sail
#

My scripts in Editor folder doesn't get autocomplete, any idea how to fix it?

#

Using VS Code.

#

Moving them outside of Editor makes them work, but that's not ideal obviously.

#

Nevermind, restarting O# and it works again, classic O#.

crude relic
#

what is O#

glacial sail
#

OmniSharp, what powers C# in VS Code.

crude relic
#

ah

#

never seen it written like that

karmic ginkgo
#

need to detect when editor has just launched, is there a native way?

waxen sandal
#

InitializeOnLoad with SessionState checking whether it's already executed this session

karmic ginkgo
#

nice, thanks

peak bloom
#

is it possible to detach children of visualelements from the parent so it can be parented to another?

feral dagger
#

Hello channel I am currently working on a project where i need to have two very different build targets. One is building Unity as a library for android and the other one is building a standalone App for android. The difference is a few settings in the project settings and one setting in the preferences. And i am currently stuck on finding a way to set certain project settings. Namely the custom manifest and gradle template checkboxes. Does anyone know if and how this is possible from an editor script?

tough cairn
#

is there a EditorUtility.DisplayDialog that allows the user to enter a string ?

green palm
gloomy chasm
#

Same with components

green palm
green palm
#

(I should add that I've managed to get it working for GameObjects, mostly by replacing the parts that say transform)

gloomy chasm
#

I think the way that would work in every scenario is to inject UITK elements in to the inspector. But that would involve a good bit of reflection and fancy code

green palm
#

Noted, thank you. Only just approaching reflection, so sounds a bit out of my depth for now. Throwing this out there in case you (or anyone else) has any alternative suggestions to achieve my ultimate goal: which is to have some extra buttons in the inspector for all objects

gloomy chasm
green palm
glacial sail
#

How do I make EditorGUILayout.ObjectField for Texture2D display inline instead of this?

#

I've found that using GUILayout.MaxHeight(16f) works but that's a hardcoded height, is it defined anywhere?

#

Actually the correct value should be 18 instead, but yeah that's kind of the problem.

crude relic
#

try EditorGUI.singleLineHeight

hoary grove
#

Anyone using MyBox? I'm running into a strange issue, I'm using [DisplayInspector] but its showing twice:

Edit: Moved over to NaughtyAttributes. Problem solved.

glacial sail
halcyon pine
#

Is there a good resource for learning about writing modules to extend Unity's Sprite Editor? I saw Sprite Editor Window functionality can be extended by providing custom module. but that is... less than entirely helpful. I'm not really sure where to begin, since I don't have much experience with Unity's UI stuff.

waxen sandal
#

Looks like you inherit from this and implement those methods somehow

halcyon pine
#

Yeah. The 'somehow' is what I'm hoping to figure out. 😄

waxen sandal
#

What are you trying to achieve?

#

Because the api looks pretty straight forward assuming you only have to implement it and Unity finds and creates it for you

#
 public class SpriteExtension : SpriteEditorModuleBase
    {
        public override bool CanBeActivated()
        {
            return true;
        }

        public override void DoMainGUI()
        {
        }

        public override void DoToolbarGUI(Rect drawArea)
        {
        }

        public override void OnModuleActivate()
        {
        }

        public override void OnModuleDeactivate()
        {
        }

        public override void DoPostGUI()
        {
        }

        public override bool ApplyRevert(bool apply)
        {
            return true;
        }

        public override string moduleName { get; } = "Test";
    }```
and it shows up in the Sprite Eidtor in the dropdown
finite cliff
#

Does anyone know what this error means when making a custom editor?

Assertion failed on expression: '!(o->TestHideFlag(Object::kDontSaveInEditor) && (options & kAllowDontSaveObjectsToBePersistent) == 0)'
UnityEditor.HostView:OnLostFocus ()

essentially I go to create a SO that the editor references, and as soon as I click off the SO turns white in the project and loses it's UI obviously, and the console shoots this error at me..

#

Unity 202.3 3.31f in case it matters

#

seems to be stemming from:
hideFlags = HideFlags.HideAndDontSave;

#

🤔

waxen sandal
#

Can you show your code

glacial sail
#

Is there cleaner way to do this or do we just have to litter like this everywhere we need edit mode specific logics?

#if UNITY_EDITOR
    if (Application.isPlaying)
    {
        Object.Destroy(_gameObject);
    }
    else
    {
        Object.DestroyImmediate(_gameObject);
    }
#else
    Object.Destroy(_gameObject);
#endif
static gyro
#

Hi guys, posted this #archived-shaders message
But also asking myself if its not more Editor based.
Are we supposed to create a custom Editor UI for Shadergraphs ?

delicate pivot
#

hey
i Have two buttons styled like this using UIElements

#

how could I style them like these (without using Stylesheets if possible)?

finite cliff
#

not sure how visible this is but I'm trying to put labels inside this grid of buttons, but a label seems to offset my button by a lot; how would I offset a GUILayout button?

#

or maybe a better question would be "how do I make the label take up less space"
edit; added GUI.Label

peak bloom
#

which some you can incorporate it with InitializeOnLoad

glacial sail