#↕️┃editor-extensions

1 messages · Page 77 of 1

naive canopy
#

first line is just reserving a space

#

it's a solution, but I'm sure any other viable solution is probably going to better

#

if you can figure out what those other solutions are

ivory fulcrum
#

What is spriteSerial?

#

Because that actually is how I want the Object Field to look for each letter but with a Label underneath

naive canopy
#

SerializedProperty spriteNameSerial = serializedObject.FindProperty("SpriteName");

ivory fulcrum
#

hmm and SpriteName is the texture2D object?

naive canopy
#

yeah, actually it's a sprite, I forgot to change it

ivory fulcrum
#

Does it have to be a sprite?

#

or does it not matter?

naive canopy
#

I don't think it maters

#

texture2D works too, but in my case I'm working with sprites

#

so when I select to change one of them, it shows me sprites instead of texture2d's

ivory fulcrum
#

Ok.

#

I'm working with Textures since I only need the texture saved

naive canopy
#

hmm

#

you know

ivory fulcrum
#

I can generate a sprite automatically from the texture at will using Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f))

naive canopy
#

if you have your object that contains a char and a texture2d

#

you should be able to pull out the properties the same way

#

In my case I'm using spritesheets

#

since you can iterate through a serialized list, you can pull out each serializedobject, and from then get both of the serialized properties

#

and do whatever with them

#

for your List<Letters>

ivory fulcrum
#

That's what I'm trying to do

#

I'm also wondering if I should be using "BeginProperty" to define the editor instead of PropertyField

naive canopy
#

not sure there

#

you might want to store the characters as strings

#

so you can use stringvalue on the serialized property

#

you might also be able to just cast the objectReferenceValue as char, but I don't know if that will work

ivory fulcrum
#

Right now what I'm running into is I can get the Object of Letter, but...

#

Although, I'm getting a NullReferenceException

naive canopy
#

can you post your code somewhere

ivory fulcrum
#

Yeah, hang on. There's some discarded code commented out in there too that might give you an idea of some things I've tried.

naive canopy
#

yeah about half of my code is that lol

ivory fulcrum
#

It's also by no means complete

#

But hopefully it will give some context

#

CustomUI is a Naninovel thing

#

And it just made sense to me to subclass it and add on my values for its editor

#

Instead of making a "new script"

#

Especially since I may need to reference those UI values in Naninovel

#

Not sure yet. I might separate it out later on

#

the code under "testing code" is me playing with Intellisense

#

to find out what I can do with what the classes provide

#

Which tends to be how I use C#

#

Otherwise I'd be pouring over the documentation and it would take a lot longer for me to write the code

#

I could probably break LetterList out of the LetterMinigame class so it's its own class

naive canopy
#

hmmm

ivory fulcrum
#

Anything stick out?

naive canopy
#

Just wrapping my head around it, you write a bit differently than I do

#

I figured you were using List<Letter> instead of wrapping it around another class

ivory fulcrum
#

That probably comes from the other languages I've worked with

#

I have the other class because a lot of lookups happen through type

naive canopy
#

Letters isn't a property of LetterList

ivory fulcrum
#

Where "I can find this for you" or "I can do these replacements, but I want to replace an entire type's editor" or "I want to find that data by 'type'"

#

I don't want ALL lists of Letters or lists of Texture2D to be replaced with my editor

#

or find all the textures that are in lists

#

So I wrapped the type so that only wrapped types get found or get replaced

#

idk, maybe that's a faulty assumption on my part about how it works

#

but that's my understanding so far

#

Letters? Letters is an object of LetterList in my LetterMinigame class

naive canopy
#

var list = property.FindPropertyRelative("Letters");

ivory fulcrum
#

hmmm

#

wait... so I should be doing "GetArrayElementAtIndex, and then getting the properties of that?

naive canopy
#

I meant more that Letters is not the property of any class

ivory fulcrum
#

😮 because it replaces LetterList..... not the whole Minigame!

#

OHHHHHH

#

Ooof

naive canopy
#

yeah you will likely have to use GetArrayElementAtIndex or some other array accessor

#

either against the serializedobject or the serializedproperty

ivory fulcrum
#

EditorGUI.PropertyField(rect, property.GetArrayElementAtIndex(index));

#

right?

naive canopy
#

so you need to pick an object out of the array

#

and then properties out of that object

#

the editor doesn't like anything except primitives and things that derive from the normal unity objects (sprites/texture)

#

does that make sense?

ivory fulcrum
#

yes

#

hmmm

#

So if there should always be 26 elements, should the ctor for LetterList (I'd have to write one) create those?

#

Because it's complaining that the elements are "null" which makes sense if the elements haven't been created yet

naive canopy
#

right

#

Not sure how you are planning on storing it

#

I'm sure someone else might be able to help you more, I'm pretty new to this stuff

ivory fulcrum
#

That makes 2 of us

#

LOL

#

Oh, if you refresh the link I gave you, it should have some new code

#

Still a bunch of nulls. I'll keep working on it

naive canopy
#

you should attach to it

#

and debug it from there

ivory fulcrum
#

I've... never done that before

#

I've always debugged by guess and check

naive canopy
#

oh..

ivory fulcrum
#

Well... that's not entirely true, but I've not really used the debugger with Unity

#

Well.... here goes nothing

#

I just pressed the "attach to unity" button

naive canopy
#

yep

#

and then you put in some breakpoints right before hit horks

#

and check your variables

ivory fulcrum
#

Ok. I'll try it

severe python
#

is there a known solution or strategy for virtualizing controls in a scrollview?

gloomy chasm
#

@severe python What do you mean?

ivory fulcrum
#

Shouldn't property.serializedObject.targetObject be of the type that CustomPropertyDrawer takes as its argument?

gloomy chasm
ivory fulcrum
#

So what I want then is

var target = (LetterMinigame)property.serializedObject.targetObject;
var list = target.Letters;
#

And then I can make sure that Letters is instantiated, has the 26 default elements, and then can construct the EditorGUI.PropertyField's

gloomy chasm
ivory fulcrum
#

Yes but unfortunately List<T> does

gloomy chasm
#

Why access the list directly?

ivory fulcrum
#

Because that's where my NullReferenceExceptions seem to be coming from.

#

Trying to create the PropertyField is where it chokes because the index doesn't yet exist

#

Even though in the ctor for the List<T> derived type, it constructs 26 elements with default values

gloomy chasm
#

You shouldn't be getting a NullRefException from SerializedProperty. If you want to share the code through Hastebin or something I could take a look at it if you want.

ivory fulcrum
#

I already had a repl.it up so I just pasted in there

#

if you prefer hastebin I can make another link for that

gloomy chasm
#

Na, this is fine.

onyx harness
#

You are mixing both worlds (C++ & C#), you are straightforwarding a headache

#

Either stick to Serialized stuff (C++) only, or use the List (C#) and stay away from SerializedObject/Property.

#

To be fair, you can toy with both worlds, but you need to have solid understanding of how serialization works.

gloomy chasm
#

@ivory fulcrum One thing I notice is that you are deriving Letter from UnityEngine.Object, you con't actually do that. Anything derived from that requires something on the C++ side as well (If memory serves)

onyx harness
#

To give you an easy debug, use the iterator (SerializedProperty) of SerializedObject, and print the propertyPath of every iterations using Next(true).

ivory fulcrum
#

Ok. I read that deriving from that is a way to allow serialization, but I didn't know if it was necessary

#

It doesn't have to be and I thought that might be part of my problem.

onyx harness
#

Remove it, simple class with attribute Serializable can be serialized

#

When you derive from Object, it means you can physically exist in the Project as an asset.

ivory fulcrum
#

ahh. Ok

ivory fulcrum
#

Mikilo: Is that the only reason you said I was mixing both worlds?

#

Also. What kind of nonsense is it that you cannot use a "white texture" or any other default texture in a constructor or serializer?

#

You can't use null, nulls aren't allowed. Ok, I'll use a default white texture. NOPE! that's not allowed either.... well frick!

onyx harness
#

There is a high chance that the white texture is generated at runtime and can't be saved, but that assumption needs a confirmation

onyx harness
onyx harness
ivory fulcrum
#

I'm not even talking about the deserialization, I just mean the default texture unless assigned

#

Also it all looks like C# to me

#

I haven't used C++ in years

onyx harness
#

This implies 2 things.
When you create it the first time, the white texture 'might' be correctly assigned.
But when you reload (recompile, loading from disk, restart Unity) the texture assignation will probably be gone. Hence the deserialization check

ivory fulcrum
#

when I say "nope" I mean the editor throws exceptions all over the place about it

#

It's not that it "doesn't work" in the sense of You get your editor but nothing saves, but rather that it breaks completely

#

I can live with "nothing saves".

onyx harness
ivory fulcrum
#

Everything I've seen says to use SerializedObject and SerializedProperty

onyx harness
#

Which is good, but then don't use target in the middle (your list used in the loop)

#

This is where you start mixing both

ivory fulcrum
#

where I got the property.serializedObject.targetObject was from the debugger telling me where it was getting these null references from

#

or seemingly where

#

Because it creates an object, and then the SerializedProperty has another copy under that nesting that has null entries

#

Maybe I was misinterpreting what I was seeing in the debugger but that was what was "null" and then after that I got the Null reference exceptions

ivory fulcrum
#

OMG who designs this!?

fresh shell
#

Hey guys, does anyone have any ideas why this code works in adding to a fields right click/context menu in 2017-2019 but in the 2020.1 and up it doesnt work at all?

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    EditorApplication.contextualPropertyMenu += OnPropertyContextMenu;
    //My property code
    EditorApplication.contextualPropertyMenu -= OnPropertyContextMenu;
}

private void OnPropertyContextMenu(GenericMenu menu, SerializedProperty property)
{            
    menu.AddItem(new GUIContent(LOCK), _locked, Lock);
}
hushed ginkgo
#

Is there anything like UnityEvent but for checking properties? I'm making something like state-machine and I'd like to have list of properties (from other object which I can drag to list) to be true or whatever

severe python
#

@gloomy chasm i meant that rendering 1000 rows in imgui is expensive. I'd like to virtualize that result in a sense. I figured out how to do it though

#

Its Not actually virtualization

gloomy chasm
#

oh, well glad you figured it out!

ivory fulcrum
#

Wait... am I right in thinking that events in the Inspector call "OnGUI" when they happen?

#

.... It's an update function

#

No wonder this is so hard to wrap my head around. They have an update function to produce the gui AND handle events, etc, and on top of that use a ton of global state.

#

And layout is all done by manually calculated Rects.

naive canopy
#

OnEnable() only happens once when I click on something right?

ivory fulcrum
#

So I refactored to get rid of the LetterList class..... (Ok, not completely got rid of, I turned it into a static extension method class) and now my custom GUI isn't even being used.

fresh shell
#

Is it a generic? Cuz unity won’t serialized generics

hard spindle
#

I keep getting "Invalid editor window UnityEditor.FallbackEditorWindow" when I start Unity up and sometimes while running, but it doesn't stop the game from being compiled. I think it's because I tampered with the Unity Editor a bit ago, and has not gone away. Is there a way for me to remove it?

hard spindle
#

The editor layout could not be fully loaded, this can happen when the layout contains EditorWindows not available in this project

onyx harness
#

Use the Layout popup at the top-right corner

hard spindle
#

The warning still appears when I make save my own layout

#

It hasn't completely barred me from entering my project yet though so that's cool

onyx harness
#

Means you are opening a Window that is failing somehow

hard spindle
#

Hmm

onyx harness
#

If you change the layout and close Unity

#

When you reopen it should be good to go

#

Whatever Window you open, something is wrong about it

hard spindle
#

I'll worry about it later I guess

ivory fulcrum
#

Fuzzinator: It's a concrete generic. It's a List<Letter> where Letter is a serializable class. It's fine with List<T> in any other context. It was ok with it when I wrapped it in a not generic class.

unkempt surge
#

How would I go about modifying the way an object is displayed in an array?

onyx harness
#

PropertyDrawer

unkempt surge
#

I don't want "move location" or "script to call" to display if "Dialogue" is selected as the action type, for instance

#

right, i'll look into that, thanks

#

well that's useful

onyx harness
#

Best thing Unity did for the Editor world.

ivory fulcrum
#

Is that really the issue though? LIst<Letter> can't be replaced by PropertyDrawer?

onyx harness
#

PropertyDrawer applies on each element of a collection. Not the collection itself.

ivory fulcrum
#

Ok. So I need a PropertyDrawer to replace Letter, not List<Letter>

#

How do I make it so that the List is Expanded?

#

I don't need the "size" and "expand" fields

#

That's part of what I want to customize

#

Forget it. I'll just buy Odin and use that

somber mesa
#

It doesnt actually render out any frames.... ?

#

I can see on line 55 that it is calling ScreenCapture

#

" ScreenCapture.CaptureScreenshot($"frame_{m_RecordedFrames++}.png" "

#

but i never get that file... and there is no further documentation >????

somber mesa
#

Also Im not sure I put this in the correct channel....

heady jungle
#

Never had this problem before, but this small bit of code (for a custom inspector) causes the editor to crawl when in play mode:

    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        EditorGUILayout.PropertyField(green);
        if (green.boolValue)
        {
            contextButtons.InsertArrayElementAtIndex(0);
            EditorGUILayout.PropertyField(contextButtons.GetArrayElementAtIndex(0));
        }

Then again, I'm still unclear on exactly what to put where (as I'd guess that it's trying to apply the array parts constantly?)

waxen sandal
#

Going to guess it's adding elements constantly

heady jungle
#

Yea, would it be prudent to make a check to see if the bool value has changed since the last update, then based of that modify (or not) the array element?

Or should I just keep the array fixed at 5 (for predefined buttons) and use bool values to decide whether to display them or not?

gloomy chasm
#

@heady jungle Yeah, as Navi said. As long as green is true, it will add an array element every time OnInspectorGUI is called (I think default is 20 times a second?)

#

=======
Got a question of my own. How do you make sure a custom field supports prefabs/overriding? I mean like show that it has been overridden, and have the context menu and stuff?

waxen sandal
#

Use changecheck @heady jungle

#

I don't remember the conditions exactly but using serializedproperties for everything gets you quite far @gloomy chasm

heady jungle
#

Merci, that is perfect 🙂

gloomy chasm
#

@waxen sandal It functionally works okay. But there is no visual indication, and it is for a tree/hierarchy data structure so I want/need to handle the overriding in a custom way. But I haven't been able to find much on how to do it.

waxen sandal
#

Using propertyfield or something else?

#

Also wrapping in begin/end property should do things

vestal sand
#

is it possible to put variables into TMPro rich text???

gloomy chasm
#

@waxen sandal AH! That does exactly what I wanted! Thank you! 😄

#

@vestal sand Nope, at least as far as I know. Unless you mean threw code, then yes you can.

whole steppe
#

i need help and this boys saying to go here can you help me ?

gloomy chasm
#

@whole steppe Don't ask if you can ask for help or ask if someone can help you. Simply say what the problem is that you are asking for help with and if someone is able to help you with the problem they will.

whole steppe
#

I need help with my code

#

@gloomy chasm

gloomy chasm
#

@whole steppe Just say what the problem is. If someone can help, they will.

whole steppe
#

Can I send you the code here?

#

@gloomy chasm

gloomy chasm
#

@whole steppe Don't send it to me. Just put the problem here. If that includes code than post that too. If it is a lot of code, then use something like Hastebin and post a link to it instead of posting the code directly.

whole steppe
gloomy chasm
#

@whole steppe You have to say what the problem is as well. Otherwise people won't know how to help you.

whole steppe
#

i have errors

#

@gloomy chasm

gloomy chasm
#

@whole steppe You have to be more specific. You need to say what the errors are and where they are at.

whole steppe
#

When I want to start I can not move up, down, right, left and I have a script for the controller and do not let me move!

#

@gloomy chasm

gloomy chasm
#

@whole steppe So this isn't actually the right channel for your problem. #💻┃code-beginner would be a better channel where you would get more help.

nimble idol
#

This method works in Unity 2019 but not in Unity 2020. Any idea what replaced it?

"MethodInfo findMethod = typeof(UnityEventBase).GetMethod("FindMethod", ..... )"

Is there a way for me to view the source code of UnityEventbase?

nimble idol
#

Thanks!

gloomy chasm
#

Any way to change the background for the items in TreeView? I can't find any.

whole steppe
#

@gloomy chasm I was told to come here:)

barren belfry
#

There are probably worse places to be told to go. 🙂

whole steppe
#
using System.Collections.Generic;
using UnityEngine;

public class MouseLook : MonoBehaviour
{

    public float mouseSensitivity = 100f;

    public Transform playerBody;

    float xRotation = 0f;

    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }
}```
#

pls

#

help me

near flume
#

@whole steppe Send the error message you're getting

#

Exactly what's in the console

whole steppe
#

this is my error

near flume
#

Oh, did you fix the problem you were having earlier?

#

I don't know that language

whole steppe
#

yes no longer appears

#

srry:)0

near flume
#

Not a problem

gloomy chasm
#

@abstract pendant I believe so.

#

I would assume so.

violet veldt
#

Sorry if this is a super common question, but is there any way to wire MonoBehaviours into interface variables in the inspector

gloomy chasm
#

@violet veldt Unity does not support polymorphic serialization of UnityEngine.Objects, which includes interfaces. So no, not unless you do custom serialization and property drawer.

left gate
#

Hello, How do I get the component for a overriden property in a prefab?

#

PrefabUtility.GetPropertyModifications(prefab)'s .target is the source prefab's component

#

which is not what i want, i want specifcally the instance of the component that is being overridden

candid linden
#

I'm trying to make a custom editor for a component to add a button but want to keep all the exposed properties without having to rewrite them in the custom editor. How can i do this?

gloomy chasm
left gate
#

Or atleast I assume it does,the instance ids do not match up

gloomy chasm
left gate
#

Correct

left gate
#

converting the component to SerialisedObject, then checking prefabOverride does the trick

#
var so = new SerializedObject(component);
                            Debug.Log(so.FindProperty("m_Asset").prefabOverride);```
solar basin
#

i have hundredths of these, is there any way to add some function like public Texture2D GetIcon() { return this.Icon; }

lucid hedge
#

I'm trying to create a grid of color fields

#

but I'm stuck with these spaces in the middle.... I would want them gone

#

I use the following code

#
            for (int y = 0; y < paletteSize.intValue; y++)
            {
                c = EditorGUILayout.ColorField(GUIContent.none, c, false, false, false, GUILayout.Width(35),GUILayout.Height(20));
            }
            EditorGUILayout.EndHorizontal();```
gloomy chasm
#

@lucid hedge Do you mean the vertical ones? Or the horizontal ones?

lucid hedge
#

the space between the red squares vertically is fine, I mean the horizontal ones yeah

#

so I don't want the large spaces between the columns, I want them to be just as small as the spaces between the rows

onyx harness
#

Stop using layout

lucid hedge
#

Don't know what else to use lol, how else do I draw a color field, if not with editorguilayour.colorfield or guilayout.colorfield?

#

Before, I just drew rects and that was fine, perfect grid, they were clickable and all, but I didn't know how I could trigger the opening of the color picker?

#

That didnt seem possible

onyx harness
#

EditorGUI.ColorField

gloomy chasm
#

Simply not setting the width should do, shouldn't it?

lucid hedge
#

Tried that as well but then my colorfields looked squashed, but that's probably something on my side. I'll try using editor GUI instead of fighting layout

lucid hedge
#

Thanks for the help, both :)

gloomy chasm
#

I have a property drawer that has a TreeView in it, but I can't for the life of me figure out how to make it Reload when property is changed with Undo/Redo. Any ideas?

random willow
#

What is a good tutorial that through gizmos and scene specific implementations?

onyx harness
gloomy chasm
onyx harness
#

OnDestroy?

#

hum....

#

-= then += perhaps

gloomy chasm
#

There is no OnDestroy 😦

gloomy chasm
onyx harness
#

ofc you'll to handle the null case in your callback

severe python
#

Anyone happen to know if there is a good wa yto get the AssemblyDefinition that would contain a .cs asset?

#

So I'm using AssetDatabase.GetDependencies on the assets in the Assets array on the Manifest (middle column inspector)

#

and thats getting the CS files, and I want to actually discover the assemblies, which I'll use somewhere else other than the assetbundle build

opaque rivet
#

getting this with TMPro looked everywhere and it i dont know to get rid of the assembly reference

onyx harness
# severe python Anyone happen to know if there is a good wa yto get the AssemblyDefinition that ...
using System.Text;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEditor.PackageManager;
using UnityEngine;

namespace NGToolsEditor.Internal
{
    static class PrintAssembliesSources
    {
        [MenuItem("NG Tools Internal/Print Assemblies Sources")]
        public static void Print()
        {
            var    list = Client.List(
#if UNITY_2018_1_OR_NEWER
                true
#endif
            );

            while (list.IsCompleted == false);

            foreach (var item in list.Result)
                Debug.Log(item.packageId);

            Assembly[]        playerAssemblies = CompilationPipeline.GetAssemblies();
            StringBuilder    buffer = Utility.GetBuffer();

            foreach (Assembly assembly in playerAssemblies)
            {
                Debug.Log(assembly.name);

                buffer.Length = 0;

                for (int i = 0, max = assembly.sourceFiles.Length; i < max; i++)
                    buffer.AppendLine(assembly.sourceFiles[i]);

                Debug.Log(buffer.ToString());
            }
        }
    }
}
gloomy chasm
#

@onyx harness I am getting errors, but I think I just need to do more/better null handling... Though it says that the tree wasn't initialized. I will clean up some of my code and see if I can get it to work. Thanks.

severe python
#

oh you just already have a solution lol

#

awesome, thank you

#

Do you happen to also have a solution for all my complicated asset bundle building processes? :p

onyx harness
#

I don't unfortunately 😄

severe python
#

this is a rabbit hole I should not have dove down, but I don't really think I had a choice

severe python
#

This also solves other problems, I also needed to figure out how to deal with assembly reference handling, and this provides a path to that, which is awesome, huge help @onyx harness

gloomy chasm
#

For UIToolkit ListView, how can you register KeyDownEvents with the item's them selves. I want to be able to press the delete key to remove the selected item. But it isn't working. I assume because the ListView itself already registers the event for the arrow keys.

left gate
#

I wish to run a script to find any "added component overrides" on any prefab. How can I achieve this?

#
                var path = AssetDatabase.GUIDToAssetPath(guid);
                var prefab = PrefabUtility.GetPrefabInstanceHandle(AssetDatabase.LoadAssetAtPath<GameObject>(path));//null
                prefab =PrefabUtility.LoadPrefabContents(path);// unpackaed instance of the object```
#

when I use PrefabUtility.LoadPrefabContents it seems the object that is returned is unpacked. i.e. is not a prefab which means PrefabUtility.GetAddedComponents(prefab) does not work on the object

half scroll
#

how do i check if an array is null in a SerializedProperty?

gloomy chasm
#

@half scroll Unless using [SerializeReference], unity does not support serializing null values. So the array will never be null.

half scroll
#

so i should just check if its length is 0 instead?

half scroll
#

thanks @gloomy chasm

whole steppe
#

something wrong with my editor

#

it kinda loads old material

#

whenever i launch editor

#

but the material is saved

#

weird

#

do i need to save the .asset file after every change?

#

and the material

waxen sandal
#

If you're doing editor scripting then yeah you need to save it after editing it

#

If you're not then 🤷

half scroll
#

am new to editor scripting am I setting the value incorrectly here? animSetInstance is not null yet after i assign it to the objectref it says the property is null in the log

Debug.Log(animSetInstance); //Not null

animations.GetArrayElementAtIndex(animIndex).objectReferenceValue = animSetInstance;

Debug.Log(animations.GetArrayElementAtIndex(animIndex).objectReferenceValue); //Null
waxen sandal
#

Gotta apply your serializedobject

#

Or something else could be going on but looks correct to me

#

Finding the array element might return a new instance that has the old data not sure htough

half scroll
#

I tried applying first but its still null apparently

Debug.Log(animSetInstance); //Not Null

animations.GetArrayElementAtIndex(animIndex).objectReferenceValue = animSetInstance;

serializedObject.ApplyModifiedProperties();

Debug.Log(animations.GetArrayElementAtIndex(animIndex).objectReferenceValue); //Null
whole steppe
#

i think its rewritted

#

whenever i launch unity

#

the material is saved

#

when i quit

#

but its different color when i open it

#

cant really find which function does that

hardy apex
#

can anyone ELI5 how to appropriately mark a scene as dirty when I'm modifying an object in a scene with a custom extension? I've seen a few different methods but I'm not sure what the "correct" approach is

#

I'm also unsure of how to store the state of an object so that it can be modified with undo/redo, I believe this may be a similar issue
EDIT: disregard, setting the object state with "Undo.RecordObject" appropriately marks the scene as dirty and stores the last state of the mesh

drifting forge
#

can I make a custom ctrl + c(opy) and ctrl + v(paste) for my editor window?

onyx harness
#

Yes

#

I implemented it in NG Tools Free

drifting forge
#

:o

#

do you have a link to an explanation?

#

cause I cant find anything

onyx harness
#

Event.Type == Command

#

If commandName == "copy" or "paste", then do something

drifting forge
#

oh :o

#

i will try that out right when i get out of bed tomrrow

real ivy
#

Ive been asking stuff in #📲┃ui-ux about UIE, and it seems no one is really knowledgeable there...
All the UIE gurus seems to be here, but.. if i have question with UIE runtime, should i still ask there (more appropriate?) or here (more effective, i think) ?

#

And... im gonna move my question here while im at it:

Is this gonna work?
inputPrice.RegisterCallback<ChangeEvent<string>, int>(SetPrice, (int)element.userData);
If i change .userData later on, will it use that new value when the callback's triggered?

gloomy chasm
gloomy chasm
#

@onyx harness I finally figured out how to handle removing a method for the undo callback in a PropertyDrawer.
Honestly, I am pretty happy with it, looks pretty clean, and I can't think of any other way to handle it.

private void OnUndoPerformed()
{
    // There is no OnDisable/OnDestroy method for PropertyDrawers, 
    // so there is no way to know when it is no longer being drawn,
    // so inorder to know when to remove the callback, we see if it has already been called without being reset. 
    // If it has, we can assume that it is no longer being drawn sense undoCalled is reset in OnGUI.
    if (_undoCalled)
        Undo.undoRedoPerformed -= OnUndoPerformed;

    _undoCalled = true;
}
onyx harness
gloomy chasm
real ivy
#

So im doing drag and drop runtime, and...
Kinda wondering what's so special about ve.AddManipulator(new MouseManipulator)
Im seeing it being used in the TextureDragger example (albeit this is for editor)

Seeing some repetitive issue people are having to make DragNDrop, mostly by this same guy
https://forum.unity.com/threads/drag-events-not-working-at-runtime.973467/
In some post, he said he used MouseManipulator for a same window case, and did NOT use it for inter-window drag drops

Inside MouseManipulator, in the example, it's just some more RegisterCallback<MouseDownEvent> etc

So yeah. Why not just directly do the RegisterCallbacks in the element. Why use MouseManipulator?

#

Is it just to make it "neater" ? Fair enough
But i want to handle the callbacks from the outside, and if i have to use a class for it, then... i have to make a delegate in the class, that gets triggered when the MouseDown etc are called inside the MouseManipulator. And from the outside, register my specific method to this delegate. Is this the proper usage?

onyx harness
severe python
#

is there an easy or standard way to deploy a set of Packages to use for a project?

onyx harness
#

The manifest?

severe python
#

basically I want to have a set of entries in the ProjectRoot/Packages/Manifest.json

#

I mean as a redistributable

#

I was going to use a UnityPackage for it, but that doesn't seem to work

#

I was trying to move away from having users clone a project repo

candid linden
#

I am trying to set a property in a gameobject in the scene with a script when a button in the inspector is hit. However when I hit play, the property I have changed is null. What's the correct way to set a property during an editor script?

#

These properties are serializable

real ivy
#

Im trying to disable game input when any inputField is active
Using uGui, this is done by checking all Selectable.allSelectablesArray

Is there an equivalent in UIE ?

gloomy chasm
real ivy
candid linden
gloomy chasm
severe python
#

its way easier to use them than not to, get over the learning curve and you will save a lot of time

candid linden
#

Okay, well me not using them isn't working for some reason. I found Undo.RecordObject and have been using that. If I set int or float property during the editor-time script, this works. If I set a GameObject reference, this never gets serialized correctly

#

Would a serializedObject help me with setting game object references?

severe python
#

is there some high quality crash course on SerializedObject and SerializedProperty somewhere?

candid linden
#

I'm looking at the documentation, it's sufficient

#

I basically am asking if serializedObjects can handle setting component/gameObject references

severe python
#

I'm partially curious because I'm wokring on a project that pulls people with little to know experience into using Unity and they may find themselves wanting to build some editor extensions

gloomy chasm
#

mySerializedProperty.objectReferenceValue = myGameObject

candid linden
# gloomy chasm It can.

These gameObjects exist in the scene. I should be able to set their references and have them exist after hitting play right?

severe python
#

yes

candid linden
#

🤞 cheers for the help

severe python
#

Really, anything that derives from UnityEngine.Object can be assigned to mySerializedProperty.objectReferenceValue in order to persist it

candid linden
#

I was getting UnityEngine.UnassignedReferenceException or something when hitting play in my various attempts to get this to work

severe python
#

Be warned, you can do that even if the type of that field does not match the object you assign it

#

which enables fun shenanigans, but can also cause terrible problems

candid linden
#

the data I'm serializing is quite structured, hope this works with Lists and Lists of structs

severe python
#

given this type

public class MyExample : ScriptableObject {
      public Material myvalue;
}
public class MyExampleEditor : Editor {
  public void OnEnable(){
    serializedObject.FindProperty(nameof(MyExample.myvalue)).objectReferenceValue = new GameObject();
  }
}
#

this is totally valid syntactically, but obviously will cause some problems

candid linden
#

thank GOD it worked. Thanks again for the help!

quaint zephyr
#

Hey guys, how ya’ll doing? It’s been a minute. Wanted to ask, I have a situation that generates quite a bit of colliders. Sometimes I need to select the parent object that holds it, and because of that it draws all the collider gizmos, which severely slows down the performance of editor. I don’t want to completely disable the collider gizmos. So I’m am looking for something like OnSpecificGameObjectSelected() => DisableColliderGizmos(). And when it deselected, re enable the gizmos. Is this simple to do? And how?

waxen sandal
#

There's Selection.selectionChanged and I don't remember the name but there's some gizmo utility iirc

quaint zephyr
#

Thanks. If someone can provide me with a bit more context, I’d appreciate it.

jagged coral
#

Is there a way for those of us without deep pockets can get access to the source code for UnityEditor? Specifically, I'd like to extend SerializedProperty, SerializedPropertyType and the PropertyDrawer stuff. I'm not sure the best way to go about that without looking at the source.

onyx harness
#

You can C# extend, but not override the classes.

jagged coral
#

Thanks

honest dune
#

I saw this post looking around how to set up a custom editor for some SO I have, just so I can keep stuff more clear for myself

#

How does one even implement something like this?

waxen sandal
#

^

honest dune
#

So you create a separate script that defines how the scriptableObject custom header is drawn in the SO? Is this just essentially overriding the header?

gloomy chasm
#

@honest dune What is it that you are wanting exactly? In that tweet, what they are doing is have a custom attribute that they add to the fields in their script that makes it look like a header (or something else).
Is that what you want? Or are you wanting to be able to full customize the look of the inspector for a ScriptableObject? If that is the case, then you want to look at this: https://docs.unity3d.com/Manual/editor-CustomEditors.html

honest dune
#

Uhh, I just want a header like that. I have a Skill SO but else than looking at my comments in the actual SO Script it can be a bit annoying to create new skills since I sometimes take a break and am not exactly sure what some attributes do, so I want to clarify that when you make a script.

#

Like this is literally all I want right now honestly, and I can use two Headers with an Order but the second header being the same size etc makes it a little bit jarring. I just don't wanna delve too much in custom attributes/customeditor since it's just a small clarity thing.

gloomy chasm
# honest dune Uhh, I just want a header like that. I have a Skill SO but else than looking at ...

Ah, then you do want the attributes then. Just so you know Unity has a couple of decorative attributes builtin that you can use.
There is [Header("My Header")],

[Tooltip("This a tool tip that will show up when hovering over the label of the field in the inspector")]

[Range(0, 1)] // Makes a numeric field a slider

[Space] // Puts a space between two fields

[HideInInspector] // makes it so the field does not show up in the inspector

[Multiline] // make a string be edited with a multi-line textfield.

[Min(0)] // make a float or int variable in a script be restricted to a specific minimum value.

There are more, but those are the most used ones.

honest dune
#

Thanks. Yeah I think I just wanted it clean like how that twitter post has it (A Large header, then the sub header explaining) but I think Tooltip will work fine.

onyx harness
#

This is a mistake to mention them as decorators

gloomy chasm
onyx harness
honest dune
#

Ah, so a propertyDrawer is like the Min/Max slider and stuff

#

and a DecoratorDrawer would be like the header?

onyx harness
#

Exactly

honest dune
#

So is it like Overriding? Like a customGUI or whatever edits the original Header one, so if I wanted like a two argument header with a sub like [Header("Main Header","Custom Description")] It'll edit the original script or w/e?

gloomy chasm
honest dune
#

Ah. So I'de essentially be making a new custom attribute that you like have to define via drawing in the inspector I guess

onyx harness
honest dune
#

So just make a smallHeader implementation and stack it with the regular one

onyx harness
#

If Header is enough, yep

trim heart
#

I have an issue with vscode. I installed 2020.2, open a project in vscode. the code works without issue in Unity, but in vscode I have a bunch of false errors

#

there's a bunch of those false errors in the code, any idea what's wrong?

#

I have the vscode package in unity, I have the c# extension + .netcore in vscode

trim heart
#

hmm, now it works. it took a couple of minutes, as if the vscode intellisense took that long to load up

#

still taking suggestions, it used to work instantly

#

maybe a bug with 2020.2?

fossil gyro
#

Hi, does anyone know how to create an empty gameobject inside a prefab?

#

@trim heart i currently have a lot of (false) errors inside VSCode too, using Unity 2019.4 right now

severe python
#

Is there a standard way to add a root folder to the Project window? Root meaning the folders Package and Assets?

gloomy chasm
severe python
#

yeah, I'm digging into the source now, it does look doable... it doesn't look like it would be fun to do

#

No matter

onyx harness
#

I'm interested in the outcome by curiosity

torpid bobcat
#

does anyone know how i can get rid of all those .meta files or just show C# scripts?

#

like in visual studio

quaint zephyr
#

Does anyone know if the following affects memory/performance:
I have 6 variations of an item, depending on it's state and mode. If I create all six in blender and export them as a single fbx. Then place it in scene and SetActive(false) all but the needed one. Versus, separate each one into it's own GameObject and have each their own script keep track of state and active state.

Would the former or the latter be more tolling on performance/memory? Or is there a more effective approach?

trim heart
#

@quaint zephyr 1 object vs 6 objects. which one do you think is more demanding ^^

quaint zephyr
#

I understand. But I'm also trying to balance graphic performance. If I have a single object with 6 children, will setting them to inactive, be the same as if I had that 1 active object separate?

torpid bobcat
#

oh thanks lol

onyx harness
#

Just remember one thing, hiding meta is highly not recommanded

main grove
#

How can i add more tabs here if i want all my UI in one tab and icons in an other?

heady jungle
#

I'm getting so confused by editor scripts. How do I get an enum (set IN the editor script) to appear and be editable?

[CustomEditor(typeof(ContextButton))]
Public class ContextButton_Editor : Editor{
  public Button_Enum buttonEnum;
  public override void OnInspectorGUI(){
    if (buttonEnum == Button_Enum.blue){
      //Draw stuff;
      }
  }
}```
#

The only way I can get it to show up is with EditorGUILayout.EnumFlagsField(buttonEnum); but that defaults to buttonEnum 0 and doesn't let me change it. All the examples I find assume that the enum if being called from the non-editor portion of the script

#

I was missing a cast: buttonEnum = (Button_Enum)EditorGUILayout.EnumFlagsField(buttonEnum);

deep wyvern
#

@heady jungle EditorGUILayout.EnumPopup

#

EnumFlagsfield is for Flags (notice you can selecte the option "Everything"?)

heady jungle
#

I got it, just read to read over all what I can do with the editor options before I continue, thanks though

waxen sandal
#

Or just propertyfield if you want the default behaviour

fossil gyro
#

Is there some kind of event I can listen to when a prefab instance gets unpacked by the user?

gloomy chasm
#

Been messing around with the inspector and got it so that I can lock the inspector to only show either Assets, or Scene Objects. Not that complex really, but was fun to do!

#

It saves the lock state on editor reload too!

quaint zephyr
#

Am I understanding this correctly? If I have a parent that is SetActive(false) and I have a child, like 3 levels deep also inactive, then I SetActive(true) that child, it doesn't get set to true because one of it's parents is inactive?

visual stag
#

activeSelf will become true, activeInHierarchy will stay false

quaint zephyr
#

@visual stag thanks. I figured out what went wrong. I had an initialization code that GetComponentsInChildren. And this works as long as the container parent is activeSelf during startup. I disable it so scene isn't cluttered, and as a result they weren't being registered...oddly enough, no NullReferenceExceptions where thrown either. Anyways, fixed it with GetComponentsInChildren(true).

severe python
#

Using Unity's ImGUI can you do 2 pass layout?

#

Meaning, I place all buttons to get all the sizing,m and then the OnGUI runs again and I actually conduct the rendering, making various adjustmusts?

split bridge
#

that's what happens with the Layout/Repaint/Event etc phases of ongui - it may be a battle to work against that

onyx harness
#

Just call Repaint.

severe python
#

I'm trying to work with it not against it

#

I've got a virtualizaing search suggest box I'm remaking in imgui and I just need to figure out what constraints there are on the rendering of options

modest bane
#

Why can I not change the parent of an object created with PrefabUtility.InstantiatePrefab()?

#

I get "Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption" but its not, its in the scene

#

whoops i solved it, as always happens right after posting a Q

keen pumice
#

I wrote a class for a SerializableDictionary. I’ve tested the heck out of it and am pretty confident it works ok. It is compiled into a DLL which I use in other projects.
However, when I use this DLL in a particular game project, and try to delete an entry from the dictionary, I get the follow error and stack-trace

System.Collections.Generic.Stack`1[T].Pop () (at <525dc68fbe6640f483d9939a51075a29>:0)
UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <b17f35b08b864a3ca09a7032b437596e>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <b17f35b08b864a3ca09a7032b437596e>:0)
UnityEditor.GenericInspector.OnOptimizedInspectorGUI (UnityEngine.Rect contentRect) (at <b17f35b08b864a3ca09a7032b437596e>:0)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <b17f35b08b864a3ca09a7032b437596e>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)```
There is no mention of my dictionary code or custom property drawer code anywhere in this stack trace, just unity and system code.  Any suggestions on how I can even start troubleshooting this error message?
waxen sandal
#

If you remove your DLL then the project works?

keen pumice
#

well, if I remove the dll, I cant see the button that generates this error.

#

@waxen sandal

waxen sandal
#

Ah so it's only when you select that object?

keen pumice
#

it's only when I'm trying to delete an entry from my SerializedDirctionary. Figured I see SOME kinda reference to my code in the stack trace tho.

#

but when I click to delete it, I get this error, and it appears like it doesn't actually run my code at all- the entry remains.

waxen sandal
#

Surround it with a try catch?

keen pumice
#

you mean, inside the DLL (recompile it?)

waxen sandal
#

Yeah

#

Just copy it in for now tbh

#

Or use the package manager

#

Assuming that reproduces

keen pumice
#

I guess I could.. but before I start mucking with my release Code, any thoughts on why none of my code shows up in the stack trace?

waxen sandal
#

🤷‍♀️

keen pumice
#

so, the fact that none of my code is in the stack trace does NOT imply it's not related to my SerializableDictionary?

#

(obviously WHEN it happens does imply it's my code)

waxen sandal
#

Apparently not

keen pumice
#

trying it now.. alas not gonna be quite so easy, will let ya know if it catches anything when I get it setup.

waxen sandal
#

Could also post your code

keen pumice
#

oh. wait.. I seem to remember some issue in the past where I made a change during the wrong uh "message loop". perhaps that explains why my stuff isn't shown in the stack trace (it ran in a previous "message loop")?

#

Wrapped the entire OnGUI function in a try/catch, nothing caught. oh, well. Alas, code is far to huge to post. If you, or anyone, has any other ideas how I might cause unityeditor to get confused about the size of a stack, that I never touch myself, would be appreciated.

livid beacon
#

So, I'm creating a custom inspector for one of my scripts, and, basically, I have somethin' like this:

public class MyScript : MonoBehaviour
{
  public bool shouldShow = true;
  public GameObject somePrefab;
}

[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : Editor
{
  public override void OnInspectorGUI()
  {
    base.OnInspectorGUI();
    //...
  }
}

I want to hide somePrefab from the inspector if shouldShow is false.
I came across this solution (the "best answer"):
https://answers.unity.com/questions/192895/hideshow-properties-dynamically-in-inspector.html
Which is nice and all, but he's not calling base.OnInspectorGUI(). What this means is, every time I add a serialized/public field to MyScript, I may have to go into MyScriptEditor and add an extra line. This back-and-forth workflow sounds tedious.

#

My main question is:
is there a way for me to just call base.OnInspectorGUI, then find the serialized property by name and conditionally hide it?

#

e.g.,

public override void OnInspectorGUI()
{
  base.OnInspectorGUI();
  SerializedProperty shouldShow = serializedObject.FindProperty("shouldShow");
  SerializedProperty somePrefab = serializedObject.FindProperty("somePrefab");

  //the part below is what I want to be able to do:
  if(!shouldShow.boolValue){
    somePrefab.Hide();
  }
}
waxen sandal
#

There's a draw property excluding somewehre

#

Oh it's just on the base of Editor

#

Don't forget to apply if there have been changes

quaint zephyr
#

I am getting some strange behavior, perhaps I am not understanding something that's going on under the hood? I have a UI PlayerMenu that opens when the player presses "E" key. In the menu, there is an inventory section that has slots. The slots have children that are SetActive(false) by default.

In my code, if I "pickup" an item, those children become SetActive(true) even if the PlayerMenu is SetActive(false). I can confirm this in the inspector that the checkmark appears on the gameobject correctly. BUT, it is when I SetActive(true) the PlayerMenu, that those children get "reverted" back to their original state (which was SetActive(false))

Why does the parent gameobject keep revert the children back to their inactive states if it is activated? This I confirmed because if I start with the PlayerMenu in active state, then the script deacticates it on start, it doesn't have this behavior. But if I start it with it inactive, this occurs.

waxen sandal
quaint zephyr
#

@waxen sandal thanks. I apologize for posting here. I always get best responses here then anywhere else. I'll try there.

keen pumice
#

@waxen sandal got it, just FYI: was a combo of changing stuff during an event OTHER than Layout, AND the fact that the serialized property function DeleteArrayElementAtIndex will set the element at the index to null, rather than actually delete the array element (only values that are already null, or not nullable, are deleted!)

#

@waxen sandal thanks for the help!

waxen sandal
#

@keen pumice makes sense somewhat

#

@quaint zephyr you sure you're not setting it to inactive?

quaint zephyr
#

Yes because when the "pickup" occurs, I look at the inspector slot's children and see that the checkmark indicates that they indeed are in active state. They are still greyed out because the parent (PlayerMenu) is inactive until the player decides to view what he got. It is when he triggers "OpenMenu" (which all it does is set the menu to active) and that's it. It's as if it remembers they were inactive and reverts them back.

#

Figured it out. Don't fret. Thanks for taking a stab a it.

#

And once again, this is the only place I actually got a response lol.

gloomy chasm
#

Is there a way to check if a SerializedProperty is an element in an array? And more so to get that array if it is?

fossil gyro
#

Anyone else ever had to MarkSceneDirty() on the stage of the prefab window, and then noticed problems with physics (like raycasting)?

drifting forge
#

Hello.
I have a problem.

I made a custom editor using UIElements and UI Builder in Unity 2019.4.1 and now I wanted to import my editor to Unity 2020 but it seems UXML file is completely broken, it also looks completely different... is there a way to repair it?

split bridge
drifting forge
#

hm problem is, I cant use the newest version of ui builder package cause it seems broken

#

throws exceptions and doesn't even give me the window when I install the latest

split bridge
#

I use it without issues* so I would recommend rebuilding your library folder. *well, some issues but yea..

drifting forge
#

how do I rebuild it?

split bridge
#

quit Unity, delete your Library folder, open the project again and it should rebuild.

drifting forge
#

kk

#

hm I did it and it doesn't help

#
UnityEngine.UIElements.VisualElement.Add (UnityEngine.UIElements.VisualElement child) (at <3cdf672c21b849dea215f9c9aff21f77>:0)
UnityEngine.UIElements.VisualTreeAsset.CloneSetupRecursively (UnityEngine.UIElements.VisualElementAsset root, System.Collections.Generic.Dictionary`2[TKey,TValue] idToChildren, UnityEngine.UIElements.CreationContext context) (at <3cdf672c21b849dea215f9c9aff21f77>:0)```
split bridge
#
    "com.unity.ui": "1.0.0-preview.13",
    "com.unity.ui.builder": "1.0.0-preview.11",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.ui": "1.0.0",
    "com.unity.modules.uielements": "1.0.0",``` - those are all my ui related packages and it works fine in at least >= Unity 2020.1.10
drifting forge
#

hm.
I'm thankful for you trying to help me but I'm on a time constraint rn and need to get working on smth different, my editor isn't really core of that work so it's fine, I'll maybe rebuild the uxml file in the future or maybe make a better version of the editor anways.

lanaluThanks

split kraken
#

Hey, I am trying to figure out how to use Event.current in OnGUI, any idea what should be put in Repaint, Layout, etc...? When I put everything that draws in Repaint, I get an error on EditorGUILayout.HorizontalScope, which says Getting control 0's position in a group with only 0 controls when doing repaint Aborting

#

I didn't find any reference to them online, no documentation about it, nothing...

#

And another question regarding GUI, When i used GetLastRect, it works fine, I use it with GUI.DrawTexture and GUI.Label and when I finish, and try to use EditorGUILayout, or GUILayout, the layout is ontop of what I drew in GUI, you can see it in the attached photo

#

Is there a way to update the layout after using GUI? even an explicit way?

simple cove
#

@split kraken don't put your drawing logic inside an if event == type statement

#

even if you include both Layout and Repaint, it won't register mouse clicks etc

severe python
#

Is there a way to have Unity ignore some Assembly files in a package

#

These are not Package Manager packages, they are packages I'm creating in the ProjectRoot/Packages folder

waxen sandal
#

Disable all platforms on the asmdef?

severe python
#

They are dlls not sets of cs files unfortuantely

waxen sandal
#

Don't they still have platform settings?

split kraken
#

@simple cove Why not use the event? some places say to use it, some don't...

#

I don't get the usage of it and there is no docs..

#

My problem is that using GUI wont update the correct Rect value for Layout stuff... and it result in the above image, I tried separate the event by type, Repaint and Layout.
When I try to do VerticalScope, in the Repaint, it wont let me, so I probably will need to do it in the Layout, but HOW? If Repaint is responsible (presumably...) for the drawing stuff, how can I nest stuff in scopes if I can't use VerticalScope in the Repaint?

simple cove
#

use both

split kraken
#

What do you mean?

simple cove
#
var e = Event.current;
if (e.type == repaint || e.type == layout) { .. dRaw(); }
#

but really, this is not proper

#

don't wrap it at all imo.. just dRaw()

split kraken
#

But when I do this, as I stated, the layout is wrong

simple cove
#

I see..

#

are you using Odin?

split kraken
#

using GUI explicitly wont update the Layout

#

no

#

And how do you know about the events? I didn't find a single doc about it, care to share?

simple cove
#

ok so the main idea is:

var rect = GUILayout.BeginVertical();
// use rect here:
GUI.DrawBox(rect);
// add stuff to the layout group:
{
  // ... 
}
#

trial and error 😄

split kraken
#

Okay so now you just wont use Layout

#

you just use GUI

#

that's an extra work

#

instead of using for example, EditorGUILayout.Slider, I will need to provide it with a rect and render the slider and logic myself

#

that is, if GUI don't have slider already (The slider was just an example)

#

I want to use all of them, at the same time

simple cove
#

all EditorGUILayout even does is call the method EditorGUILayout.GetControlRect() anyway

fossil gyro
#

Anyone else ever had to MarkSceneDirty() on the stage of the prefab window, and then noticed problems with physics (like raycasting not working anymore)?

split kraken
#

GUI, GUILayout and EditorGUILayout

#

Even so, how would you render the slider?

#

You can't use GetControlRect if you don't have a a control

simple cove
#

why don't you have a control? 😛

#

step1 have a control :p

split kraken
#

With GUI?

simple cove
#
var rect = EditorGUILayout.GetControlRect(GUILayout.Height(5), GUILayout.ExpandWidth(true));
GUI.Slider(rect);
#

yes

#

wanna share the relevant code so I can see what you have?

split kraken
#

Well, I would know that if there were any docs about it lol

#

Yeah sure, mind if I send it in PM?

simple cove
#

sure, go ahead

grim vine
#

in editor land docs in not always there, and sometimes even the docs makes no effort to explain something. You'd be better off to github and dig the UnityCsReference for examples of how things are used cause there are all sorts of quirks and rarely does a "good" solution exist.

waxen sandal
#

There's plenty of good solutions and practices, they're just not documented anywhere and people don't generally write about them often

#

Since a lot of times it's easier to hack something together

keen pumice
#

@waxen sandal FYI: I was only half right yesterday.. the DeleteArrayElementAtIndex function only setting the array element to null, rather than removing from the list was only PART of the problem. The unity-only-code exception I get when using my custom property drawer seems to now only appear when I use EditorUtility.DisplayDialog("Confirm Delete", "Confirm you would like to delete this entry.", "Delete", "Cancel"); (when I replace the above with true the stack exception thrown by unity only code disappears- which is what I did yesterday during my attempts to fix stuff- then promptly forgot) What is the correct way to use a confirmation dialog like that, from inside a custom property drawer? Do I need to create an editor window or something, to prevent it from blocking property drawer code execution until it returns?

waxen sandal
#

Think I've done that before

#

Not sure why it doesn't work

#

Might be because you're in a certain GUI event?

#

E.g. repaint or layout which causes the issue

keen pumice
#

it certainly seems like it prevents the rest of the property drawer code from running until it returns... I've tried to invoke it only during layout and NOT during layout, alas both give the same result. done that before: you mean create an editor window to open in "parallel" then callback a function of my property drawer, on confirm?

#

oh, haven't tried NOT layout AND NOT paint.. I'll give that a go...

onyx harness
#

You are suppose to interact with the data during input events, not during layout/repaint events.

#

Or you will probably face Object grouping exception stuff

keen pumice
#

darn, that didn't seem to fix it.. I still get a stack exception even when I click "cancel" in the dialog (which does NOT change any data). Have you guys had success using EditorUtility.DisplayDialog in property drawers?

onyx harness
#

Can you show the exception?

keen pumice
#

sure 1 sec

#
System.Collections.Generic.Stack`1[T].Pop () (at <525dc68fbe6640f483d9939a51075a29>:0)
UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <b17f35b08b864a3ca09a7032b437596e>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <b17f35b08b864a3ca09a7032b437596e>:0)
UnityEditor.GenericInspector.OnOptimizedInspectorGUI (UnityEngine.Rect contentRect) (at <b17f35b08b864a3ca09a7032b437596e>:0)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <b17f35b08b864a3ca09a7032b437596e>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
#

property drawer code section, if relevant: ``` if (Event.current.type != EventType.Layout && Event.current.type != EventType.Repaint)
{
if (deleteClick)
{
Debug.Log("delete clicked, opening ConfirmDelete dialog window.");

                        deleteConfirmed = ConfirmDelete();
                        deleteClick = false;
                    }

                    if (deleteConfirmed)
                    { //delete an array element }
                    deleteConfirmed = false;
                }```
#
        {
            return EditorUtility.DisplayDialog("Confirm Delete",
                "Confirm you would like to delete this entry.", "Delete", "Cancel");
        }```
waxen sandal
#

Log the current event before starting teh dialog

keen pumice
#

good idea

#

delete clicked, opening ConfirmDelete dialog window. current event: Used

#

lemme get the type of event also

#

ok, wasn't expecting that: delete clicked, opening ConfirmDelete dialog window. current event: Used Event type: Used

waxen sandal
#

It's probably mousedown or mouse up

#

Which should be fine

keen pumice
#

aight..hmm, darn, guess I'll try a custom editor window to run in parallel (not block the property drawer code), then callback a function in the property drawer to assign the confirmDelete bool. That sound reasonable?

waxen sandal
#

Sure

#

Done that before

keen pumice
#

that seemed to do it, no more exceptions! alas, now I need to actually click the property drawer for it to invoke OnGUI and have the changes take effect ( I always forget how to refresh it manually) searching now...

waxen sandal
#

Repaint

oak umbra
#

hello, how do we add editor functionality like a new window and a button to activate a function from scratch? which docs should I look at to get started? I am creating a spritesheet editor script and it kind of works but I want to make it work from a window with input select slots for file paths and export paths, and a button to activate functions

keen pumice
#

@waxen sandal I had to move the actual deletion (change to data) into that callback, there is no Repaint function for propertydrawers 😦 Working well now- thanks for your help guys!

oak umbra
#

thanks

keen pumice
gloomy chasm
#

For the UIToolkit ListView, how do you get KeyDownEvent for items? I can't figure it out.

severe python
#

IIRC, you create the items the ListView contains by implementing its AddItem action right?

#

Which would mean in that same code you're going to setup a key down event like you would in any other place

#

yeah, so in the Func<VisualElement> MakeItem, you'd do what you'd normally do, something like...

public void OnEnable()
{
  var items = new List<string>(1000);
  for (int i = 1; i <= 1000; i++) item.Add(i.ToString());

  void MyCallback(KeyDownEvent evt) { /* ... */ }
  Func<VisualElement> makeItem = () =>
  { 
    var label = new Label(); 
    label.RegisterCallback<KeyDownEvent>(MyCallback);
    return label;
  };
  Action<VisualElement, int> bindItem = (e, i) => (e as Label).text = items[i];
  var listView = new ListView(items, 16, makeItem, bindItem);

  listView.selectionType = SelectionType.Multiple;
  listView.onItemChosen += obj => Debug.Log(obj);
  listView.onSelectionChanged += objects => Debug.Log(objects);
  listView.style.flexGrow = 1.0f;

  rootVisualElement.Add(listView);
}
#

the caveat here is that there are times when I need to make certain registrations when the element is attached to a panel, so I'll bounce off that, but there may be things I'm not remembering which are not relevant in the general case

#

its been a while

#

its possible that a more appropriate place to register the handler is in the bindItem Action

severe python
#

note, local function not required, I just like local functions

gloomy chasm
severe python
#

well, the last time I used listview was probably on like, 2018.2 or something, when it was all very experimental...

#

I hated it so much I built VisualTemplates lol

#

so like

#

this is my version

#

you know, suddenly I realize its ridiculous that I built in a remove element

gloomy chasm
#

Hot dang, the 2020.1 ListView is so much nice. Or at least is much more customizable and user friendly.. 😦

severe python
#

VisualTemplates is kinda like WPF DataTemplates for Unity, because of that very issue

#

I wanted to be able to have a list view, that automatically rendered the right view for a piece of data it was handed, so that I could just add list views and hand them data, and define templates for that data

#

though, thats really what ContentPresenter does, ItemsControl just makes ContentPresenters and puts them inside itself, and does binding stuff

#

I didn't like that you had to write a Bind method either, it should bind like all the rest of the stuff

#

put in a binding-path to an array

gloomy chasm
#

You know what is really cool about pre 2020.1 ListViews? If you bind a list/array property to them, they add an extra element which is the number of items! Isn't that cool and exactly what you want!

severe python
#

Wait can you use binding-path now?

gloomy chasm
#

Yep!

severe python
#

oh thats awesome, I've been stuck on old versions of unity for too long

#

wait so why do you have to bind then?

#

or

gloomy chasm
#

Well, I use the extension method BindProperty(SerializedProperty arrayProperty) that they give you.

#

You bind them to give specific data to them. Like to name each item, or to give them special fields and stuff.

#

I think it uses the PropertyDrawer for the items by default now, but don't quote me on that!

severe python
#

oh that would be awesome because that basically gives you data templating

#

So, I guess I don't know why that doesn't work, however you could make a subclass of VisualElement and implement the ExecuteDefaultActionAtTarget method in order to ensure you see the events, and then you could figure out stuff from there
https://docs.unity3d.com/Manual/UIE-Events-Handling.html

#

either by debugging the process or just handling it

#

if you go to the bottom of the linked documentation you can see how the event propogation works

#

obviously you would wrap your item content in the custom visual element

gloomy chasm
severe python
#

that makes me think this is a focus issue

#

FocusController.focusedElement

gloomy chasm
#

@severe python Ah ha! It seems the ListView it self gets all of the keyboard focus, which I guess makes sense because it needs to navigate up and down? Idk, but it works if I register to the ListView it self. I was sure I had already tried that though.

severe python
#

never hurts to try something again 😄

gloomy chasm
severe python
#

The most fun! No problem, good luck!

gloomy chasm
# severe python The most fun! No problem, good luck!

Thanks! It can't be much worse than doing reordering/parent with a treeview, using with an actual tree data structure (using SerializeReference). Which is extremely terrible and ugly if you were wondering. 😛

grim vine
#

how to properly Draw Gizmos in the Scene View in Editor mode?

#

i tried the OnDrawGizmos on a MonoBehavior but after setting HideFlags the gizmos disappear (children models are visible tho)

whole steppe
#

i kinda have this funny problem. everyday i launch unity, the code doesnt change but the LineRenderer line shortens. at first it was full circle at 16 positions, then it shortened, i had to increase to 32, now its about 100..
https://i.imgur.com/WkGNI9w.png

#
    void SetOrbitLine()
    {
        Vector3 position = default;
        float angle = default;

        int seconds = completionMinutes * 60;
        speed = 2 * Mathf.PI / seconds;

        Vector3[] updatedPositions = new Vector3[100];
        for (int i = 0; i < 100; i++)
        {
            //angle += speed;
            angle += speed * 10f;
            position.x = Mathf.Cos(angle) * orbitRadius;
            position.y = Mathf.Sin(angle) * orbitRadius;
            updatedPositions[i] = position;
        }

        LineRenderer lineRenderer = GetComponent<LineRenderer>();
        Vector3[] currentPositions = new Vector3[lineRenderer.positionCount];
        lineRenderer.GetPositions(currentPositions);

        if (!currentPositions.Equals(updatedPositions))
        {
            lineRenderer.SetPositions(updatedPositions);
        }
    }
#

i have hard time to tell when it happens, maybe not everyday, maybe every few days

bold skiff
gloomy chasm
bold skiff
#

Oh ok, cool, I'll have to look into those when I start programming more in the morning.

stuck olive
#

is this the right channel to talk about UI Toolkit?

split bridge
stuck olive
#

ah great, well, i am having trouble specifically with listView

split bridge
#

you want elements with different heights?

stuck olive
#

nah that part is fine

#

im following ray wenderlich's intro guide. and the listView part doesn't seem to work the same since he wrote it.

Couldn't get it to appear, let alone style or function.
I read the docs and came to understand that I need to supply at least the following:

  • itemHeight
  • makeItem
  • bindItem
#

so ive got that far, and now it actually appears

#

but even though I've done the binding bit.... i can't figure out how to access the bind item correctly

#
list.onSelectionChange += (o) => {
  Debug.Log(o);
};
#

i have this for example

#

or rather i found this.... but it's a pure object

#

it's ignoring any casts i do

#

i've bound it to a custom object by the way, as per the wenderlich tutorial

split bridge
#

I haven't used listview (never seemed to fit my use-cases) but just looking at the docs page now... it looks pretty awful :/

#

It looks like onSelectionChange returns a list of objects

stuck olive
#

yeah it does

#

but then it whinges at me when i try to unpack any of the objects

#

but yeah im considering ditching the list view and just populating a scrollView manually by adding visual elements in a loop

#

but i'd much rather understand the correct way to unpack selected listview objects xD

split bridge
#

sorry, had to step away. What is it you're trying to convert between? If you put some code on hastebin or something, send a link and I can take a quick look. Can't guarantee I'll be able to help though 🙂

stuck olive
#

ah i think ive got it, it's IEnumerable<object> so I can use LinQ to unpack it

stuck olive
#

pretty much, like this

list.onSelectionChange += o => {
  Debug.Log((DesiredClassWhatever)o.FirstOrDefault());
};
#

and whatever you wanna do with it from there pretty much

split bridge
#

sure - though you probably need to catch some nullrefs there

stuck olive
#

yeah for sure

#

im just glad i can access it at all now lol

stuck olive
#

how do you write comments in USS?

#

same as CSS?

waxen sandal
#

Probably

gloomy chasm
#

@stuck olive The ListView is a bit silly, by default it's flex-grow is set to 0, and it doesn't have a height. So to get it to show up you need to set either the height style property to something, or flex-grow to 1.

solid thicket
#

Anyone know why I keep getting these messages?:
ArgumentException: Getting control 10's position in a group with only 10 controls when doing mouseUp Aborting

It happens on the line:
using (new EditorGUILayout.VerticalScope("box"))
The button I clicked is inside of there (that triggered the mouseUp), but a few lines before that code I used the same VerticalScope line and it was fine, am I missing something?

#

My code is pretty simple.. Its in the OnGUI function:

using (new EditorGUILayout.VerticalScope("box"))
{
    using (new EditorGUILayout.HorizontalScope())
    {
        EditorGUI.BeginChangeCheck();
        selectedCamera.startT = EditorGUILayout.Slider("Start T", selectedCamera.startT, 0f, 1f);
        selectedCamera.endT = EditorGUILayout.Slider("End T", selectedCamera.endT, 0f, 1f);

        // If something has changed
        if (EditorGUI.EndChangeCheck())
        {
            RecalculateCamerasStartAndEnd(selectedCamera);
        }
    }
    selectedCamera.fov = EditorGUILayout.FloatField("Field Of View", selectedCamera.fov);
}
#

Figured it out, needed to use Event.current.Use() on my custom GUI

bold skiff
solid thicket
#
GUI.BeginGroup(timelineArea);
GUILayout.Button("Test");
//GUI.Button(new Rect(10, 10, 50, 20), "Test");
GUI.EndGroup();

Anyone know why the commented line work and the line above doesn't? (The timelineArea rect is fine, I tried drawing a white texture on it and it covers a big area)

#

I also tried GUILayout.BeginArea (which uses the same function `Begin/EndGroup) but failed again

#

@bold skiff What do you mean access these animations?

waxen sandal
#

BeginArea is the one you want not BeginGroup @solid thicket

solid thicket
#

I know, I stated that I tried it

#

It also doesn't work

waxen sandal
#

I know but you haven't given any more context and that's what you should be using

solid thicket
#

Okay, I am just trying to draw some stuff on a big area

#

So I created a rect using GUILayoutUtility.GetRect and got a big area

#

I tried drawing it with GUI.DrawTexture which worked, and I saw the area I wanted

#

When I then used BeginArea, with the given rect, it hasn't worked

#

I tried adding buttons and drawing stuff, it just wouldn't show

#

Even if I try to use GUI methods to draw explicitly at a hardcoded rect

bold skiff
#

I need to access each node to be able to change their animation.

solid thicket
#

@bold skiff I once needed to manipulated the animation system, its kinda funky, you need to use the Animator and the RuntimeAnimatorController

waxen sandal
#

You go through that class to layer to statemachine to state

#

Or sub statemachines

#

@solid thicket Need more code and you should show what's happening instead of what you expect it to do

solid thicket
#
Rect timelineArea = GUILayoutUtility.GetRect(
                GUIContent.none, 
                new GUIStyle(),
                GUILayout.MinHeight(80f),
                GUILayout.MaxHeight(200f),
                GUILayout.Width(windowWidth));

            GUILayout.BeginArea(timelineArea);
            GUILayout.Button("Test");
            //GUI.Button(new Rect(10, 10, 50, 20), "Test");
            GUILayout.EndArea();
#

This is the entire code.

#

Above it, is just some buttons and sliders

#

And I already said what's happening, nothing gets rendered inside the group or area

waxen sandal
#

Does it get rendered at all?

solid thicket
#

No

#

I mean, I don't know

#

maybe offscreen

#

Its not visible

#

the odd thing is that the rect is fine

#

maybe its something to do with EventType.Layout or something?

waxen sandal
#

Looks like it's a weird interaction with GetRect

solid thicket
#

I use it before and its working fine that's the thing

#

Its the first time I use it to create an area

waxen sandal
#

Not quite sure what the issue is at the moment, I'd have to dig deeper which I don't have time for at the moment

#

@onyx harness might know

onyx harness
solid thicket
#

Its working fine

#

I tried it

#

That's what makes me thing its something to do with the EventType

onyx harness
#

What I like to do when debugging is to call EditorGUI.DrawRect(rect, Color.blue)

#

It's Editor stuff right? Not in-game?

solid thicket
#

Yep

#

The rect is fine as I stated before

#

Layout -- (x:0.00, y:0.00, width:1.00, height:1.00)
repaint -- (x:0.00, y:301.00, width:1188.00, height:200.00)

onyx harness
#

Maybe it is GUILayoutUtility

solid thicket
#

That's what I get when I view the rect

#

When I try to separate the rect update, for say, EventType.Repaint (Because that's where the rect is valid), I get errors about doing that

#

When I try to switch to EventType.Layout I get the same thing

#

I mean doing this:

if(Event.current.type == EventType.Repaint)
  UpdateRect();
onyx harness
solid thicket
#

Me, its just position.width

onyx harness
#

If you say the example works fine alone, but your code is impacting the current result, something in your current code is annoying the layout

#

Try to narrow it down

#

Remove some part one by one, until BeginArea starts drawing again

#

Or add them one by one

#

up to you

waxen sandal
#

Removing the getlastrect and replacing it with a constant value works fine

#

So it's some interaction with that

onyx harness
#

GetLastRect?

waxen sandal
#

Getrect I meam

#

Mean

solid thicket
#
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;


public class TestWindow : EditorWindow
{
    [MenuItem("Tools/Test Window")]
    public static void Init()
    {
        TestWindow window = GetWindow<TestWindow>();
        window.Show();
    }

    private void OnGUI()
    {
        Rect rect = GUILayoutUtility.GetRect(
                GUIContent.none,
                "button",
                GUILayout.Height(200f));

        // Maybe its something to do with the EventType?
        Debug.Log($"{Event.current.type} -- {rect}");

        GUILayout.BeginArea(rect);
        // Draw to the entire area
        GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture);
        GUILayout.EndArea();
    }
}
#

Here is a simple example

#

This example wont draw anything, but it should

#

It should draw a white rectangle (100% width of the window) with height 200

#

NOW, comment the BeginArea and EndArea out, the rectangle appears!

onyx harness
#

nope

#

It depends what returns GetRect

solid thicket
#

That's why there is GUILayout.Height(200f) and "button"

#

button makes it go full width in that case, and height speaks for itself

#

and you can try it yourself and see that's the case

onyx harness
#

It's not about the content and styling

#

It's about who get drawn first between BeginArea & DrawTexture

#

BeginArea opens a clip if i'm not mistaken

#

If you move GUI.DrawTexture above BeginArea, what do you see?

solid thicket
#

yes

#

Only stuff inside the area gets hidden

#

Im not following you about the draw order

#

What do you mean?

onyx harness
#

if BeginArea draws a non-opaque background, it might probably hide the white texture

solid thicket
#

Why would BeginArea draw something

onyx harness
#

Hehehe wonders of Unity Editor

solid thicket
#

Well it calls GUI.BeginGroup, and I don't think it draws something

#

how did you come to that conclusion?

onyx harness
#

Almost any GUI has a Style applying, and it draws stuff

#

Because there are a lot of surprises in GUI

solid thicket
#

So I need to try another style?

onyx harness
#

In your code just above, if you draw GUILayout.Button("Test"), it works, right?

#

(Between the Area)

solid thicket
#

no

#

BUT

#

You were onto something with the GUIStyle

onyx harness
#

Then, now if you replace GetRect with a manually assign Rect, it works

#

Like Navi stated

solid thicket
#

I replaced "button" with new GUIStyle and I see a small pixel below the tab

solid thicket
onyx harness
#

yep

solid thicket
#

Well, that's kind of a hacky way

#

I need to find a proper Rect

#

like GetLastRect

onyx harness
#

Yeah yeah we know, it was just for the test

solid thicket
#

well hard-coded does work

onyx harness
#

We need to find the culprit first

#

What if you remove completely the style?

solid thicket
#

Well I assume you mean with the GetRect?

onyx harness
#

yes (sorry)

solid thicket
#

you mean like new GUIStlye()?

#

a default style?

#

Oh, you mean use it with a hardcoded rect?

onyx harness
#

Let me find an overload that does not use a style

solid thicket
#

There are a few

#

I just need to specify stuff like width and height

onyx harness
#

Use the first one

#

GetRect(position.width, 200F)

#

Does it give something interesting?

solid thicket
#

Surprisingly, no :\

onyx harness
#

Is the rect somehow correct?

solid thicket
#
            
            Rect rect = GUILayoutUtility.GetRect(position.width, 200f);

            GUILayout.BeginArea(rect);
            GUILayout.Button("Test");
            GUILayout.EndArea();
onyx harness
#

(I'm not even surprised myself)

solid thicket
#

Well I am, I thought maybe that way its like using hard-coded values

onyx harness
#

what about GetRect(position.width, position.width, 200F, 200F)

#

It's not hardcoded, since height = 200F is also used like this in your first code

solid thicket
#

I know its not hard coded

#

I meant maybe it will behave the same way

onyx harness
#

Try GetRect(0F, 0F, GUILayout.Width(position.width), GUILayout.Height(200F))

solid thicket
#

Same result

onyx harness
#

Well shit, GetRect is definitely colliding with BeginArea

solid thicket
#

Lol

#

That's odd because I thought people use it a lot

onyx harness
#

But I feel it is somewhat expected

solid thicket
#

it would have come up but I didn't find anything about it

#

Yeah, I think so too

onyx harness
#

GetRect will reserve a space

#

BeginArea is suppose to start a new layout in a given rect

solid thicket
#

Thats a second button under the EndArea

onyx harness
#

which is fine

solid thicket
#

Yep

#

That's where it should be

#

Unlike someone else...

onyx harness
#

What you can use to trick the layout

#

Use GUI.Space

#

GetLastRect

#

Set the correct width and move on

solid thicket
#

Yeah that's my fallback

#

I'll dig some more inside Shader Forge and see how she uses it

#

I saw she uses only GUI.BeginGroup

#

But I don't know

onyx harness
#

Which is for purely clipping

#

GUI is much more cumbersome but much more reliable than its counterpart GUILayout

#

I use GUILayout for quick prototyping, GUI for production

solid thicket
#

Yeah I started using GUI, getting the hang of it on the way

#

I want to create a timeline now using it

onyx harness
#

You'll have much less headache using GUI directly

#

Things like timeline needs precision

#

Good luck

solid thicket
#

Thanks 🙂

#

Thanks for the help also! really appreciated

onyx harness
#

@waxen sandal TL;DR GetRect weirdly messes with BeginArea

deep wyvern
#

for some fields you can click the circle with the dot on the right side of the field

royal lantern
#

im trying to create some good looking lists with a custom inspector (mainly just to hide the size field and change the name from Element 0 to something like hips)
this is what my code looks like ```cs
using UnityEditor;

[CustomEditor(typeof(PlayerController))]
public class PlayerControllerInspector : Editor
{
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorList.Show (serializedObject.FindProperty("playerBodyParts"));
serializedObject.ApplyModifiedProperties();
}
public static void Show (SerializedProperty list) {
EditorGUILayout.PropertyField(list);

    for (int i = 0; i < list.arraySize; i++)
         EditorGUILayout.PropertyField (list.GetArrayElementAtIndex(i));
}

}

#

jump to "Creating an Editor List"

#

oh also this should be hiding the Size field but for some reason it wont do that either

onyx harness
#

PropertyField(list, false)? @royal lantern

royal lantern
#

wait did i miss that

onyx harness
#

nope

#

But I suggest to avoid drawing children

royal lantern
#

hmm weird they didnt do that 🤔
thanks ill try that

onyx harness
#

In the tutorial you mean?

royal lantern
#

woah it worked

#

yeah

#

thanks alot ive been stuck for the past hour lol

onyx harness
#

The tutorial was made by CatLikeCoding, which provides good basics, but is also very outdated.

royal lantern
#

i mean it did show about the "include children" field above but they didnt do it in the code for this part for some reason
probably just forgot

oak umbra
#

im looking for the functionality from the Trim button in the built-in sprite editor through code

#

since it, for no reason at all, doesn't support multi-select trim for sprite slices in the sheet.

whole steppe
#

Good morning all, not sure if this question fits here but i will try. Is it possible to have a custom editor for two different classes that have the same base class? Generable (Base Class), ClassA : Generable, ClassB : Generable and then the editor appears in the inspector for both ClassA and ClassB?

waxen sandal
#

Is your editor for GEnerable?

#

If so you can just enable the bool editorForChildClasses on the attribute

whole steppe
#

[CustomEditor (typeof (Generable), true)]

#

Thanks @waxen sandal!

merry pecan
#

I am trying to create an extension (CustomEditor) for the UI Image component, but it doesn't seem to affect it in any way?

#
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;

[CustomEditor(typeof(Image))]
public class UnsetNativeSize : Editor
{
    public override void OnInspectorGUI()
    {
        Image targetComponent = (Image)target;
        DrawDefaultInspector();
        if (GUILayout.Button("Unset Native Size")) {
            Debug.Log("Button Clicked...");
        }
    }
}
fossil gyro
#

i'm trying to use PrefabUtility.GetPropertyModifications to see what my code prior just changed, and somehow the properties don't include all my own variables

#

is that by design?

#

my main problem is that PrefabUtility.ApplyObjectOverride does not work for me.

#

only PrefabUtility.ApplyPrefabInstance applies everything needed, but also too much, like the transform

#

okay, apparently i need to mark the scene dirty before ApplyObjectOverride does anything :|

waxen sandal
#

@merry pecan IIRC it uses the first editor it finds, but I wouldn't recommend doing that either way since it'll probably not show the correct default drawer

waxen sandal
#

Not really

#

I'd probably just make static methods and menu items that trigger when you hit a shortcut

#

Or add it ot the context menu

royal lantern
#

so ive been trying to make a custom inspector for my PlayerController script and for some reason i cant drag in any game object in any of the fields. What happens is, when I drag in a game object and release the mouse button, it still says None (Game Object) . Here's all the code im using for the custom inspector: https://paste.myst.rs/iyl0b4sa
And heres a screenshot of what it looks like right now

#

please ping me in case anyone has an answer or question 😄
solved, apparently I had some weird error in console that i needed to fix

thin fossil
#

Is it possible to create a scene asset without opening it? This is my current workaround but I would rather just create the file:

var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
EditorSceneManager.SaveScene(scene, "scene.unity");
EditorSceneManager.CloseScene(scene, true);
waxen sandal
#

There's SceneAsset that might work

thin fossil
#

Problem is it is just an empty object with a private constructor. So I cannot create it with new

waxen sandal
#

ScriptableObject.CreateInstance or is it not a SO?

thin fossil
#

no its just an Object 😕

public class SceneAsset : Object
  {
    private SceneAsset()
    {
    }
  }
waxen sandal
#

Try to check what the Assets > Create > Scnee does

thin fossil
#

any clues how to find that?

waxen sandal
#

Check the reference source

thin fossil
#

Oh totally forgot about that 😅

fleet current
#

hy all, very specific question incomming :
in unity, you can create your own packages. you can 'embed' them so that they show as 'in development' in the package manager (not many people know that, thought i'd share 🙂 )
in case there's someone here that has done this : do you know of a way to identify which packages are embeded (or how to differentiate them from regular packages) I'm trying to achieve to know wether a specific instance of a scriptable object is 'read only' because it's from a protected package, or not (only editor, not runtime)

#

nvm, found it. posting the answer in case someone ever needs to know: PackageInfo.cs contains a method FindForAssetPath (to find package of an asset), and that info also contains 'package source' which would be embedded (or not)

waxen sandal
#

Path.GetFullPath also works

#

Don't ask me how

thin fossil
#

@waxen sandal cannot find anything on creating scenes in the source. No clue how unity does it

#

They rarely use CreateAssetMenu, never use CreateAsset with scenes and never use SceneAsset in any instantiation context 🤔

royal lantern
#

im not sure how i can make this "Feet IK" text be bold... this is my code ```cs
public class PlayerControllerInspector : Editor
{
private bool collapseFootIK;

public override void OnInspectorGUI()
{
    serializedObject.Update();
    collapseFootIK =
        EditorGUILayout.Foldout(collapseFootIK, "Feet IK");
    if(collapseFootIK)
    {
        EditorGUI.indentLevel += 1;
        EditorGUILayout.PropertyField(serializedObject.FindProperty("rightFootTarget"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("rightFootPole"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("leftFootTarget"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("leftFootPole"));
        EditorGUI.indentLevel -= 1;
    }
    serializedObject.ApplyModifiedProperties();
}

}

#

ive tried just adding EditorStyles.boldLabel after the "Feet IK" parameter but that makes Feet IK not be a foldout but just a normal bold label

thin fossil
#

@waxen sandal no luck either...

royal lantern
cyan sphinx
#

General question. I did some custom editor window a few years back. Checking into things now, it seems that UIElements is the new way to go

#

Has it completely replaced the old system now?

#

Not looking forward to porting my custom node editor

waxen sandal
#

It hasn't

cyan sphinx
#

Okie

empty island
#

For Unity, in the editor I can set the public Transform teleportTo, where I can teleport my player to a specific teleportTo.position.

Is there a better way of doing this? I.e. I want to choose a location in my scene, but it seems I have to create a gameObject for every coordinate. I could do Vector3, but I won't be able to "preview" the location as easily or move it in Scene View

patent pebble
#

can't find much info on what a "Preview Scene" is and what practical applications it has

#

it doesn't seem to have any documentation other than a couple of vague docs on the EditorSceneManager class

#

anybody has some info on this? 🤔

bold skiff
patent pebble
#

@bold skiff I think you can do AddState with a Vector3 aswell as the name

#

I don't know if you can move them after being created though, it's been a while so I don't really remember

#

I think you can manipulate the AnimatorStateMachine.states and change their positions? not sure

bold skiff
#

Alrighty, looks like I can use vector 3, now to find out where to put everything

bold skiff
#

Ok, here is one more question. In my code I have it setting the weight for layer 1 to be 1, but its not doing that. Any thoughts? (Code above post)

Line 163,4,5

gloomy chasm
#

@patent pebble Regarding Preview scenes. They are used for the prefab editing. They seem to be pretty new too, last time I looked at mimicking the prefab functionality it was going to be a pain. So thanks for bringing it up!

patent pebble
#

@gloomy chasm oh so I guess it's similar or related to the Prefab Stages experimental API

gloomy chasm
patent pebble
#

yeah I'll dig around their github source code to see how it's used

#

just wanted to see if there was some neatly explained info online

#

I guess they didn't bother expanding the docs for this since it's still very new or experimental

gloomy chasm
#

Guess so, some things are just like that with little to no docs.

patent pebble
#

yeah they don't seem to bother much with some Editor extension APIs, sadly

onyx harness
urban hazel
#

Hello

#

I'm trying to write a propertydrawer which handles drawing references to scriptable object assets. I want to display fields from the referenced object inline, and have them update in the inspector as changes happen.

#

So far, the changes in the scriptable object don't cause an update in the inspector the drawer is being rendered in.

#

Which makes sense since the object which is changing is a separate object form the behaviour the inspector is rendering.

#

Just having a hard time figuring out how to accomplish this.

gloomy chasm
#

@urban hazel Are you using SerializedProperties?

urban hazel
#

Yep

#

Thus far to display the fields of the scriptable object I have reference to, I've had to create a scriptable object instance for that object.

#

It works to display the values of the object pointed to, but as they change, they don't update in the inspector.

gloomy chasm
#

@urban hazel No, to get the fields, you create a SerializedObject from the ScriptableObject

urban hazel
#

Well, the field in particular which is the type of the ScriptableObject, I do the following:

var variableSO = new SerializedObject(variableField.objectReferenceValue);
variableSO.Update();
SerializedProperty varValueProp = variableSO.FindProperty("Value");
erializedProperty varRuntimeProp = variableSO.FindProperty("RuntimeValue");```
#

Not sure if that's what you're refering to.

#

so variableField is the serializedProperty which holds a reference to a ScriptableObject asset type I have in my project.

#

I wanted to display data from within that object in this inspector

#

Is this what you were asking?

gloomy chasm
#

Yeah, that's it.

#

So, what part isn't updating?

urban hazel
#

When I display varValueProp and vaRuntimeProp, if I change their values from code the updates don't hit the inspector

#

Not unless I hover the inspector while doing it.

#

The inspected object doesn't get told to update since this SO reference it points to is receiving the changes,.

#

And I mean, that makes sense

#

I just want to work around it.

#

Cleanly if possible.

visual stag
#

editors don't repaint unless events are sent to them or they're part of editors that override RequiresConstantRepaint

stuck olive
#

kia ora all

#

im wondering some'at

#

and just as soon as i'd thought to ask.... i forgot what it was i wanted to ask ><

stuck olive
#

anyway... different question... is there an !important in USS? I'm trying it with zero luck...

whole steppe
#

i am struggeling on why the obj is null when i enter run mode:

           t.go = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Go", "Event GameObject"), t.go, typeof(GameObject), true);
             if (t.go != null)
              {
                   Debug.Log("assign obj here");
                   t.obj = t.go.GetComponent<CustomEvents>();
                   Debug.Log(t.obj.ToString());
               }

---------------------------------
    public GameObject go;
    public object obj;
#

while the gameobject "go" is ok

#

talking of the obj field

gloomy chasm
whole steppe
#

on the go field?

gloomy chasm
whole steppe
#

not quiet sure how to do this

gloomy chasm
#

@whole steppe Like so. This is assuming that go is just a public field. If it is a property, then you want the backing field with the [SerializeField] attribute.

SerializedProperty goProperty = serializedObject.FindChildProperty("go");

EditorGUILayout.PropertyField(goProperty, new GUIContent("Go", "Event GameObject"));
if (goProperty.objectReferenceValue != null)
{
  serializedObject.FindChildProperty("obj").objectReferenceValue = t.go.GetComponent<CustomEvents>();
}
// This is important, this actually applies the changes, without this the new values will not be saved.
serializedObject.ApplyModifiedProperties();
whole steppe
#

okay let me see

#

hmm not able to Drag Drog the GameObject from the Scene now 🙂

#

it is a Scriptable Object and i using some System.Reflection

gloomy chasm
fickle copper
#

Greetings; I am currently making a Property Attribute for a project of mine where said Property Attribute exposes the information contained in a Scriptable Object directly to a component that contains said Scriptable Object.

#

So far, i found out that using Editor.Create(target) works fine with the exception of the fact that i am using editor.OnInspectorGUI() which draws everything at the bottom of the inspector.

#

Is there any way of having the same functionality as the OnInspectorGUI() but also control where said element is being drawn?

patent pebble
#

@fickle copper you probably have to either create Custom Editors for editor you are creating with CreateEditor or draw everything manually

#

It's been a while since I did stuff with nested editors but I remember it being relatively simple

fickle copper
#

especially since i dont know what properties the object contains

#

I straight up lack that information as its a Property Attribute that works on any scriptable object.

#

I tried GetIterator() but im getting some weird behaivour and/or errors out of it.

#

I can send you a screenshot of how the current editor looks with CreateEditor if you want

patent pebble
#

@fickle copper I mean if you want to draw it in the inspector view you can just use a custom editor for the type that you want to draw

#

I expect that you are just getting the nested editor at the bottom of your inspector, but yeah send the screenshot anyways

fickle copper
patent pebble
#

how do you want it to look?

fickle copper
#

I want the nexted editor to draw right below its data holder

#

So the Test Scriptable Object should have its editor right below it.

#

And the same for the Instance Event one

#

This way, i can use this Attribute on lists

#

As it is rn, if i were to use it on a list, it would draw every editor at the bottom

#

And that gets confusing if you have multiple scriptable objects of the same type.