#↕️┃editor-extensions

1 messages · Page 49 of 1

severe python
#

tbh I have no idea how Addressables works, I haven't investigated it yet

#

if you want a system to automatically load UXML for a window absed upon a naming shcme the solution is simple

#

Make a base class with the necessary data you need to automatically load stuff based upon whatever metric you want

#
using System;
using UnityEngine;
using UnityEngine.UIElements;

public abstract class AutoTemplate : VisualElement
{
    public AutoTemplate()
    {
        RegisterCallback<AttachToPanelEvent>(LoadTemplate);
    }

    private void LoadTemplate(AttachToPanelEvent evt)
    {
        Resources.Load<VisualTreeAsset>($"{GetType().Name}.uxml").CloneTree(this);
    }
}
#

just create a resources folder in an Editor path somewhere to store all your templates

#

this code may not specifically work

dim walrus
#

I suppose where the name is you also need the path

severe python
#

generally, hence why I mention using Resources

dim walrus
#

I like the idea of the base class, gonna look at addressable to avoid path or a common folder

severe python
#

heh, made this as an example for you, and I'm probably going to end up using it tonight

#

please let me know what you figure out with Addressables, if there is a way to make the pathing situation better, than that's awesome

severe python
#

If addressables can be used in the editor, then it seems like it will provide a huge amount of capability for this goal

waxen sandal
#

IIRC it will

severe python
#

the WYSIWYG UI editor is coming out with the next major version right?

dim walrus
#

You can always use the UI Builder

severe python
#

the what? Do you mean the UI Elements Builder they just announced?

#

oh well heck, I didn't realize It was available

#

Can't seem to load a USS file for a given control however

#

Nevermind, you can if you follow their naming scheme

dim walrus
#

With that and an auto editor load, making editors could be really easy

#

Although i'm not a big fan of linking logic with buttons using their names

severe python
#

?

#

There is a distinct lack of Code behind support or connecting the UI to logic

#

right now that connection appears to be 100% driven by code

dim walrus
#

I'd prefer having a public UIElementReference or something like that

#

So you can bind whatever you need to it

#

Rather than having to use a Query to find anything

#

That's what at least i've seen

#

No idea if there is other way of doing it

muted pelican
#

Anyone figured out how to make TextMeshPro.Buttons react to anything other than the main button on a controller or like "right click"?

#

Do I have to build my own script completely or is it possible to use the built in features to add another interaction button?

severe python
#

Welp, I made a generator for VisualElements for all the Unity.Mathematics types...

#

lets see if they actually work

severe python
#

Okay, so this works pretty well, but there are some problems

#

First, I can't see how to instantiate a Template element and an Instance element from code, I'd guess its not possible and they expect you to use VisualTreeAssets, this makes things a ltitle wierd

#

the UIBuilder helps with this problem a bit, since all you really have to do is create a custom inspector class which loads a visual tree for the inspected type, and as long as the XML there is implemented correctly all the binding path stuff works

#

However, I don't see how you could render lists using this setup

#

Okay, so this works pretty well, it requires some annoying boiler plate, maybe there is a way around that.
All I have to do to setup a custom UXML driven inspect for a type, for example:

public class TestType : MonoBehaviour { public float3 Test3; public float3x3 Test3x3; }

Is instantiate this class

[CustomEditor(typeof(TestType))]
public class TestTypeEditor : AutoTemplate<TestType> { }

Create this UXML

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
    <ui:Template name="Double3" src="Double/Double3.uxml" />
    <ui:Template name="Double3x3" src="Double/Double3x3.uxml" />
    <ui:VisualElement>
        <Style src="TestType.uss" />
        <ui:Instance template="Double3" binding-path="Test3" />
        <ui:Instance template="Double3x3"  binding-path="Test3x3" />
    </ui:VisualElement>
</ui:UXML>

This is enabled by this class, plus generated fields/templates for the Unity.Mathematics types:

public abstract class AutoTemplate<T> : Editor
{
    public override VisualElement CreateInspectorGUI() => Resources.Load<VisualTreeAsset>($"{typeof(T).Name}").Instantiate();
}
#

If anyone is interest in the generator code I'll toss it up on Github

#

The serialization bindings just work in this case

#

Using the UI Builder is really helpful for creating the inspector element UXML, because it handles the pathing to the template files

#

the generator deals with setting up the binding paths as well

onyx harness
#

We should really consider again creating a channel specifically for UI Element X)

hearty cypress
#

How would I access the colorpicker swatches and add colors to it?

onyx harness
#

@hearty cypress I'm not sure, I don't have time to investigate more, but look at the internal class PresetLibraryEditor<ColorPresetLibrary>

hearty cypress
#

@onyx harness ok thanks for pointing me in the direction.

onyx harness
#

It seems you can find the presets in a file. I don't know where

hearty cypress
#

which is great because I wanted to do a custom color palette

brisk isle
#

is there a way to run code in the editor whenever I place a specific prefab in my scene?

onyx harness
#

@brisk isle EditorApplication.hierarchyWindowChanged?

brisk isle
#

Method group is Obsolete

#

that can't be good

onyx harness
#

Wut?

#

Oh

#

What Unity are you on?

hearty cypress
#

@onyx harness is that a poring 😮

onyx harness
#

I am working on Unity 2017.4...

brisk isle
#

2019.2

onyx harness
#

@hearty cypress Hell yeah X)

brisk isle
#

nice

#

i played RO for way too many years

hearty cypress
#

sammmee hahaaa!

onyx harness
#

EditorApplication.hierarchyChanged?

brisk isle
#

yeah that seems like one that could work thanks

#

just to make sure I'm not on an XY problem

#

what I'm trying to do is, whenever I place an object on the scene in the editor, i want to check if theres another object, exactly Vector3(1,0,0) away from it

onyx harness
#

It's a way to do it I guess

brisk isle
#

@onyx harness thanks

whole steppe
#

Am having problem

#

With buttoms

#

If i press one of them it will only press the first buttom i created

#

Any thoughts?

onyx harness
#

Any code?

whole steppe
#

@onyx harness i am only using Canves

#

I have an Invetor y

#

Inventory when i press lets say The armor place it will press On the helmet place

#

Same as everything else it will always press on helmet

#

i think its a layers thing?

#

Oh fixed it

#

its all good ❤

hearty cypress
#

how do I set a white border around an ongui button?

onyx harness
#

@whole steppe you are on the wrong channel.

#

@hearty cypress you get the position of your button and you draw 4 lines around it.

hearty cypress
#

@onyx harness could I use DrawTexture for this? Im thinking a black 2x2 pixel that is expanded via ScaleMode.StretchToFill. Or is there a Draw Line method I didnt see?

#

oh nevermind i found it DrawLine.DrawLine(pointA, pointB, color, width);

onyx harness
#

I'm not on my computer, but yeah there is utilities for that

#

They are not optimised, but they do the job

hearty cypress
#

maybe a 2x2 white pixel texture stretch and put behind a button is more efficient than drawing 4 lines

hearty cypress
#

Not sure why but the color doesnt change when I click a button:

Texture2D selectedColor = new Texture2D(2, 2);
changeSelectedColor(selectedColor, Color.white);    // set to default color

if (GUI.Button(redButton, ""))
 {
    changeSelectedColor(selectedColor, Color.red);
}

if (GUI.Button(blueButton, ""))
 {
    changeSelectedColor(selectedColor, Color.blue);
}

my helper function looks like this:

private void changeSelectedColor(Texture2D selected, Color c)
{
    for (int y = 0; y < selected.height; y++)
    {
                for (int x = 0; x < selected.width; x++)
        {
            selected.SetPixel(x, y, c);
        }
    }
     selected.Apply();
}
onyx harness
#

Lol

#

You are creating a new texture each frame, that's why

hearty cypress
#

this is OnInspectorGUI though.

onyx harness
#

What do I need to conclude with it?

hearty cypress
#

Doesnt OnInspectorGUI draws on event changes for inspector like EndChangeCheck(). So i dont see how it is every frame.

onyx harness
#

Everytime you draw your buttons, just before you created a new texture white

#

When you click you modify the texture

#

But the next frame will have again a new texture created

#

It's always white, that's what I trying to say

hearty cypress
#

yeah i guess im not understanding the order of render here. id assume if clicked once itll re-render just once.

onyx harness
#

Imgui is a bit weird to grasp

#

You need to store that texture once

hearty cypress
#

like cache or store as a serializable or something?

onyx harness
#

Just a field

#

If null, you create it

#

Or in a OnEnable

#

Whatever suits you, as long as it is done once

hearty cypress
#

Okay this is clear for me to resolve it, thanks.

#

got it. thanks @onyx harness. Heres my ghetto palette selector.

onyx harness
#

Haha gj

severe python
#

@onyx harness I apologize if my large comments were annoying or something

severe python
#

I did go an put a suggestion into the server feedback channel about creating a separate channel for ui elements, especially considering it will be getting runtime compatibility in the next year

onyx harness
#

@severe python oh no, don't worry, but it was a suggestion made a long time ago

severe python
#

with unite 2020 copenhagen showing that UIElements is going to be an important technology going forward, I think its more necessary than ever

#

having a good place on here where people can work out some issues with the technology so it can be improved I think would be helpful for both users and unity tech.

#

On that note, maybe you (or anyone else here) have some thoughts on an issue I'm running into with this stuff I'm setting up

#

I'm trying to implement a few basic controls that would really ease the usage of UXML by enabling binding-paths to be used more easily, thats what those big posts up above were about

#

now I'm trying to setup a ListView, I originally started by trying to implement listview, which successfully bound to the binding-path, but its implementation doesn't allow for elements of multiple types, so I'm trying to build a new list view from scratch

#

but even upon reviewing the binding system in Unity CS, I can't really tell how you'd utilize bindings in a custom VisualElement

#

it seems like maybe you can't

onyx harness
#

I am very far from being an expert on UI Element unfortunately

#

But I hope to become one, one day! 😁

#

I just know the theory, never practice yet

severe python
#

I may know more than most and thats kinda frustrating

#

I've combed over a fairly large portion of the Unity CS reference with regards to UIElements, multiple times since it was first introduced

onyx harness
#

So... Is it good?

severe python
#

If you look simply at the UI creation aspect, styling and structure are super easy

#

and very powerful, makes it really easy to make something well layed out and nice looking

#

comperable to HTML

#

In simpler situations for Serialized objects, where you don't have lots of nesting or arrays/lists of base types which contain multiple sub-types, the bindsing is very easy to setup and works really well

#

however, when you're trying to go just a little bit more advanced things get hairy

#

because they hide a bunch of the systems that, atleast at a glance, you need in order to work with bindings

severe python
#

which honestly, is probably just a lack of understanding on my part, but it shows a weakness in either the design or the documentation

crystal timber
#

😂

severe python
#

?

crystal timber
#

I'm worried if I asked too many questions about UIElements here... maybe it's really nice if there's a separate channel

onyx harness
#

Just shoot, there is almost no contraint about asking questions

severe python
#

how would you figure out if a binding is taking place...

visual stag
#

The fact that it says inspectors call Bind itself is confusing

#

especially when you're not working with the scriptable object the inspector is operating on

#

I totally agree with the:

because they hide a bunch of the systems that, atleast at a glance, you need in order to work with bindings
which honestly, is probably just a lack of understanding on my part, but it shows a weakness in either the design or the documentation

#

which is completely my experience with it

severe python
#

oh man, the more i look into their binding system, the more disappointed I am...

#

I'm just going to pretend it has to do with the fact that its a game engine and all this spaghetti is necessary for performance...

#

yeah

#

it really makes me think I just should just do my own thing

severe python
#

buahahahhaa, I got this auto-binding auto templating inspector crap working I think

#

ArchetypeManager contains an array of EntityModel, which I showed up above a bit. The EntityModel contains IDataComponents which are populated with different IDataComponents, and then Ihave a class, ItemsControl which derives from Bindableelemetn which looks up a UXML file based upon the type name found in the array element

#

so now I can easily render complex arrays, and fill in missing elements by simply creating a UXML file

low crown
#

Would it be possible to create a slider where one end would gradually change to warmer colors and the other would change to colder colors on a game object? (Oddly specific yes but if anyone could lead me to a tutorial that’d be great)

onyx harness
#

@low crown Slider is just a value between 0 & 1

#

From that value, you do whatever you want

severe python
#

I gotta say, once you get something setup to do good automatic loading of UXML its pretty great

#

I've been just building views for the past couple hours

#

and haven't needed to touch code

#

Honestly, this is how it should work out of the box

onyx harness
#

That's why I am so eager to switch to UI Element

#

No more compilation...

severe python
#

exactly

onyx harness
#

That's a HUGE time saver

severe python
#

rapid iteration is huge for UI/UX

#

its the difference between a good ui and a bad one honestly

#

Once I got that list control working, I've been able to just build UXML templates for various IComponentData implementations

#

and as you can see, they are quite simple

sleek edge
#

Hey, I want to do something that's probably a bit too ambitious
In order to add effects (aka functions) to a scriptable objects, I decided to do this: create a bunch of templates for functions with variables (deal damage, move something somewhere, heal, play, return to hand, etc...) that I could then drag n drop inside of a List or array and that would display input sapce where I would be able to enter the variables, like with a MonoBehaviour script component.

#

TL; DR If I could put a MonoBehaviour-extended class inside of a List in a way that allowed me to modify the variables just like in a component, that would solve my problem
If you know or have ideas on how to make this possible, please ping me. I'm quite new to modifying the Editor

onyx harness
#

I'm so not used to the new UI. Still working with U2017, I cant wait to switch ! 😄

#

Hum... what is UI Builder? native editor?

severe python
#

its an editor for building UIElements

#

its good with a little glue like I've built, but its still buggy

#

like, buggy to the point where, its important that I don't create UXML files before I open the UI Builder, the file needs to not exist and I have to start a new one INSIDE the UIBuilder in order for anything to save

#

and for data to actually flow into the UXML, I hae to add an element, then cut it, then paste it, and then the template will correctly start updating

low crown
#
        {
            foreach (GameObject obj in Selection.gameObjects)
            {
               
                obj.GetComponent<SpriteRenderer>();
                scale = EditorGUILayout.Slider(scale, 0, 100);
            }
           
        }``` I'm trying to make my scale affect my gameobjects color, any tips
#

like one would be on the cool spectrum and the other on the warm

#

I think I have to make a color array

sleek edge
#

I think the error comes from the fact you aren't actually storing the sprite renderer anywhere

#

You are calling it, but it's not going anywhere, no variable

#

Try adding SpriteRenderer renderer = obj.GetComponent<SpriteRenderer>(); instead

#

Then you'll be able to modify the different values of it

#

Don't know if that's the issue you are encountering but that's the first thing I noticed '^^

feral karma
#

@severe python would be great if you can report bugs about those. I had similar experiences but sounds like you might already have clear paths for reproduction

crystal timber
#

Is there a way to force a newly created VisualElement re-layout or get informed after VisualElement resized? I want to do some positioning according to Node sizes in a GraphView...

visual stag
#

a GeometryChangedEvent could be one way of doing it

crystal timber
#

thanks!

severe python
#

is there a forum for the UI Builder somewhere?

#

I need to solve one more problem, which is how to deal with adding to and removing from arrays and allowing different controls to do that

severe python
#

Hmm, how would you find the current editor object from within a visual element that

severe python
#

Yes, I finally figured out the design for this templating setup, and I couldn't be happier

severe python
#

I swear I'm the only person who gets excited about good ui frameworks

feral karma
#

you're not! following closely here ;)
Have you figured out a good way to draw a auto-resizing table? Unity themselves create it using vertical columns but it's super hacky to get the rows the same height then

#

@severe python

severe python
#

I have done nothing with tables

#

what do you mean auto-resizing?

#

you talking like an excel grid?

severe python
#

unfortunately I've seem to have come upon a bug in unity thats causing it to crash

severe python
#

looks like an issue with looking at an array element which doesn't have a value assigned to it maybe

severe python
#

Welp, I'm quite happy with where I've gotten to

#

the performance of generating the interface is a bit slow, which I'll have to investigate, but the interaction performance is great

#

There are some places where I'm collecting and iterating over every type in the current app domain, so that could be part of it

severe python
#

hmmm, how do you increase the size of an array of structs with SerializedProperty without duplicating the values from the previous element?

#

I don't see a way I can' assign a struct to a SerializedProperty

severe python
#

Popup stuff is a really weak thing in this system

#

unless you feel like adding a style to the root of your inspector...

severe python
#

popups are murder 😦

severe python
#

oh man, so it turns out an auto-suggest box of this nature is not possible

severe python
#

there doesn't appear to be a way to position a popup window in uielements without it being a imgui popup

candid briar
#

@gloomy chasm Don't know if you were still wondering about making your UI scale with screen size but HandleUtility.GetHandleSize() might work.

brittle cosmos
#

Is it possible to allow dropping one or more items from the project or hierarchy into a ReorderableList like you can with the default array inspector?

waxen sandal
#

Sure you gotta implement drag/drop yourself

candid briar
#

Which you can do by making using of Unity's event system 🙂

brittle cosmos
#

Oh ok thanks

brittle cosmos
#

Cool that was pretty easy

patent seal
#

is there something that can set textures to materials programmatically in editor? I have this mesh with like 100 child objects that I need to set textures for

gloomy chasm
#

@candid briar Thanks, I ended up realizing I was saying the opposite of what I meant. I wanted the handle to stay the same size. So when scrolling out it would be smaller, like gizmos. But don't think it is possible.

#

@patent seal yeah, though if they all just need the same texture you can just select them all and drag the same texture on to them.

candid briar
#

For staying the same size:
Ye you can use sceneView.cameraDistance. Unless you mean something else?

patent seal
#

@gloomy chasm they all need a different texture

#

the tex names are like 001, 002, 003

onyx harness
#

@patent seal yes you can

severe python
#

@patent seal the Mesh component has a submesh value, each face that needs a specific material needs to be a different submesh, once you have that then you can assign a number of materials to the MeshRenderer's Material array

#

the index of the material array corresponds to the submesh

patent seal
#

yeah my question is how do I do that with a script

#

instead of manually dragging

#

I load the texture I want via AssetDatabase then assign it to my meshRenderer, how do I save it

severe python
#

Just to check, are you just working with GameObjects and MonoBehaviours?

patent seal
#

yes. I found out I can create a menu button that creates materials via AssetDatabase.

I make a material per texture that I want.
Now I have a game object in my scene with 100 children. I need to assign each children the corresponding material taht I have in my asset folder

severe python
#

wiat, are the 100 children, all game objects? or are you talking about a mesh with abuncha different sub meshes?

patent seal
#

game objects

#

they're all game objects, dont ask me why lol

severe python
#

so ignore what I said above, its not correct for your scenario

#

okay, so you'll need to iterate over each child game object, which you can do via Transform, and then get the MeshRenderer on each child, then assign the Material to its material property

patent seal
#

yeah, I wanna do that in the editor too

#

instead of at runtime

severe python
#

if you want to save it in the editor, you'll have to write that into an editor script, but the same thing applies

#

if you want all the frills, then you'll do it via serialized properties

#

So iterate over the gameobjects children, get the MeshRenderer, then do a new SerializedObject(MeshRendererInstance), then

#

serializedObject.FindProperty("material")

#

then I think you'll assign the material to, materialProperty.objectReferenceValue

#

if you've not worked with editors before, then you'll want to read up on it, its a bit more than I can just describe quickly here without probably screwing something up

patent seal
#

Interestly, might be a new thing, but I just changed the object via the editor script without having to explicitly save, and it worked

#
    public void AssignMaterial()
    {
        MeshRenderer[] frames = rootMesh.GetComponentsInChildren<MeshRenderer>();

        for(int i = 0; i < frames.Length; i++)
        {
            var name = destination + i + ".mat";
            Material material = (Material)AssetDatabase.LoadAssetAtPath(name, typeof(Material));
            frames[i].material = material;
            Debug.Log("Assigned " + name + " to " + frames[i].name);
        }
    }
severe python
#

that will generally work, but you'll miss out on some things which I'm incapable of clarifying

#

Undo won't exist, so if that matters you'll want to setup support for it, its not too hard for a 1 off case

patent seal
#

yeah that makes sense. Thanks for your help 🙂

severe python
#

no problem

gloomy chasm
#

I can't figure out how the heck to do a Singleton MonoBehaviour that works in editor. Any ideas?

cedar reef
#

Does it have to be a MonoBehaviour for some reason?

#

Because it can just be a static class at that point

gloomy chasm
#

I need it to save the data from designtime and use it in runtime.

cedar reef
#

You could save it in a ScriptableObject

gloomy chasm
#

True

cedar reef
#

If you really have to use a MonoBehaviour, you can force the editor to load a prefab into memory with PrefabUtility.InstantiatePrefab and work with it from there

#

But you'll need a static class to do at least that

severe python
#

I want to metnio, I've frequently run into problems when I've tried to use static initialization in unity

#

I do a lot of heavily dynamic reflection stuff though, so that could be related

gloomy chasm
#

No, a So should work better actually. Idk why I didn't think of it, I have been doing so much with SOs of late...
Can you use ISerializationCallbackReceiver with SOs? Or do you need to? I need dictionaries.

severe python
#

I believe so

#

they still utilize SerializedObjects in the editor

cedar reef
#

You can

severe python
#

sorry, I believe you can, whether or not you need to I'm unsure, dictionaries are dictionaries

cedar reef
#

You can use ISerializationCallbackReceiver with any class marked with the Serializable attribute

#

There are assets that bring dictionaries to the editor, a few of them free

gloomy chasm
#

Yeah, I only need the serialization. As long as they are saved, I'm good. And I can just put the keys and values in arrays for that

#

Shoot, now I gotta remember how to get things to show in the sceneview from a SO

onyx harness
#

I work a lot with statics, there are some stuff required to know, but beside that, it works like a charm in the Editor

cedar reef
#

Yeah, just gotta be aware that everything basically gets cleared out when there's a recompile

odd vessel
#

I created a custom editor that draws a handle in OnSceneGUI with Handles.PositionHandle, and I'm also using a Vector field in OnInspectrGUI.
However, when moving the position handle, the vector field doesn't update. how can I force refresh of it?

lucid hedge
#

@severe python is that UI Builder something native? or your tool?

waxen sandal
#

There's a new UI Builder in 2019.3? IIRC

lucid hedge
#

ah it is

#

yeah

#

thank you!

#

that's awesome, need to get into UI elements badly

onyx harness
#

I'm no expert on this matter, but is it possible to use UI Builder in 2019.3 then backport the result to an earlier version?

waxen sandal
#

Probably?

#

I think it just generates xml files

onyx harness
#

That would be great, but still asking, because... I don't expect it to work

lucid hedge
#

can UI Elements be used to create UI in scene view?

#

should be right?

#

just not game view right now?

onyx harness
#

I don't know how different are the engines between versions

waxen sandal
#

@lucid hedge You should be able to get the root object of the scene somehow not sure if it's officially exposed

lucid hedge
#

cool thanks

severe python
#

It's a custom ui elelements, some ui buildera

severe python
#

honestly, UI builders part is fairly limited

#

oh, nevermind thats not what you were asking lol

#

@waxen sandal @lucid hedge UIElements for the scene/game are not available just yet, but soon

waxen sandal
#

Well you can draw on top of the scene editor window

#

In hacky ways

#

But not for actual ingame use

lucid hedge
#

Yeah that's what I want just scene editor. Just edit mode.

#

But overlayed on scene editor.

#

Scene view*

severe python
#

is probably possible, but I don't actually know

lucid hedge
#

I think it should be, will give it a try

tidal cave
#

Is there a way to add class instances into propety via inspector? I have a component that can accept several "strategies", and I want to just select a type in inspector (inheritor of a specific abstract class), and have it instantiated in runtime. Also I want to set its properties in inspector. Same for an array of strategies. (may be kinda Volume Overrides, or something).

severe python
#

not without making a custom editor

#

and what you're trying to do isn't exactly clear

#

are these class instances derived from MonoBehaviour or ScriptableObject?

tidal cave
#

I don't need them to be even Object, but if it is required, I can make them anything or [Serializable]

#

It's more like a logic plugin, e.g. if I have an actor (gameobject with behavior), I'd like to plug in different decision making strategies, etc.

#

Like for AI, it could be "reaction to alert" and strategies like "attack", "flee", "defend"

severe python
#

this has always been a little difficult because unity serialization couldn't handle multiple types in a field or an array

#

You can populate a single field with a specific type, if you build a custom editor, but you'll lose the data type upon serialization

#

That being said SerializeReference is a new feature aimed to solve that problem

#

but you have to be on the 2019.3 beta to try it out, and its still buggy

tidal cave
#

yep, I'm on 19.3b

#

It's not a production code, and yes, it is buggy 😦

severe python
#

thats what I'm using to do all that component stuff above, I have a struct with IComponentData and ISharedcomponentData in it, and I built a custom editor to allow me to populate them

#

basically I get a collection of all types that are assignable to IComponentData, and created a search box that lets me pick one, create an instance, and inject it into the array

tidal cave
#

Dang, too complex. I was hoping for something easier 🙂 For now I just have a number of empty GO with strategies as components on them, and I set a component property from there…

severe python
#

its not too bad tbh

#

if you're dealing with a single field, you're talking a few lines of code, maybe 20?

tidal cave
#

I have fields and arrays. Thanks, I will look into SerializeReference and *ComponentData stuff.

severe python
#
void OnInspectorGUI()
{
var types = AppDomain.Current.GetAssemblies().SelectMany(asm => asm.GetTypes()).Where(typeof(IComponentData).IsAssignableFrom).toArray();
var property = new SerializedObject(target).FindProperty("IComponentDataField");
//GUI stuff to present type options
//GUI stuff to select type option
property.managedReferenceValue = Activator.CreateInstance(selectedType);

//Importantly
property.serializedObject.ApplyModifiedProperties();
}
#

with an array you'd have to use the property.GetArrayElementAtIndex call to get the actual property element

#

that said nothing says you have to use serializedProperties, they just provide some additional functionaltiy over modifying target directly

tidal cave
#

Does reflection work in il2cpp targets? stupid me, it's editor

severe python
#

tbh, I donno, but yeah, doesn't matter

#

I think some reflection works

#

I believe its just System.Reflection.Emit that you can't use

fresh shell
#

Is it possible to add to the window context menus? such as when you right click on the inspector window, I want to put something in the add Tab section but I cant seem to find the right context for the MenuItem attribute.

severe python
#

I knjow you can fo rmany places, though I'm not sure about that one specifically

#

@fresh shell This is how they get the ui elements debugger in there I think?

        public const string k_WindowPath = "Window/Analysis/UIElements Debugger";
fresh shell
#

Oh awesome okay. Thanks @severe python that should be a good place for me to dive more into it.

severe python
#

I just was looking aroun the unity reference

#

which I totally recommend keeping a copy of on hand, because its helpful for this kinda stuff

fresh shell
#

That's a good idea

severe python
#

I found that just by right clicking on the tab seciton you were talking about, thens earching for UIElements Debugger

onyx harness
#

@fresh shell have you looked at IHasMenuItem or something similar, I don't remember the exact name

severe python
#

in the source code, to see if I could figure out the path

fresh shell
#

@onyx harness I hadn't I'll take a look at that too. Thank you!

onyx harness
#

This one allows you to intercept the contextual menu when you right click the tab of a window

severe python
#

man, no one from unity responded to my popup positioning issue

onyx harness
#

Positioning issue? What is it?

severe python
#

as far as I can tell, with UIElements you can't get the screen space position of a control

#

Since UIElements are drawn in hierarchical order, you have to move a control up to the rootVisualElement as the last child in order for it to render above everything else, within the window panel

#

however, if the popup would show up at the edges of the panel, it would be cut off, or you have to have some code to have it move its positioning so it remains visible, which may not be preferrable

#

So the obvious choice would be to launch an EditorWindow with EditorWindow.ShowAsDropDown or Editor.ShowPopup

#

however in order to use either of those you need to be able to position them with screen space coordinates

#

and since you can't find the screenspace coordinates of a UI element you cant position them appropriately

#

And so the only way to actually accomplish this is to setup an IMGUI container and use the old REct layout system

#

and a classical imgui popup window, which means your popups cannot contain uielements

onyx harness
#

Interesting, if one day I stumble upon that, I will gladly investigate

severe python
#

there is a work around with using Win32

#

but I didn't want to solve it using a platform specific solution

#

even though it will never affect me, I may decide to release this code for others and in that case I'd like to not prevent it from being usable for linux or macosx users

severe python
#

welp, i guess we will be getting the ability to control z-index, eventually

#

it is not a "near term priority"

#

so 2021 maybe?

#

:/

severe python
#

buahahahaha, I stumbled upon a solution that should theoretically be portable

#

it does use reflection...

#

welp, I figured out how to handle positioning

#

but editor windows take focus when shown

onyx harness
#

What is the problem with reflection

severe python
#

I'm now in the process of hacking my way to success through reflection...

#

I'm accessing methods and properties marked internal in the Unity source

onyx harness
#

Just keep the focus, no?

#

So? XD

severe python
#

which means its not an API which means it subject to change without notice

onyx harness
#

The notice is the alpha ;)

severe python
#

so it could break at any time

#

fair enough, I could be ahead of everyone except other people like me who live on the bleeding edge

onyx harness
#

Trust me, this is no issue

severe python
#

also, what you talking about, just keep the focus?

#

I don't know a way to not give up focus?

#

certainly not in this context

onyx harness
#

Get the current window and focus it right after you opened your popup

#

Or create your pop-up manually

severe python
#

well, I did it, I can open the window as a popup and not lose focus

#

oh I tried that, it didn't work really

onyx harness
#

(I don't know your code, so I don't know which technique you used)

severe python
#

I tried a bunch of different things with not giving up focus by refocusing the textbox, none of it actually worked sadly

#

but now I'm not even losing focus in the first place, which is honestly preferable

severe python
#

I'm making progress here, but god damn, its just a slog

#

every problem I solve leads immediately to a new problem

#

it seems the focus transfer to click on something is an issue

severe python
#

woa my gif capture has some uh, artifacts huh

#

styling is a work in progress

scenic elbow
#

that looks great

#

i like how it still shows even outside the unity window

severe python
#

It's a little buggy, needs work but it's going well now that I sorted out the big problems

lucid hedge
#

I have a scriptableobject in my project

#

and I'm trying to add a material asset as a sub asset

#

but I'm getting the error

#

'AddAssetToSameFile failed because the other asset Section 0 Material is not persistent'

#

any idea why that is happening?

onyx harness
#

Just make it persistent. Save it to disk, then delete it.
@lucid hedge

lucid hedge
#

I tried doing that after you suggested but then I notice I was adding cycle to material when really I wanted to add material to cycle 😮

#

and that fixed it

onyx harness
#

lol

#

Well gj 🙂

lucid hedge
#

works 🙂

#

thank you

tidal cave
#

@severe python is that thing with Add component to Entity Model your editor or something standard? I need exactly this!

waxen sandal
#

Is it possible to show a tooltip like window when the user clicks a button?

#

Something that would say for example "Id copied"

visual stag
waxen sandal
#

Custom Editor :/

visual stag
#

You could find the inspector in question and send the event there

waxen sandal
#

Oh fuck

#

I forgot, it's actually neither an EditorWindow or an CustomEditor

#

It's just a class that gets used in multiple different places

#

That has a draw method

#

It mostly gets used in a custom editor though so I'll just show it in there

#

Thanks!

severe python
#

its a custom control I built, its a type ahead search box (really just doing some contains checks on strings)

#

actually its a combination of htem I built for UI Elements

#

theres AutoTemplate which sets up the whole root of the inspector using a type lookup for the uxml template

#

and there is the ItemsControl which does the same thing against an array/collection, it looks up each items type and loads a uxml template by name

#

then there is finally the SearchSuggest control, which is what makes up the parts of the "Add component" ui, which justpresents a list of labels that you can click on in a poup window which populates the items control

#

an itemscontrol*

severe python
#

actually it can populate whatever you tell it to

severe python
#

Anyone know if there is a way to see if Unity is losing focus as a whole?

onyx harness
#

Yes

#

But it only work on Windows

#

Do you still want it?

severe python
#

nah, i was hoping for something generic

#

a unity api or something, I can do a whole lot of neat stuff with win32, I just don't want to go down that road

#

not unless I know of, how to interface with, and target other platforms method of doing so

#

and I can't even test it

#

like, one time I put a wpf application inside an inspector for Unity, becuase I hate IMGUI

#

built a whole ipc mechanism to update the data between unity and the app

#

was totally more trouble than it was worth

patent pebble
#

hi! Does anybody know if there is a simple way to create a new handle every frame and keep the handle from the previous frame in it's position?

#

is that possible at all?

#

I'm drawing handle sphere like this:
Handles.SphereHandleCap(0, debugger.transform.position, Quaternion.identity, 0.5f, EventType.Repaint);

#

I would like to redraw that handle every frame but keeping the handle of the previous frame also drawn

cedar reef
#

You have to store the previous positions, and do a Handle for each of them.

patent pebble
#

that was my guess, storing positions in an array and drawing multiple handles. But I wanted to make sure if there was a simpler way

#

thanks anyways @cedar reef 🙂

gloomy chasm
#

I know I have learned this before but I have forgotten. Why would the selection for my freemove handle be like twice the size of the handle? And more importantly how do I prevent it?

severe python
#

zoom?

jaunty furnace
#

hi i'm really struggleing with the [SerializeReference] attribute in 2019.3. it does what it's supposed to but it refuses to apply changed fields to the asset if i use a custom inspector for the class that holds the [SerializeReference] field. property drawers don't show up at all and even a normal enum field shows up as an int. this can't be how it's intended to function right? how can i get around this? i need a [SerializeReference] tagged field to work with propertyDrawers and preferably also with custom inspectors...

severe python
#

Are you using UIElements?

#

If so, I guess PropertyDrawers don't work for UIElements yet

uncut snow
#

Did anyone ever serialized a field by its own? since unity doesnt support polymorphism- serialization before 2019.3 ?

waxen sandal
#

What?

uncut snow
#

i mean save a inspector field with some other serialization lib and load it ?

severe python
#

@uncut snow I have a hierarchical class structure I serialized with Newtonsoft.Json because the design relied upon properties which where backed by an object graph and I needed to serialize the graphs behind the properties in addition to the structure

#

it was a pretty miserable experience overall, and I had constant problems when the data structure changed

uncut snow
#

thx for the info^^

muted pelican
#

Cross platform buttons with OnLeave/OnHover etc, does this exist or will I have to build it all myself?

#

Problem I had is that I want to use a function at each event, not just change sprite for example

forest hare
#

Does anyone experienced really long build time for AssetBundles ? I have like 300Mo of AssetBundles data and it takes 29hours on a decent machine (i9, 32GB of RAM, SSD).
I use the AssetBundle Browser, maybe this tool causes troubles ?

#

I know it's single threaded but come on...

waxen sandal
#

Some of the newer Unity assets like ShaderGraphs are actually not serialzied with Unity

#

They use a custom serializer that they save in a normal .asset file

#

And are then trasnformed to the asset file using a scripted importer

surreal bramble
#

guys i have variables inside of a class that i use in a list and i need the editor script to show a variable inside of the class instead of in the script in the inspector

stark geyser
#

You need to make serializable the class you are using, by adding [System.Serializable] on top of it.

#

Every public or marked with [SerializeField] attribute field inside of it will be serialized in the inspector in Unity

severe python
#

it does not work for Properties however, only Fields

surreal bramble
#
    public class dialouge
    {
        public string ElementName;
        [TextArea]
        public string Text;
        public bool skip;
        public float skipT;
    }```
#

this is my class

#

i want the skipt to appear only when skip is true
and iam using this class in a list

cedar reef
#

Then you're going to need to make a custom property drawer

severe python
#

yeah, you'll want to write a custom PropertyDrawer for the dialogue class that checks the value of skip and then renders skipT based upon that

surreal bramble
#

how

#

do you have an example

stark geyser
cedar reef
#

You have Google at your fingertips. Don't be afraid to use it.

severe python
#

Aye, I'm not one to do the "You need to google first" but when it comes to specific implementation things, following the manual or watching a well built tutorial is better than some chat conversation

surreal bramble
#

i always do google first i just don't know what to specifically look for right now

severe python
#

No worries, the hardest part of development in my opinion is knowing what to look for

surreal bramble
#

if i have class f inside of anthor mono class n do i have to say typeof(n.f)

#

and f is serializable

severe python
#

do you mean like

#
    public class MyBehaviour: MonoBehavior {
        [System.Serializable]
        public class dialouge
        {
            public string ElementName;
                [TextArea]
                public string Text;
                public bool skip;
                public float skipT;
        }
    }
surreal bramble
#

yes

severe python
#

yeah, the parent class becomes like (this is not TECHNICALLY accurate) a namespace

onyx harness
#

(FYI, it is called a nested class)

surreal bramble
#

ok thanks

severe python
#

man, everytime I talk to someone who is doing procedural modeling, and I show them my project, after they asked

#

they never say anything

surreal bramble
#
public class IntractionE : PropertyDrawer
{
    public override VisualElement CreatePropertyGUI(SerializedProperty property)
    {
        var container = new VisualElement();

        var skip = new PropertyField(property.FindPropertyRelative("skip"));

    }
}```
#

why is there an error in CreatePropertyGUI

regal jasper
#

@surreal bramble check the console for the error description, it is probably warning you that the method should return a VisualElement but you are never doing that

surreal bramble
#

it says not all code paths return a value

#

oh ok got it

severe python
#

uh, that might not work, maybe its in specific versions, but I've been told that UIElements PropertyDrawer doesn't work

#

maybe thats incorrect

#

or maybe theres a caveat I'm not aware of that causes that situation

surreal bramble
#

no it did

#

work

severe python
#

huh, there must be a more specific situation, or I was just misinfomred

surreal bramble
#

is there something like DrawDefaultInspector (); for property drawers

severe python
#

PropertyField is basically that

#

in my templating system thats how I'm using it

cedar reef
#

Yup, that's how you draw a default inspector

#

If you mean draw the default one, not a custom property drawer, no there's not a method I'm aware of

#

Possibly something you could do through reflection

surreal bramble
severe python
#

maybe thats what I was being told

#

Examine this and the response, it may be releavnt

surreal bramble
#

my current script it's still giving me the same problem

#
public class IntractionE : PropertyDrawer
{

    override public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        base.OnGUI(position, property, label);

        bool Skip = property.FindPropertyRelative("skip").boolValue;

        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

    }
}```
#

no gui implemented

#

?

severe python
#

Unfortunately for you, I don't do a lot with imgui or property drawers, uhm

#

maybe don't call base.ongui?

#

I imagine that woudl draw the property twice

surreal bramble
#

it's ok i fixed it

severe python
#

sweet

#

what was the problem?

surreal bramble
#

this EditorGUI.BeginProperty(position, label, property);

#

i had to write it

surreal bramble
#
    {
        EditorGUI.BeginProperty(position, label, property);
        var nameRect = new Rect(position.x, position.y + 18, position.width, 16);
        var diaRect = new Rect(position.x, position.y + 36, position.width, 16);

        EditorGUI.indentLevel++;

        EditorGUI.PropertyField(nameRect, property.FindPropertyRelative("ElementName"));

        EditorGUI.indentLevel--;
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        Rect rect = new Rect(position.x, position.y, position.width * 0.4f - 5, position.height);

        
        EditorGUI.EndProperty();
    }```
severe python
#

I'll be making another repo with the test case I was setting up, but it requires a whole bunch of packages

severe python
#

lots of room for improvements in thie system, some of the code in ItemsControl can be extracted into its own code for just a template presenter

#

I should make this a package

severe python
#

and now its a valid package

onyx harness
#

@surreal bramble you need to override GetPropertyHeight()
And in your OnGUI, you are not required to call Begin/EndProperty.
Also, I don't understand the last Rect

surreal bramble
#

Yeah i did that but thanks anyways

surreal bramble
craggy kite
#

is this a serialized list?

look up PropertyDrawers

surreal bramble
#

iam using property drawers i just don't know what this arrow is called

craggy kite
#

lookup "Foldouts" then, that's what it's called

visual stag
#

You can also use the debugging tools to find out what things are

#

information about them is pinned to this channel

surreal bramble
#

guys when i have my foldout unfolded i can't change anything```[CustomPropertyDrawer(typeof(Intraction.dialouge))]
public class IntractionE : PropertyDrawer
{

override public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    EditorGUI.BeginProperty(position, label, property);

    var nameRect = new Rect(position.x, position.y + 18, position.width, 16);
    var diaRect = new Rect(position.x, position.y + 36, position.width, 64);
    var skiRect = new Rect(position.x, position.y + 108, position.width, 16);
    var skitRect = new Rect(position.x, position.y + 126, position.width, 16);

    bool sk = property.FindPropertyRelative("skip").boolValue;
    property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
    EditorGUI.indentLevel++;

    if (property.isExpanded)
    {
        EditorGUI.PropertyField(nameRect, property.FindPropertyRelative("ElementName"));
        EditorGUI.PropertyField(diaRect, property.FindPropertyRelative("Text"));
        EditorGUI.PropertyField(skiRect, property.FindPropertyRelative("skip"));

        if (sk == true)
        {
            EditorGUI.PropertyField(skitRect, property.FindPropertyRelative("skipT"));
            extraHeight = 16 * 8;
        }
        else
        {
            extraHeight = 16 * 7;
        }
    }
    else 
    {
        extraHeight = 0;
    }

    EditorGUI.indentLevel--;
    position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

    Rect rect = new Rect(position.x, position.y, position.width * 0.4f - 5, position.height);

    
    EditorGUI.EndProperty();
}```
waxen sandal
#

Define can't change anything

surreal bramble
#

i can't click on the text box and write in it

surreal bramble
#
[CustomPropertyDrawer(typeof(Intraction.dialouge))]
public class IntractionE : PropertyDrawer
{

    override public void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        var foldRect = new Rect(position.x, position.y, position.width, 16);
        var nameRect = new Rect(position.x, position.y + 18, position.width, 16);
        var diaRect = new Rect(position.x, position.y + 36, position.width, 64);
        var skiRect = new Rect(position.x, position.y + 108, position.width, 16);
        var skitRect = new Rect(position.x, position.y + 126, position.width, 16);

        bool sk = property.FindPropertyRelative("skip").boolValue;
        property.isExpanded = EditorGUI.Foldout(foldRect, property.isExpanded, label);
        EditorGUI.indentLevel++;

        if (property.isExpanded)
        {
            EditorGUI.PropertyField(nameRect, property.FindPropertyRelative("ElementName"));

            if (sk == true)
            {
                EditorGUI.PropertyField(skitRect, property.FindPropertyRelative("skipT"));
                extraHeight = 16 * 8;
            }
            else
            {
                extraHeight = 16 * 7;
            }
        }
        else 
        {
            extraHeight = 0;
        }

        EditorGUI.indentLevel--;
        //position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        
        EditorGUI.EndProperty();
    }

    float extraHeight = 120;
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        // Use Unity's default height, which is a single line
        // in the inspector
               
       return base.GetPropertyHeight(property, label) + extraHeight;
    }

}```
#

code

surreal bramble
#

is there an alternative for GetPropertyHeight

#

because i have a list and every time i change the height it changes for all the elements not just the element that iam working with

#

and i know why i just don't know how to stop it

surreal bramble
#

basically what i want is to assign each property it's own height instead of having a GetPropertyHeight

dim walrus
#

You could have a bool isControlled and change the height based on that?

surreal bramble
#

guys iam using editor gui layout but now it's in the end how can i make it go up

dim walrus
#

What do you mean?

surreal bramble
#

EditorGUILayout

#

it creates the field in the bottom of the script

#

i want to move it up

lucid hedge
#

for UIElements

#

how do I get syntax highlighting and stuff

#

for .uss

waxen sandal
#

What ide?

lucid hedge
#

vscode or c# rider

#

but .uss is a unity specific extension right?

waxen sandal
#

In Rider you can go to Settings > File Types > CSS

#

And add an extra extension

lucid hedge
#

ahh

waxen sandal
#

But you'll also get autocompletion of CSS :/

#

In VSCode you can mark the file as CSS in the bottom right

lucid hedge
#

oh yes that solved it immediately

#

tysm

severe python
#

I use Notepad++ for it

#

it would be nice if they built a syntax engine for VS though

crystal timber
severe python
#

sexpr eh?

#

ah neat, til what sexpr is

crystal timber
#

ah without that line

#

just add uss and uxml, the css editor in vscode is really nice

severe python
#

I wonder if there is a way to do that for regular VS

crystal timber
severe python
#

das really neat

#

oh, I guess I could just build a USS text editor with UI elements

#

especially since I havbe a reliable type-ahead search

crystal timber
#

in regular VS you can click 'Open with...' on the file and select css/xml editor as default

severe python
#

oh, thats right, you totally can

#

I always forget that you can do that

#

not only that, but you can set it as default

#

o/ @crystal timber

crystal timber
#

but the vs css editor is not so cool like vscode, so I always open my project with both vs and vsc lol

severe python
#

yeah, but I ahve a color picker now

#

I don't have to just make educated guesses for my color hex values now

tidal cave
#

I'm generating mesh in Editor when user hits a button and assign the sharedMesh in MeshFilter component. When object is in scene it works perfectly. But when I make it a prefab, it generates mesh, everything is working, but when I open scene or another prefab in Editor, the generated mesh is lost… Any ideas?

onyx harness
#

Your mesh is 100% temporary

#

If you lose its host (a MeshRendrer I guess), you will lose the Mesh.

#

You need to save it to disk.

tidal cave
#

I have a MeshRenderer on the same object…

#

But I wonder why Scene persists the Mesh (even with Unity closing and reopening) but prefab doesn't

severe python
#

the issue is the mesh isn't an asset

#

the data isn't saved into the MeshRenderer

#

the meshrenderer saves a reference to an asset that is going to disappear

#

in a scene that asset reference can persist

#

but outside it has no where to peresist to

#

IIRC, you need to use AssetDatabase to create an asset for the mesh

tidal cave
#

Why is it so? Scene and prefab has more or less the same structure, and in scene Mesh is serialized, and in prefab it is not

severe python
#

I can't say specifically as I don't know

#

but they are not the same overall

#

You could view a scene as a prefab

#

but its not one, they are different

#

you can't override elements of a scene and store multiple versions of the same scene with overrides

onyx harness
#

When your generate a Mesh and assign it on a MeshRenderer that lives in a scene, the scene persist it after restarting Unity? O_O

#

I need to check that

tidal cave
#

Yes, the mesh data is in the YAML file

onyx harness
#

Interesting...

#

Well I guess it is auto-embedded

#

While a prefab needs a viable link to the Mesh.

severe python
#

the important part that matters is that it doesn't happen for prefabs

#

Why that is, ask Unity Technologies

tidal cave
#

Yeah, I understand that it doesn't happen 🙂 I was thinking I'm missing something

onyx harness
#

But technically, I would like to add, a scene is a prefab.

#

There have no difference but the extension at the end.

#

Which will be handled differently due to it

tidal cave
#

Can I may be create an empty persistent mesh, link it to prefab, and when generating code would update the original mesh?

onyx harness
#

It's a way to go

#

But yep, this should work

tidal cave
#

May be I'm blind, but I can't see how to create an empty mesh asset…

onyx harness
#

new Mesh()

#

AssetDatabase.CreateAsset() ? Something like that

tidal cave
#

UnityException: Creating asset at path Prefabs/Small Stone Mesh.asset failed.

#

No much information in the exception…

onyx harness
#

Have you forgot Assets/?

#

Yeah I agree, most errors are very poorly written

tidal cave
#

Yes, thanks. 🤦

wispy delta
#

I saw that SerializedObject.ApplyModifiedProperties returns a bool. The documentation doesn't saying anything about it tho. Does it only return true if properties were modified?

#

After testing it appears so. neato

whole steppe
#

Im just starting out in Unity, what VS Extensions would you reccomend?

lunar raptor
#

I'm trying to install a couple of extensions but Visual Studio seems to dislike that. VS prompts that extensions will be installed once all VS windows are closed but closing all windows and reopening has no effect at all (I've tried this about 5 times now)

#

Going to try restarting now

lunar raptor
#

Restarting was useless

#

OH

#

Nope, still not installing

#

OH GOD FINALLY VSIX MAGICALLY OPENS

#

All I did was click Stop Roaming for the extensions thing

severe python
#

I see some people have cloned my repository for visual templates, any thoughts?

tidal cave
lone wing
#

I have an editor script that contains some variables, like objects, when in a session I drag the assets into the object fields (some in the scene, some in the project), is there a way to make those persistent after restarts of Unity, or do I need to make a scriptable object or something like that and serialize that? I have them set to [SerializeField], and the editor script set to Serializable, but I guess I am confused on the set dirty part, if that is what I am missing.

onyx harness
#

code code

half marten
#

Can you make custom editor windows which are based on the scene view?

#

I'd like to make a comprehensive level editor that's separate from the regular scene view, but still is based on it so I can make use of the built in tile brush features

waxen sandal
#

@tidal cave Got any gifs?

tidal cave
#

Nope. It’s trivial 🙂

#

Drop it to Editor project

feral karma
#

@half marten last time I needed something like this I ended up making hidden/invisible objects in the scene, with a camera that renders them to a separate RT that's used in the editor window
Gives you full control but you have to do all raycasting etc yourself.
Not saying this is the best or only way :)

half marten
#

does that allow tile painting on the custom window though?

#

i imagine not, since it's just the visual element of the camera render

sharp siren
#

Hi, on Visual studio, intellisense works fine for terms like "GameObject", but not for functions like "Update(), Start().... " any idea please ?

onyx harness
#

Install Unity plugin

#

They have plenty of stuff to "easily" add those methods

#

(My favorite way) Or use snippet

sharp siren
#

ok thanks, going to try it now !

#

@onyx harness Do I install it on visual code ? or is it available on VS ?

onyx harness
#

@sharp siren It's pretty easy to find it, look for vstu

#

you need to install it

#

Usually, Unity installer offers it

sharp siren
#

I don't understand. I've go VS but not VC. Do I need absolutely VC ?

sharp siren
#

ok thanks. that's works fine 🙂 @

#

@onyx harness

cloud prairie
#

What is a font that y'all like at the moment? I'm using cascadia code

waxen sandal
#

FiraCode

cloud prairie
#

Ima check that out

waxen sandal
#

With ligatures

cloud prairie
#

are ligatures the curly ones?

waxen sandal
#

They're combing multiple characters to one

#

Visually

dim walrus
#

Is there any way to get the unity conversion from string to a float with the operations?

#

Like placing (7+8)*2 sets a float in a field

#

I have found some third parties that does this like Flee but i wanted to know if unity has any solution built in

#

Found it in case anyone wants it

severe python
#

understandably editor only, but a little disapointing

dim walrus
#

Does anyone know how to use the "Context" with Editor Shortcuts?

#

Is a type but i have 0 idea of what type to set for playmode

odd swan
#

anyone want to edit directly that visual element inside bulit-in element, use reflection

#

Unity won't present this class :/

#

use refelection to can access their properties, fields.

#

(thats only way I think by discovered)

odd swan
blazing cosmos
#

https://github.com/lucascassiano/Unity-Arduino-Serial-Port-Finder
Guys, did anybody worked with this in previous. This is a project that works on setting up Arduino and Unity auto configuration. If yes please leave me a message. I've been sitting on make this thing work for one week

odd swan
#

I has more discovered with reflection, and I confirmed Unity doesn't exposed UIElement bulit-in control's subclasses

severe python
#

no it doesn't but you don't need to use reflection to look at the unity code base

#

go grab the Unity CS REference source

odd swan
#

I have more discovered, there's TextElement abstract class exists

#

PopupTextElement inherits it

#

So I actually now can access without reflection

#

@severe python and thanks to notice it to me! (but I found it before see it, my spended time...)

#

@severe python hey can I capture your advice?
Just posting on my devlog

#

oh god

#

PopupFieldTextElement

severe python
#

advice on?

odd swan
#

um

#

like this

#

WOW I ACTUALLY WRONG POINT AT THIS

#

*crying*

hallow glen
odd swan
#

@severe python so can I post your advice?

severe python
#

to grab the unity cs reference?

odd swan
#

yes

severe python
#

I mean, sure? but its not mine, thats all Unity-Technologies

odd swan
#

^^^^^

severe python
#

all I did was point you at something they did

#

I'd prefer if you didn't put my profile pick/nick in there tbh

odd swan
#

ok thanks!

#

hmm

severe python
#

If I were writing a devblog, I may say "With the help of a user on Unity's official Discord I found the Unity CS Reference source, an invaluable tool for anyone working with Unity's newest technologies" or something like that, then link the github repository

odd swan
#

oh thats actually good one

#

very thank you so much!

severe python
#

You're welcome

odd swan
severe python
#

@odd swan make your window really small then use that popup

#

does it still work right?

odd swan
#

yes

#

Unity's default font is actually hard to read in HiDPI

#

with CJK text

#

:(

#

So I replaced that

#

CJK stands Chinese, Japanese, Korean

#

Unity's default font doesn't contain CJK range font, so they replace system default font

#

...and there's not exist font weight

#

;(

severe python
#

should be in css

#

sorry, Uss*

odd swan
#

yes i does

#

defines root style

#

my problem was

#

by just this / thing

#

this separates popup and generic menu list

#

so I was discovered about this is UIElement, like web development. may can able to only swap it's display text?

#

Process of my discover

  1. change value property - failed, it's throws ArgumentException with Not present in list of possible values
  2. get Label through querySelector(Q) to change it - failed but found it PopupTextElement is private subclass

So I first time search about it but as you know, I was search with wrong keyword lmao (PopupFieldElement)
Then I check with debugger and inspect what it have fields, properties.

  1. using REFLECTION to force set it's value - ok, but hmm this is actually only way to able this?

So I post at here and...

  1. I found PopupTextElement is inherited TextElement abstract class!
  2. And got a Unity source repo to check it's structure.

Even works well with it, yay!

After discover, I realize I was search with wrong keyword facepalm

#

Anyway it's solved!

#

👏

#

I going to bed

#

gn

tough cairn
#

Hi i got strange results in the scene height values

#

viewing the numbers like so:

Debug.Log( SceneView.currentDrawingSceneView.position.height + " , " + Screen.height );
#

OnSceneGUI for a custom editor

#

1st and 2nd value don't match

#

more over the difference between the two is never static

#

also im using scaled DPI on windows10

#

any ideas ?

#

Huh ... i think i got it

#
var diff = Screen.height - SceneView.currentDrawingSceneView.position.height * EditorGUIUtility.pixelsPerPoint;
#

which will result in a semi constant value of 24.25 ~ 25 ( with a cyclical step size of 0.25 )

#

very strange

#

maybe it has to do with my current DPI scaling of 125% which results in the .25 step size

#

yep... changed to DPI scale size of 150% and now the value is 30 ~ 30.5 with a step size of 0.5 ...

#

so at scale of 100% the difference will always be equal to 20

#

maybe it has to do with the scene view header ( where the light, sound, skybox buttons are )

severe python
#

oh man, yeah Unity wouldn't be DPI aware would it...

tough cairn
#

old but gold

#

im trying to align a 2nd helper GUI box like the particle system

#

looks like magic numbers are the only solution to make it fit

severe python
#

why not use relative positioning instead of pixel positioning?

#

is that not a thing in the sceneview?

tough cairn
#

oh lol i think it is

#

let me try

#

huh...

#

seems to do the trick

#

but there is a catch

#

20 pixel bottom padding

#

although using the relative positioning ( i assume you meant to use the GUILayout and EditorGUILayout ) will take care of the DPI scaling automatically

#

.
.
Anyone know how can i set the title of the window on the left ?

severe python
#

the padding looks the same too me?

tough cairn
#

( bottom cutoff )

severe python
#

I presume thats IMGUI, if so I don't know, but anyone else would need more context

tough cairn
#

on the 1st screenshot the size of the box was always bigger then the scene

severe python
#

donno what you're doing to draw that "window"

#

but I'd suggest looking at the Unity Manual for the call you're using to create that "window"

tough cairn
#
using( new GUILayout.VerticalScope( GUI.skin.window ) ) { ... }```
severe python
#

vertical scope? I've never heard of this before

tough cairn
#

its the same as : GUILayout.BeginVerticalScope()

#

hmmm... seems like the folks at unity created a SceneViewOverlay internal class for the particle effects GUI

#

where they use: GUILayout.Window( ... )

severe python
#

yeah I was going to say, I think the first thing is that Scope doesn't take a GUIContent and so doesn't have a label, you're just applying a style which makes it seem like it should

#

GUILayout.Window likely does take a GUIContent for a label

tough cairn
#

yea but it wakes a screen Rect ...

#

which will require to do the manual calculation again

#

eh....

severe python
#

Is there an EditorGUILayout.window?

#

this is why I hate imgui

tough cairn
#

ha solved it

#
var rect = GUILayoutUtility.GetLastRect();
var titleContent = new GUIContent( titleStr );
rect.y += 2f;
rect.x += ( width - 7.25f * titleStr.Length ) / 2f;
GUI.Label( rect, titleContent );
GUILayout.Space( 20f + padding );
#

this ^ directly after closing the window vertical scope

#

seems like magic numbers will never go away

west ether
#

Not sure if this is the right place to ask but I am trying to get into Unity Editor scripting, are there any recommended reading materials/video channels/courses on picking it up + learning more in-depth about it?

odd vessel
#

I have an editor script and I want to run a function on the object after the editor app has stopped running. I tried adding an event to EditorApplication.quitting in onEnable ,but either the event isn't firing or onEnabled isn't the place. how can I solve this?

visual stag
#

do you mean OnEnable?

#

Just to be clear, because capitalisation matters

odd vessel
#

yeah sorry, you're right. I am using it OnEnable though

#

I'm also using OnEnable with the EditorApplication.update event btw, which is working. it's just the quitting event I'm not sure how to use

grim walrus
#

Whats the correct EditorGUILayout for the SerializedProperty of a quaternion?

#

alone it just shows a dropdown but the internals are not there

grim walrus
#

nvm looks like i have to make my own drawer

karmic aurora
#

Is there a good getting started guide on editor extensions? I want to build a tool that lets me interact with meshes in the scene view in a similar way to probuilder.

#

For starters just want to click on the scene view, cast a ray to find what I clicked on, and then get the mesh that it intersects.

#

I know how to do all the raycasting and object detection, I just don't know how to have that happen through interaction in the scene view.

versed crater
#

@karmic aurora

Never really found great tutorials on it. But some stuff to point you in the right direction:
You can just use the SceneView camera for raycasting https://docs.unity3d.com/ScriptReference/SceneView-camera.html

Input is a bit trickier in the scene view and generally you gotta do it with a key event like https://answers.unity.com/questions/130898/how-to-check-if-a-key-is-down-in-editor-script.html

If things aren't as snappy as you want using OnSceneGUI or whatever else they have built in, you can make a custom editor update with a bit of googling.

You can instantiate a GO to help you wherever you need in the editor and then just set it's hide and not save flags. You can also do this with additive scenes like the humanoid editor works.

gilded flame
#

Anyone know if it's possible to activate Animation mode from a script? (The mode when you have the Animation window open and the play and pause buttons become red)

#

I want to be able to apply a animation clip temporarily while I have a custom Editor window author time based metadata that shouldn't be encoded as animations

versed crater
gilded flame
#

Thanks

versed crater
#

if you DL the project and then use Visual Studio to find references to some promising things like OnStartLiveEdit you can probably find how they do it

gilded flame
#

It's a shame that it's all internal right now

versed crater
gilded flame
#

Excellent

#

One finall other question: does anyone know if the source code for Shader Graph/VFX graph is available?

#

I have a graph based editor extension that I think would be about 10x less code if rewritten in UIElements

#

And would definitely want to see if I could get the base code node based graphs off of those two packages

visual stag
#

The source is in your project when you download it

#

and also on github

feral karma
#

@gilded flame there have been a couple of attempts in the past to get a "basic node framework" based on what Unity has but they didn't exactly make it easy.

#

Problem is that they started the Graph API, deviated from it at all different times for ShaderGraph and vfx graph and now there's very little common ground between them with lots of redundant/duplicate functionality all built a bit differently. So right now there's at least 3 versions of a "Unity Graph Framework"

#

If someone knows about a project with a "clean" approach based on the current Graph api I would be super happy to see that :)

wispy delta
#

I'm trying to make a custom property drawer using ui elements and would like to put 3 floats in a row. With imgui I'd temporarily lower EditorGUIUtility.labelWidth so that they all fit but I'm not sure how to lower the label width in ui elements

public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
    var root = new VisualElement();

    var longitudeProperty = property.FindPropertyRelative("longitude");
    var latitudeProperty = property.FindPropertyRelative("latitude");
    var radiusProperty = property.FindPropertyRelative("radius");

    var longitudeElement = new PropertyField(longitudeProperty, "Lo");
    var latitudeElement = new PropertyField(latitudeProperty, "La");
    var radiusElement = new PropertyField(latitudeProperty, "R");

    var horizontalLayoutElement = new VisualElement() { style = { flexDirection = FlexDirection.Row } };

    horizontalLayoutElement.Add(longitudeElement);
    horizontalLayoutElement.Add(latitudeElement);
    horizontalLayoutElement.Add(radiusElement);

    root.Add(horizontalLayoutElement);

    return root;
}
#

Setting the width of the property element doesn't work

tidal cave
#

@gilded flame ^^

gilded flame
#

@tidal cave yeah I saw, unfortunately I am looking for something closer to Meccanim in construction, I just want to author custom state machines

#

Been trying to use that as a reference

#

Might just have to fork the official GraphView and make one myself

#

Looking at the CsReference for GraphView and it seems to all be available

tidal cave
#

What do you mean?

gilded flame
#

Didn't have time to finish my thoughts

#

The source code for GraphView is entirely in C#

#

My only thought is if it is legal to fork it give the reference only license of the CsReference repository

tidal cave
#

GraphView ShaderGraph based on GraphView is a package, not in main Unity source code. So it might have a different license, but unlikely.

#

It's Unity Companion Package License v1.0

#

Unity hereby grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available with this License
(emphasis mine)

#

Sorry, I messed up 🙂 The above is about the ShaderGraph

gilded flame
#

Oh there's two versions of it?

#

Do you have a link to where I might find this?

tidal cave
#

That's not two versions. What you see in Shader Graph tool is half generic GraphView, half special code for Shader Graph. GTLogicGraph attempts to generalize on some Shader Graph features for use in different use cases.

gilded flame
#

Yes, what I want is direct node-node connections not port-port

#

And that'd require forking GraphView

tidal cave
#

GraphView is part of the Engine/Editor, so it is covered by Engine License, I suppose

wispy delta
#

Is there a better way to indent a visual element than hardcoding the styles left property?

severe python
#

The project context Asset Create menu has gotten way to large

#

and its root context menu for that matter

tidal cave
#

So, I've seen a lot of different hacks to extend inspector editor instead of replacing it. Why is it not a standard feature of Unity Editor? If there is already a custom editor for a component, and I want to extend it I have to go through a lot of hacks to get that working (e.g. http://www.li0rtal.com/extending-unity-inspectors/)

severe python
#

extending default editors is as easy as calling the base method

waxen sandal
#

Lots are internal though

tidal cave
#

Yea, internal. And also there might be custom editors

ebon moss
#

Hello ! Does anyone here know a good (free would be great too) vegetation/grass placement system apart from vegetation studio and the default unity terrain vegetation placer (wich almost never works with 3D objects) ?

tidal cave
#

I'm working on my own, but that's because I want to learn procgen

odd vessel
#

how can I display a UnityEvent using a custom editor?

onyx harness
#

I guess yes.

odd vessel
#

... what do you mean yes? how?
just to clarify, not using the default inspector

onyx harness
#

Maybe a EditorGUI.PropertyField

odd vessel
#

I don't have a property. Or rather, it's inside a class that is inside an array property.

#

If there's a way to get SerializedProperty from that, that would be a good solution too. I couldn't find that either though

odd vessel
#

that's just the array element it self. I need the property of an array element

visual stag
#

That is an element in an array

#

if you want to find something inside of that element, then you use FindPropertyRelative

odd vessel
#

yes, element in an array = array element

#

mm I think I tried FindPropertyRelative and it didn't work, but I'll try again. Any special syntax for "children" ?

visual stag
#

what do you mean by children? You can either walk down the chain of serialized properties using FindPropertyRelative

#

or you can provide the entire property path

odd vessel
#

😮 can I use array elements using the entire property path?

visual stag
#

yes, I forget the syntax though

odd vessel
#

e.g. myArray[2].intValue ?

#

I'll try to look up the syntax then, cool. thanks!

visual stag
#

Also, you can display UnityEvents using UnityEditorInternal.UnityEventDrawer

odd vessel
#

😮 that's actually better! how do I actually use that drawer though?

visual stag
#

They might get displayed fine with PropertyDrawer, but I have used that class to create a custom version once, or just display the default field

#

just instance it and call OnGUI

odd vessel
#

lol sounds hacky but I'll take it. I'll try it, and thanks again!

ebon moss
#

@tidal cave No, because I don’t want a terrain based placement method because I am using 3D models instead of terrains because terrains aren’t scalable and always too big.

clear canopy
#

Hi everyone, is there an editor extensions that allows you to draw with 3d objects basically? Like a tilemap for 3D? I have diffrent types of 3D cubes and i want to design levels with them without having to place one after one and arrange them in a grid but instead basically draw like in a tilemap. Thanks in advance!

candid pelican
#

Is there any way to set an emissive color to Text Mesh Pro text? I'm using a Screen Space - Camera UI and would like the text to be affected by bloom.

sleek plank
#

Did someone ever made or worked on a way to import SVGs (such as the ones Figma and Zeplin exports) to a generic prefab?

#

Or a custom import system for UI?

digital spoke
#

i've tried putting strings, textures, string arrays, texture arrays etc into this first argument (GUIContent) but it always has an error

#

nvm figured it out

#

had to create a new GUIContent

#

how do I use a dropdownbutton from this point on? Clicking it in the inspector does nothing

meager chasm
#

is it possible to remove the minimum size of an editor window?

grizzled minnow
#

@meager chasm You could set the minimum size for your editor window to something tiny before opening it.

        {
            EditorWindow editorWindow = GetWindow<HelpWindow>(true, "Help", true);

            editorWindow.minSize = new Vector2(10, 10);

            editorWindow.Show();

        }
meager chasm
#

oh, i tried that already, guess you have to close and re-open the window to get it to apply, whoops

onyx harness
#

@meager chasm put it in your OnEnable to ensure it is always set.

jaunty furnace
#

can someone help me out here? I've made a custom editor that's editing scriptable object files and all is great with the editor itself but for some reason the scriptable object files are throwing errors when unity loads them. they load just fine but unity still complains... so far i've tried: 1.deleteing the meta file, 2.tried reimporting the file, 3.googled about without success. here's the error for it: Unable to parse file Assets/Data/AI/BT/Test BT.asset: [Parser Failure at line 47: Expected closing '}']any help is greatly appreciated!

#

and heres the file:```yaml
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2032da47346b4904e9e65d2347498396, type: 3}
m_Name: Test BT
m_EditorClassIdentifier:
blackboard: {fileID: 11400000, guid: 0009731d10e36914393215e7b2396214, type: 2}
rootIndex: 0
nodeGroups:

  • decorators: []
    task:
    json: "{\n "name": "Root"\n}"
    type: StaterZ.Core.BehaviourTreeSystem.RootData, StaterZ.Core, Version=0.0.0.0,
    Culture=neutral, PublicKeyToken=null
    services: []
    isProtected: 1
    childIndices: 02000000
    pos: {x: 0, y: 0}
    guid: 22686c7e-0e2d-471f-b3b6-2fa1d67936aa
  • decorators:
    • json: "{\n "name": "LoopDecorator",\n "loops": 5\n}"
      type: StaterZ.Core.BehaviourTreeSystem.Tasks.LoopDecoratorData, StaterZ.Core,
      Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
      task:
      json: "{\n "name": "Wait",\n "time": 40.0,\n "randomDeviation":
      0.0\n}"
      type: StaterZ.Core.BehaviourTreeSystem.Tasks.WaitData, StaterZ.Core, Version=0.0.0.0,
      Culture=neutral, PublicKeyToken=null
      services: []
      isProtected: 0
      childIndices:
      pos: {x: 392, y: -199.5}
      guid: be3950c6-f3dc-41c4-be46-10e066553d03
  • decorators: []
    task:
    json: "{\n "name": "SubBehaviour",\n "behaviourTree": {\n
    "instanceID": 28942\n }\n}"
    type: StaterZ.Core.BehaviourTreeSystem.Tasks.SubBehaviourData, StaterZ.Core,
    Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    services: []
    isProtected: 0
    childIndices:
    pos: {x: -85.5, y: -207}
    guid: 7a26449f-f40d-44fb-8002-413cf0921277
severe python
#

read your error

#

go to line 47 and then looka t the line above it, recognize that you're in YAML and that whitespace matters

#

That is of course assuming what you paste is accurate for what is in your files

tulip plank
#

How would I create a custom Project view icon depending on the content of a file there?

#

For example, I have a folder full of prefabs, and each has the default cube prefab icon. But I want to change the color of this cube depending on the contents of each prefab.

onyx harness
#

@tulip plank check project's gui callback

tulip plank
#

Project's GUI callback? Is project a class?

onyx harness
#

Nope, it's a callback living in EditorApplication

#

@tulip plank

tulip plank
#

Okay, I will hunt for the details about what you're referring to, using the clues provided. Thank you.

onyx harness
#

@tulip plank You are asking for a custom Project view icon.
Look at this: UnityEditor.EditorApplication.projectWindowItemOnGUI
This callback provides you the instanceID of the drawn object.
From that, you can inspect it and display whatever suits you regarding the content.

jaunty furnace
#

@severe python i didn't know yaml was senitive to such... infact, don't know much about yaml at all 🙂 i think i've solved it now so thanks for the help!

severe python
#

no problem, and yeah, YAML is a white space language

#

so the number of spaces, carriage returns, tabs, w/e, they all matter

tulip plank
#

Thank you very much, @onyx harness !

timid cobalt
#

Does anyone here know how to display arrays with property drawers

blissful sinew
#

@timid cobalt I think you can do that by EditorGUILayout.PropertyField(serializedObject.FindProperty("x"), true);
Where x is the name of the array

#

and then serializedObject.ApplyModifiedProperties();

timid cobalt
#

That doesn't work for arrays

#

I have already tried that

#

It works for everything else though

onyx harness
#

@timid cobalt PropertyDrawer applies on element of an array

#

Not the container

timid cobalt
#

Ok

blissful sinew
#

Hey, can someone help me with my editor method for converting Rotation Interpolation in animations to EulerAngles? When I use it it seems to be adding both rotations properties to the animation (I guess it's keeping the old CurveBindings and adding the new converted one) and when I add a line deleting the old one it deletes both. I don't know if it is because I'm editing dimension curves one by one (first I convert the x then y and z, instead of replacing the three CurveBindings together). I would really appreciate any help

onyx harness
#

@blissful sinew Bring some code to the table

blissful sinew
#
        {
            if (curveBinding.propertyName == "m_LocalRotation." + dimensionLetter)
            {
                EditorCurveBinding newCurveBinging = new EditorCurveBinding();
                newCurveBinging = curveBinding;
                newCurveBinging.propertyName = "localEulerAnglesRaw." + dimensionLetter;
                AnimationCurve curve = new AnimationCurve();
                curve = AnimationUtility.GetEditorCurve(clip, curveBinding);
                AnimationUtility.SetEditorCurve(clip, newCurveBinging, curve);

                //This line deletes both
                //AnimationUtility.SetEditorCurve(clip, curveBinding, null);

        }
        }```
#

Here's how I'm calling it

                for (int i = 0; i < CurveBindings.Length; i++)
                {
                    ConvertRotationInterpolationCurvesToEulerAngles(CurveBindings[i], animationClip, "x");
                    ConvertRotationInterpolationCurvesToEulerAngles(CurveBindings[i], animationClip, "y");
                    ConvertRotationInterpolationCurvesToEulerAngles(CurveBindings[i], animationClip, "z")

                }```
verbal maple
#

Hey all, I had this issue before and forgot how it was fixed. I know it was in some settings... I just updated this project from a 2018 version, to 2019.2.0f1
Here are the errors in the log:

#

I posted here because most of it said extension 😅

#

nvm, Updating the package manually fixed it.
Window -> Package Manager -> MultiPlayer HLAPI
This clear the compiling error.
However, the extension errors still persist. Pretty sure the facebook build package didn't install properly

tulip plank
#

Is there a way to actually programmatically change the icon of an item in the project window (instead of just drawing over it) ?

onyx harness
#

lol I knew you would come back with something more consistent

#

Yes there is a way

tulip plank
#

Hah yes, all the solutions online are so very hacky, as I've become accustomed to with Unity solutions.

onyx harness
#

Use new SerializedObject({YourGameObject})

#

Find the path for the {icon} and set your texture in it.

tulip plank
#

These are project window items, so what would {YourGameObject} represent here?

onyx harness
#

Use this to easily get all the paths:

public static void    OutputHierarchy(this SerializedObject so)
{
    SerializedProperty    it = so.GetIterator();

    it.Next(true);

    while (it.Next(true))
        Debug.Log(it.propertyPath + " " + it.propertyType);
}
#

Oh sorry, don't use {GameObject}, but {AnyObject}

tulip plank
#

I can get the guid or assetPath of one of my prefabs, for example.

#

These are the files/items whose icons in the project window I'd like to conditionally change.

#

For example, a prefab can be marked as "Done". If so, I might change its icon in the project window to a green one.

onyx harness
#

Hum... I think I need to clarify one thing

#

You can customize Icon for scripts & Prefab

tulip plank
#

And I definitely don't care about its icon in the Inspector window, not at all.

#

I care about it's "file" icon in the project view.

onyx harness
#

Well, the only reliable way I know is the one I gave you already

tulip plank
#

Right, drawing over the existing icon. It is helpful, I can make it work to some degree.

onyx harness
#

Unity uses few methods to fetch an icon from an Object.

tulip plank
#

I just wish there were a way to actually change the icon.

onyx harness
#

But if you want your own custom icon, you need to do it manually

tulip plank
#

It's okay, I can settle with an overlay now, and tweak it around to work with every zoom level (since it moves around as you change the icon view zoom)

tough cairn
#

How can i get all layers for a custom editor ?

onyx harness
#

What do you mean a custom editor?

#

@tough cairn You can get layers using LayerMask.LayerToName()

tough cairn
#

@onyx harness is that possible to know the layers count ?

onyx harness
#

Very easy

#

32

#

😄

tough cairn
#

hhhh

onyx harness
#

64 perhaps one day

tough cairn
#

how does Unity finds out the layers tho ?

#

in the drop down screen shot

#

i mean it knows what to show

#

does it simply check all 32 via LayerToName for nulls /

onyx harness
#

I think yes.

tough cairn
#

( or empty strings - i didn't try to read the return value of the name of a none existing layer yet )

onyx harness
#

It's simply 32 iterations.

#

Nothing dramatic

tough cairn
#

lol

#

ok that's doable

#

thanks

onyx harness
#

If one day, a user set layer 30th

#

How would you know? You kind of have no choice but to check all layers

tough cairn
#

true

#

i didn't know if there is a internal function or something that handles that

feral shell
#

searching someone who is good to animating for a project
2d platform
if the game will get money i'll give half of them to who helps me

tough cairn
#
var layers = new int[32]
    .Select( (x,i) => i + ": " + LayerMask.LayerToName( i ) )
    .Where( x => ! string.IsNullOrEmpty( x.Substring( x.IndexOf(":") + 2 ) ) )
    .ToArray();

var layers_indexes = layers.Select( x => LayerMask.NameToLayer( x.Substring( x.IndexOf(":") + 2 ) ) ).ToArray();

EditorGUILayout.IntPopup( "Layers", 0, layers, layers_indexes );