#↕️┃editor-extensions

1 messages · Page 103 of 1

prisma olive
#

thanks so much

patent pebble
#

but as I said it would probably be easier if you do it with ScriptableObjects instead

#

they work the same way with the type filtering

#

but I can share the Example code anyways if you want to learn

prisma olive
#

i'm not really sure what you mean by doing it with scriptableobjects

#

would i need to select the json object and assign it in the scriptableobject too ?

#

which would mean i'd still have to select the json file amonst all the text assets

patent pebble
#

@prisma olive yeah you would do a scriptable object with a TextAsset reference inside

prisma olive
#

exactly...then i would need to create an SO for each Json asset and assign it manually

patent pebble
#

yeah that's true, it's more cumbersome

prisma olive
#

i still would have the same problem that it shows all text based assets when selecting

patent pebble
#

with a custom asset type you can have them be still .json files but in the eyes of Unity they won't be a TextAsset, so you need to figure out a way to feed that data into Ink

#

and I assume the files that Ink outputs would be automatically picked up as your custom asset type, but I have no idea to be honest

prisma olive
#

maybe it will allow casting

#

only one way to find out haha

patent pebble
#

haha yeah, gimme a sec I'll share all the scripts

prisma olive
#

thanks mate appreciate it 😄

prisma olive
#

hehhh even a scripted importer is not gonna work

#

The scripted importer 'InkJsonFile' attempted to register file type '.json', which is handled by a native Unity importer. Registration rejected.

#

screw it... i'll just name all the files with Ink_whatever and then in the search i'll drill down with that... this is too much hassle for such little payoff hehe

patent pebble
#

In case you still want to learn about scripted importer

patent pebble
prisma olive
#

thanks so much for the package though, I'm still gonna study it and learn from it for future

patent pebble
#

and even before attempting to force a custom asset type as a fix. I'd rather implement a custom Object Picker with a custom SearchField that handles extension filtering

prisma olive
#

I will take a look at that one tbh coz it might be something helpful especially with the search field

#

thank you very much

patent pebble
#

no problem. I wish Unity wasn't so... "Unity" about some of these seemingly super basic things

#

but I guess we are all insane for wanting to search assets by extension instead of by type 🙃

prisma olive
#

HAHAH right???

#

😄

tough cairn
#

Trying out the graphView , im creating nodes items and each one has an Image element , but for some reason when changing the texture on one node will also change the image on all the other once.

In GraphView

public void NewNode( ... data ) 
{
  var node = Activator.CreateInstance( Type.GetType( data.type ) ) as BaseNode;
  ...
  AddElement( node );
}

In BaseNode

class BaseNode : Node {
  ...
  public Image preview;
  public Texture2D previewImg;
  ...
  void Init()
  {
    ... 
    preview = new Image();
    extensionContainer.Add( preview );
    previewImg = Texture2D.grayTexture;    
    preview.image = previewImg;
    preview.AddToClassList("nodeImage");
  }
  void Redraw()
  {
    if ( previewImg.width != 256 ) previewImg.Reinitialize(256, 256);
    for( var x = 0; x < 256; x ++ ) 
      for( var y = 0; y < 256; y ++ )
        previewImg.SetPixel( x, y,  ... );
    previewImg.Apply();
  }
}

The image & texture should be unique per class or is there something im missing when doing UI Elements ?

gloomy chasm
tough cairn
#

ah... figured it generates a new one each time

#

thanks

gloomy chasm
tough cairn
#

right .. im too used to editing structs from getters

#

sometimes i just do something like this ( even with classes )

public static ItemA value => new ItemA( . . . ) ; 
barren moat
unreal phoenix
unreal phoenix
#

also check with AssetDatabase.ValidateMoveAsset to make sure it's not overwriting something

heady jungle
#

Oops! Sorry I missed the reply when I woke up,

Anyways, probably not the most efficient solution but I came up with a couple of small methods which basically split the [,] into 4 regular arrays. These stay on the Entity so they serialize, and "convert" when being displayed in the EditorWindow

#

(Not actually tested it yet for the serializing part, but it should work)

EDIT: Works pretty much perfectly! Just need to make sure that my EditorWindow doesn't stay open while hitting play and I can call this complete 🙂

tough cairn
#

how to handle asset double click event ? trying to open custom window when clicking a scriptable object

#

i think i found it [OnOpenAsset]

dreamy viper
#

Hi,
I put a Textarea in the CustomEditor.
How can I change its font ? Thanks.

serene apex
#

help

#

NavMeshComponents

#

I really need help

#

cuz i can't continue my project

dreamy viper
# serene apex

I already had this problem. I have no idea what is the cause but here is what I did :
Change the Api Compatibility to .NET Standard 2.0, then change back to .NET 4.0x.
I hope it will work...

#

(Project Settings, Player)

serene apex
#

for some reason it was set to 2.0 for me

#

ok thanks it worked

patent pebble
#

most, if not all, of the IMGUI control methods have overloads that take in a GUIStyle parameter

dreamy viper
hushed dome
#

is there a way to edit a list of enums through inspector?

#

I believe it has been asked for +inf times already

#

but anyway

waxen sandal
#

You want to add extra entries to an enum

#

Or you want a list of enum values?

barren moat
#

No special handling required I'm pretty sure

#

Just do:

[Flags]
enum MyEnum {
  Boo,
  Bar
}

public MyEnum myEnum;
#

That will modify the enum mask.

#

If you want a literal list then you can do that too in the normal way you'd expect: public List<MyEnum> myEnums

atomic pelican
#

so i'm using invector third person movement to make my game and i don't want the character to rotate when the player is walking back can someone help?

patent pebble
#

by default they just get assigned 0,1,2,3,4...

#

you need them to be 1,2,4,8,16...

round tangle
#

can i ask a thing about buttons here?

#

is more in the config menù of the button

glass basin
#

hey guys, anyone here got good experience designing tools to make code flows be more effective?

#

In my case I got procedurally generated UI buttons and I'd like to make a good system to design these visually rather than having to code the positions and testing them out with multiple iterations

#

these buttons are more advanced than regular UI buttons and are supposed to be animated (position, rotation) as well

#

they're also supposed to always animate a bit differently each time (rotation) since they're supposed to be cards

#

I was thinking of using gizmos in some way to do this

#

but at the same time I think it'd make sense to have a more visual way to design and prototype them

whole steppe
#

i tried installing my first extension. universal rp. is this normal?

median karma
#

Regarding serialized Vectors, is there a way to make them editable like Transforms in the sceneview? I have some positions I want to be easily editable just by dragging like with a transform component

patent pebble
#

@median karma look into handles, they do exactly what you want

#

in your case the Handles.PositionHandle method

median karma
#

thank you

patent pebble
#

@median karma the example shows how to use them with a custom Editor, but they can also be used from EditorWindows

#

you'd need to subscribe a method to the SceneView.duringSceneGui event

#
public class HandlesWithEditorWindow : EditorWindow
{
    private void OnEnable()
    {
        SceneView.duringSceneGui += OnMySceneGUI;
    }

    private void OnDisable()
    {
        SceneView.duringSceneGui -= OnMySceneGUI;
    }

    private void OnMySceneGUI(SceneView view)
    {
        //Code to draw your handles
    }
}
karmic ginkgo
#

            var assetsFolder = AssetDatabase.LoadAssetAtPath("Assets", typeof(UnityEngine.Object));
            UnityEditorInternal.InternalEditorUtility.expandedProjectWindowItems = new int[1] { assetsFolder.GetInstanceID() };
            expandedIdsField.SetValue(treestate, new List<int>() { assetsFolder.GetInstanceID() }, null);

just unity things

tough cairn
#

this pops up when i add the second line below in a class that extends GraphView.Node :

extensionContainer.Add(preview); ///< Works as expected > 
extensionContainer.AddToClassList("nodeExtensionContainer"); ///< ERROR >
#

seemed to work so far when i was using other elements , but adding a class to a container seems to break everything , any one know alternative ways adding classes to elements ?

tough cairn
#

unity v 2021.2 btw

patent pebble
#

What's a good way of getting the icon from a script?

#

and is there any callback or any way of getting notified when it changes?

#

right now I'm reading the GUID from the meta file using magic strings, but it seems like not a great solution

#
public static string GetIconGUID(string metaFilePath)
{
    string allText = File.ReadAllText(metaFilePath);
    if (allText.Contains(", guid: "))
    {
        return allText.SubStringBetween(", guid: ", ", type");
    }

    return string.Empty;
}
#

and I currently have no way of getting notified when it changes. So I'm just checking it on domain reload, which seems inefficient 😕

waxen sandal
#

Asset import callback probably

patent pebble
waxen sandal
#

That's the one

patent pebble
#

but I wonder if there's anything internally that Unity uses to check when a script icon is changed

#

because changing it via the inspector it triggers a reimport on that asset

#

I'm trying to find it in the source code but haven't found anything so far 😓

waxen sandal
#

That's probably just a saveassets call

patent pebble
#

i think it has what I need to listen for changes on the icon

whole steppe
#

can someone help me to write a custom editor for recttransform which displays world position of selected object?

i wrote this but doesn't work

using UnityEngine;
using UnityEditor;
using System.Reflection;
using System;

[CustomEditor(typeof(RectTransform), true)]
public class RectTransformEditor : Editor
{
    private Editor _editorInstance;
 
    private void OnEnable()
    {
        Assembly ass = Assembly.GetAssembly(typeof(UnityEditor.Editor));
        Type rtEditor = ass.GetType("UnityEditor.RectTransformEditor");
        _editorInstance = CreateEditor(target, rtEditor);
    }
 
    public override void OnInspectorGUI()
    {
        GUILayout.BeginHorizontal();
        target.transform.position = EditorGUILayout.Vector3Field("World position", target.transform.position);
        GUILayout.EndHorizontal();
        _editorInstance.OnInspectorGUI();
    }
}
barren moat
#

Does anyone know how to access this setting through code?

visual stag
#

I'm not sure how, but I think you would need to get the ScriptableObject for UnityEditor.AudioManager and alter the m_DisableAudio SerializedProperty.

barren moat
#

Cheers vertx

visual stag
#
[SettingsProvider]
static SettingsProvider CreateProjectSettingsProvider()
{
    var provider = AssetSettingsProvider.CreateProviderFromAssetPath(
        "Project/Audio", "ProjectSettings/AudioManager.asset",
        SettingsProvider.GetSearchKeywordsFromGUIContentProperties<Styles>());
    return provider;
}``` is in `AudioManagerInspector` and I think you would need to go through it to create the SO
#

I'm sure there's a neater way, but that's where I'd start looking

#

either that or you actually alter the asset's text and get Unity to reload it, but I find that iffy

patent pebble
#

iirc you can access the Project Settings via loading the .asset with the AssetDatabase, by loading with the path

#

the paths for those settings are "ProjectSettings/xxx.asset"

#

I might be misremembering, but I think it's possible

visual stag
#

I've never done that before, but if it works that sounds great

#

does seem like how it works

#

just had to look one deeper 😄

#

so no reflection needed 🎉

patent pebble
#

it's been years, but I think you just edit the properties with SerializedProperty

visual stag
#

Yup

patent pebble
#

you need to make a new SerializedObject from the asset and all done

visual stag
#

Btw @barren moat I just did:

patent pebble
#

neat 😊

visual stag
#

It's nice when the names are not completely generated from code so they're easy to find

barren moat
#

Or is that actually distributed with the engine?

visual stag
#

Yes, the source (pinned to the channel)

#

They added the up to date versions not long ago so it's back to being accurate 🙂

barren moat
#

awesome

patent pebble
#

@visual stag what's TrTextContent used for? I've never seen it before

#

what's the difference between that and a regular GUIContent constructor?

#

aaaah it's for Editor localization, i see i see

barren moat
#

Should I include meta files in my package's Samples~ folder?

#

(in this case it's just a scene, so I don't need them for it to work)

#

nvm, the answer is yes

barren moat
#

I'm having trouble getting Unity to download my package with a specific revision:

An error occurred while resolving packages:
  Project has invalid dependencies:
    com.effortstar.effort-star-logo: Version 'git@github.com:EffortStar/effort-star-logo-unity.git#v1.0.0' is invalid. Expected one of: a 'SemVer' compatible value; a value starting with 'file:'; a Git URL starting with 'git:' or 'git+', or ending with '.git'.

A re-import of the project may be required to fix the issue or a manual modification of C:/Users/rhysv/Projects/bridge-knight/Packages/manifest.json file.
#

Is it possible to provide a revision while using the git@foo.git protocol?

#

If I do simply:

    "com.effortstar.effort-star-logo": "git@github.com:EffortStar/effort-star-logo-unity.git",

It works.

visual stag
#

I've not seen the git@ syntax

#

"https://github.com/EffortStar/effort-star-logo-unity.git#v1.0.0" should work

barren moat
#

https fails

visual stag
#

well, if it existed

barren moat
#

git@ is SSH

#

It does exist

#

For whatever reason I can't use https validation on this project... Maybe I need to look in to how to authorize it via git-scm.

#

tbh I'm a little confused about keys etc. in windows

visual stag
#

I've not seen private git repos in UPM, is that a thing now?

barren moat
#

It's not to do with UPM, UPM just pulls from git

#

UPM is blind to authentication, it will just tell you if git complains

#

The problem is that I don't know how to specify a revision while using SSH, and https doesn't work. I don't really know how to configure https.

visual stag
#

should be the same by the looks of it

barren moat
#

Evidently not

barren moat
visual stag
#

Perhaps try ssh://git@... ?

#

it could be UPM's parsing isn't very thorough 🤷

barren moat
#

You're right!

#
    "com.effortstar.effort-star-logo": "ssh://git@github.com/EffortStar/effort-star-logo-unity.git#v1.0.0",
#

🎉

visual stag
#

🎉

barren moat
#

you beautiful man

#

thank you

#

Now I can synchronise my cool new company logo between all of my projects

barren moat
#

Hmph, this is my first time working with a package that contains non-code assets. Could anyone advise a workflow for modifying assets? I have added it as a local dependency but I can't seem to push changes to the prefab from the scene.

visual stag
#

You will not be able to modify the package assets

barren moat
#

Ah, wait. I can.

#

I was mistaken.

#

Seems you can just modify them.

visual stag
#

Well, maybe you can, but it'll reset

barren moat
#

I don't think so? I can see changes in git.

visual stag
#

If you're just talking about authoring them, that will work fine

#

I was thinking you meant once you intended to use it in a project 😄

barren moat
#

Yeah, well a bit of both.

#

My intention is to sync changes between two projects.

#

So... copy scene from Samples~, then if I need to add stuff I can use the local clone of the repo as a file system dependency and modify it that way.

#

I thought it wasn't working but apparently I was confused.

#

so all good!

visual stag
#

Should work fine, as long as you're just working with local packages it sounds appropriate 👍

barren moat
#

The confusing part is that Samples~ is invisible so I need to rename it

#

But then also make sure anything that was copied out has refreshed GUIDs to avoid collisions

#

I probably should just not include the .meta file from the scene in this case I think.

#

Force unity to renew it on import.

visual stag
#

Yeah I think I had to do that at some point... but I can't remember what I was authoring so I'm just uselessly saying this lol

barren moat
#

all g

#

I'm mostly just vocalising my minor frustrations

gloomy chasm
#

Given a path or guid, is there a way to check if an asset exists for one of them?

patent pebble
#

you'll get an empty string from the first one

#

and an all 0 GUID from the second one

#

ah there's also this one AssetDatabase.AssetPathToGUID

#

that last one has a gotcha tho If the asset does not exist AssetPathToGUID will return nothing. However, recently deleted assets return a GUID until the Unity Editor is restarted.

patent pebble
#

i wonder if the other two have the same problem

#

not sure

gloomy chasm
#

They do

#

They all do the same thing basically

#

Right now I am using File.Exists. However that will break if an asset is deleted, and then one with the same name is create before the check happens.

#

I could get the meta file and read the GUID from that. But the code is in a semi hot path

patent pebble
#

hmmmm, that doesn't sound fun 😕

#

@gloomy chasm can you maybe use the FileSystemWatcher class? iirc it gives you notifications when stuff happens

gloomy chasm
#

In 2021 AssetpathToGUID has another param for whether to return deleted asset guids

#

I could store the guid/path of every deleted ScriptableObject (that is the only type I care about)

whole steppe
#

hi, im having technical difficulties upgrading my project to URP

#

i created URP asset, assigned it a 2d rendered. i then used that in project settings, upgraded all materials. but they were not upgraded? gave the camera the render as well

gloomy chasm
whole steppe
#

also. i deleted the default renderer

#

tho I do not believe that had anything to do with the problem. Only upgrading materials in scene worked. not in project. makes sence

patent pebble
#

How can I force the ProjectBrowser window to repaint?

#

I tried with the internal ResetViews() and with a plain EditorWindow.Repaint()

#

I'm trying to prevent this

#

the Project window doesn't repaint until I hover the mouse over it 😓

#

ah nevermind, fixed it with EditorApplication.delayCall

steady pilot
#

timeline editor question: is there a way to custom the context menu when right clicking the empty space on timeline window? Tried TimelineAction & MenuEntry, but they only affect right click menu on Tracks/Clips/Markers

visual stag
brisk turtle
#

Not sure this is the right channel, but what do I need to do to properly repaint the scene view? I'm making a custom renderer component and I have to play and stop the project to get it to update properly, even with [ExecuteAlways].

#

i tried this

view.Repaint();```
#

but it made it impossible to switch from the scene view when tabs were stacked

#

hmm maybe if i only call it once

gloomy chasm
brisk turtle
#

hmm this might work, might be wrong somewhere else. thank you.

gloomy chasm
#

Also, this sort of thing is how Unity does stuff internally too (using Resources.FindAllObjectsOfType to get windows).

brisk turtle
#

👍 ill keep it in mind

patent pebble
#

iirc SceneView has a RepaintAll() public static method too

teal estuary
#

i'm trying to create a GUILayout element for every item in my items list in my custom editor window, it doesn't seem to work :/

gloomy chasm
#

Also, the if (spawnAmount < itemList.Count) is redundant as spawnAmount will always be less then itemCount unless you are setting it somewhere else, in which case you are going to get some odd behavior I suspect.

teal estuary
#

i ended up resolving this, and basically my entire method was flawed 😄

gloomy chasm
#

Ah, well glad you got it working 🙂

teal estuary
#

this is my code now

#

new problem :/

#

managing to get the item buttons, but how do i make them all appear on screen in a grid pattern?

gloomy chasm
#

You will need to use Rects to do that, can't use GUILayout

#

At least not nicely

teal estuary
#

ah

#

can you link documentation on it?

gloomy chasm
#

There isn't any

teal estuary
#

-oh

gloomy chasm
# teal estuary -oh

Here is the basic idea taken from some of my code

// In some method
_columnCount = Mathf.Max(1, Mathf.FloorToInt(viewportRect.width / ItemSize.x));

// else where
private Rect GetItemRect(int itemIndex)
{
  float row = Mathf.Floor(itemIndex / _columnCount);
  float column = itemIndex - (row * _columnCount);

  return new Rect()
  {
    x = ItemSize.x * column,
    y = ItemSize.y * row,
    width = ItemSize.x,
    height = ItemSize.y
   };
}
teal estuary
#

thank you! i'll try it out

do you mind if i dm you about this further if i have questions?

teal estuary
#

alrighty :)

wooden ocean
#

Not sure if we have any C# wizards in here, but struggling with dynamic dispatch on my baby editor extension. Wrote up the brief here: https://stackoverflow.com/questions/70523456/how-do-i-replace-a-switch-statement-over-an-enum-with-runtime-dynamic-type-based

subtle axle
#

Anybody ever have this problem with Odin Inspector?

#

Also, how can i change the background of a box in odin?

subtle axle
#

found [GuiColor] which seems to just add a colored box on top of the GUI instead of actually changing the color...

gloomy chasm
quartz nebula
# wooden ocean Not sure if we have any C# wizards in here, but struggling with dynamic dispatch...

At first glance, reflection might be what you're after. I'm not too knowledgeable about reflection, but you'll want to scan all loaded assemblies in the current appdomain, find the Type objects for types that implement/extend your interface (or even a custom attribute) and then invoke the method there. The latter is easy, something like GetType().GetMethod(nameof(IInterface.DoTheThing)).Invoke(null, myArgs)

quartz nebula
tawdry kraken
#

Hello. Is there an extension for tracking the time spent working on a project?
Or if not, any idea which handles could be useful to create such a feature?
Oh wow, I found one: https://wakatime.com/unity-time-tracking

kind linden
#

rmb export is broken, I want to export prefabs with what they use only. Not include everything that the prefab uses. Thus I have to write my own export....
Does someone has a good tutorial on how to create custom packages like that via c#?

brisk turtle
#

It seems a lot of these declarations that take a serializedObject are obsolete. So how are you supposed to do it then?

patent pebble
#

@brisk turtle there's EditorGUI.BeginProperty/EndProperty or EditorGUI.PropertyScope for controls that don't take in SerializedProperty parameters

#

or you can just assign the value manually

brisk turtle
#

@patent pebble ah yeah i see now the .intValue I can assign on the serializedProperty. thanks.

gloomy chasm
#

<@&502884371011731486> ^

onyx harness
gloomy chasm
#

LOL

young robin
#

I’m having trouble downloading the multiplayer tools. I followed the tutorial on there web site and I see the package in the packages folder but when I go to add the network components to a object I can t find them. Pls help. Never mind I downloaded multiplayer tools instead of netcode lol.

tough cairn
#

how to change current tool space ( Local / Global ) ?

patent pebble
#

pivotMode and pivotRotation

tough cairn
patent pebble
#

@tough cairn and in case you want to change the button to the right, the one that controls snapping

tough cairn
#

where does the package manager download the files to ?

#

From my assets when i press download before import

#

nvm found it C:\Users\%UserName%\AppData\Roaming\Unity\

tough cairn
#

.

i asked this before but never got an answer , any ideas how to force unity editor to avoid using the integrated GPU ( intel ) and use the Nvidia one only ?

#

i got this one setup

#

but it still seems to be using the first one

#

in the Nvidia control panel it points me to the windows "graphics settings"

#

would rly like to avoid disabling the intel graphics inside the device manager since i won't be able to use a second monitor

#

hmmm so i tried -gpu 1 but that didn't work

#

but when i add vulkan ... it seems to be ok 🤔

#

finally the editor no longer lags ...

cunning acorn
#

idk if its here to ask this type of question but how can i make the animation curve like that ?

#

nvm i found it just need to put the tangents to constant

zinc vessel
#

When using the graph view API, how do I add an objectfield to a node?

#

Nevermind, I was using the GUILayout object field when I should have been using the UnityEditor.UIElements object field

smoky jasper
#

I'm working on a 2D game using a Grid cell. There are specific data to set for some cells. Currently I have to manually set in the inspector these specific data and the associated cell coordinates (X & Y). It's not very user friendly to set the X and Y values. Is there a kind of "cell picker" to select the cell using a mouse click in the grid ?

tough cairn
#

u could do something like this :

    void OnSceneGUI()
    {
        for( var x = -3; x < 4; ++x )
        {
            for( var z = -3; z < 4; ++z )
            {
                var p = new Vector3( x, 0, z );
                if( Handles.Button( p, Quaternion.identity , 0.15f , 0.15f , Handles.SphereHandleCap ) )
                {
                    Debug.Log($"Selected {x},{z}");
                }
            }
        }
    }

which would look something like this

unkempt coyote
#

hi

#

Someone can show me some websites on you can edit your character in unity.Exist some websites like this?

wanton heath
#

Why is my ui broken?

zinc vessel
#

How do I set a graphview as a valid target for a drag and drop using the DragPerformEvent callback?

tired basalt
#

Anyone know how can I reset fbx import setting via script?

#

I want to remove the extracted material in the setting

#

I want to click this via code

#

basiclly

patent pebble
#

there's an internal method called ResetValues on the ModelImporterEditor class

tired basalt
#

So if I just want to reset setting for a specific fbx, how can I use that class to do it?

patent pebble
#

you'd probably need to use reflection to get the ModelImporterEditor that's being shown and then call that method

tired basalt
#

I have no idea about reflection but I will look into it

#

thx

patent pebble
#

it took me a while to get used to doing reflection stuff

#

maybe look for an alternative approach to resetting your importer values

tired basalt
#

Basically my issue is that I want to re extract material after it was extracted already

#

Not sure if there is any other way to do this

tired basalt
#

Also resetting them via UI also is very slow for some reasons

#

takes half minute for one

patent pebble
#

is [SerializeRefecence] completely broken with multi-object editing? (Unity 2020.3)

I'm making Editor UI to display polymorphic fields

for (int i = 0; i < _selectedProperties.Length; i++)
{
    ChangeReferenceType(_selectedProperties[i]);
}
#
private void ChangeReferenceType(SerializedProperty property)
{
    property.serializedObject.Update();
    {
        Type referencedType = DropdownUtility.GetTypesForDropdown(_fieldType)[_typeIndex];
        property.SetManagedReference(referencedType);
    }
    property.serializedObject.ApplyModifiedProperties());
}

public static object SetManagedReference(this SerializedProperty property, Type type)
{
    object obj = (type != null) ? Activator.CreateInstance(type) : null;
    property.managedReferenceValue = obj;
    return obj;
}
#

I've seen the extension that @visual stag made, but it didn't support lists or multi-object editing, so I started adapting my own version of it
I've gotten everything working except multi-object editing

#

my editor just explodes when doing the code above and crashes

#

sometimes it doesn't crash, but the SerializedProperties get all screwed and they don't behave correctly (reverting values, displaying mixed values even tho the value in all target objects is the same, etc)

visual stag
patent pebble
#

yeah putting the attribute on a collection

#
List<ISomeInterface> _someInterfaceList;
visual stag
#

TypeProvider supports collections

#

The DecoratorDrawerWithProperty won't. TypeProvider is not a decorator. The readme could be clearer on that fact

#

It's saying in the next sentence "If you have another use case similar to TypeProvider that requires collection elements, please let me know." that TypeProvider is an exception to that rule

patent pebble
#

ah crap, my bad then 😅

visual stag
#

It not working with multi-object editing though... that might be complicated 😓

patent pebble
#

there's a bunch of bugs I've seen people reporting

#

and it's very inconsistent, seems to be random sometimes

#

I guess for now I'll just display a "mixed value" content and skip drawing the property entirely if there's multiple objects selected

#

because the changes doesn't even affect the target objects based on selection order

visual stag
#

I should probably be doing the same

patent pebble
visual stag
#

2022.1.0a13 prints this

#

I don't know how else I would do it. Multi-property editing is still just done through one scriptable object and its properties is it not?

patent pebble
#

I've gotten similar errors in my implementation when doing multi-object edits
specifically in this particular case:

Target1 has a value of A
Target2 has a value of B
Target3 has a value of A

when the value of Target2 is changed from B to A while all 3 are selected, I get the "offset stack trace" error

patent pebble
# visual stag I don't know how else I would do it. Multi-property editing is still just done t...

yeah I've tried by using the property.serialize.targetObjects like so:

private void ChangeSelectedType(SerializedProperty property, Type newType)
{
    Object[] targets = property.serializedObject.targetObjects;
    for (int i = 0; i < targets.Length; i++)
    {
        SerializedObject serObj = new SerializedObject(targets[i]);

        serObj.Update();
        {
            SerializedProperty prop = serObj.FindProperty(property.name);
            prop.SetManagedReference(newType);
        }
        serObj.ApplyModifiedProperties();
    }
}
visual stag
#

Yeah, that might work. Seems a bit bizarre it's required though

patent pebble
#

1 sec, I'll share gif of what happens

#

@visual stag it almost feels like Unity is losing track of the SerializedProperties internally, or recreating them every time the managed reference value is changed or something

#

I don't have enough knowledge of the inner workings of Unity's serialization to really guess what's happening

#

when I re-select all the multiple gameobjects it does show correctly that the values are the same

#

so I guess when the editor does OnEnable it's syncing up again all the properties from the attribute drawer or something

visual stag
#

Yeah... it does the same thing here

#

at least that trick makes the multi-object editing for assigning the property work

patent pebble
#

"work"

#

when the editor doesn't explode

#

and sometimes it reverts the other selected objects to the previous value

#

and only retains in the currently inspected object

visual stag
#

I don't have any replication to make it explode here

patent pebble
#

I've read they fixed a bunch of bugs from 2020 to 2021

visual stag
#

2022, I will check the others soon

patent pebble
#

I'm currently only testing on 2020.3 because I only want to make tools for LTS versions

#

i guess SerializeReference is more stable on 2021 and 2022

visual stag
#

I do stuff on later versions because I'm selfish and don't care to support older versions until someone complains

#

I should hack to support old, not amend to support current 😄

patent pebble
#

well... I guess SerializeReference is still "in the oven"

#

hopefully they figure this one out soon and make it better

#

polymorphism has such potential for Unity

#

it'd be a shame if they left it half baked

visual stag
#

They've been pretty aggressive in fixing it, it's just that there seems to be a lot of bugs

patent pebble
#

yeah, I guess their serialization system wasn't robust enough to support all the new stuff they want to make

#

i haven't been keeping track of the roadmaps and the version notes

#

so I don't really know how it's going

#

I've been digging through this discord channel and a lot of you guys usually recommend only using SerializeReference for simple things for now

#

just to be safe

visual stag
#

yeah, even if the reliability has gone up in recent versions, I've not yet tested it enough to know you wouldn't hit an unsolvable wall

visual stag
#

it's a pity that hasMultipleDifferentValues is always true

#

even if the types are the same

#

so the only way to find out whether I should show a mixed field would be to make all the serialized properties and check their types

#

which is not reasonable on allocations

patent pebble
#

it's not for me

visual stag
#

It is for me, if I have two that share the same type then it's true

patent pebble
#

it's always false for me

#

😓

visual stag
#

Might be a version difference

patent pebble
#

probably

patent pebble
# visual stag so the only way to find out whether I should show a mixed field would be to make...

yeah I was doing this on my tests

public static bool HasMultipleManagedReferenceTypes(this SerializedProperty property)
{
    if (property.serializedObject.isEditingMultipleObjects == false)
    {
        return false;
    }

    Type inspectedType = GetManagedReferenceType(property);

    for (int i = 0; i < property.serializedObject.targetObjects.Length; i++)
    {
        SerializedObject serObj = new SerializedObject(property.serializedObject.targetObjects[i]);
        SerializedProperty prop = serObj.FindProperty(property.name);
        Type otherType = GetManagedReferenceType(prop);

        if (inspectedType != otherType)
        {
            return true;
        }
    }

    return false;
}
#

felt super hacky doing that, but I just wanted to see if multi-editing was even possible

visual stag
#

I might do some fancy caching with something similar

patent pebble
#

yah, seems fairly doable to cache things on user interaction, on selection change, etc

gloomy chasm
#

Hey, random thing that I assume the answer is no to. But is there a way to apply a shader to what is drawn in OnGUI?

patent pebble
gloomy chasm
patent pebble
#

ah

#

I've always wondered that

gloomy chasm
#

What I am trying to do is to isolate and only render certain controls.

patent pebble
#

I've wanted to do fancy animations and stuff with IMGUI controls if it's possible

patent pebble
#

very bad solution lol 😅

gloomy chasm
#

That is what I have done as well. I was thinking I could use a shader to 'collapse' the UI in the parts I don't care about, but that isn't possible it seems. My other idea was to see if I could get it to render to a scene and capture it with a camera

patent pebble
#

i've just accepted the reality that I have to play by Unity's rules most of the time

patent pebble
#

but yeah doing weird shit with the Editor is fun tho

gloomy chasm
patent pebble
#

Mikilo has done a bunch of cool stuff too

#

i haven't gone so deep into making extensions and stuff

#

I'm mostly still learning

gloomy chasm
#

Yeah, he has

gloomy chasm
patent pebble
#

this whole editor stuff feels like there's infinite topics to learn

#

I started like 1 year ago and my objective was to learn everything I could related to making tools and editor extensions

#

"it won't take me more than a couple months, surely" 🤡

#

I'm almost "done" learning to an acceptable level of competency that enables me to make mostly any tool I need for my game projects

#

most of the stuff I have yet to get into is related to Assets, Packages, Prefabs, Previews and similar things

tired basalt
#

For some reason my script is really slow

karmic ginkgo
#

@gloomy chasm

scriptableobject variants
where

#

repo

tired basalt
#

This is taking for ever

#

It seems like hot reload is the issue

#

Anyone know what hotreload is and how can I fix it?

warm pendant
#

Moin, Im working on a project for which Im writing an editor extension that allows me to adjust some sound settings individually per sound. Does anybody know where I could find some resources on how to implement the Unity functionality for the rollof settings into my own objects? Ideally I just need to mimic the editor 3d sound settings and pass that data into the player when the sound is called. If that does not work do you know any resources where I could look at how they made the rollof curves etc internally? Would really appreciate some ideas where to start with this.

smoky jasper
#

Hello. I have a 2D sprite "Arrow". Depending on an inspector parameter (an enum [up, down, left, right]), the animation used to render the Arrow sprite in PLAY mode will be different (Up anim, Down anim, Left anim, Right anim). I would like to display the first frame of the anim in EDIT mode. Is it possible ?

gloomy chasm
gloomy chasm
karmic ginkgo
#

i do indeed, want to make sure its odin compatible as well

gloomy chasm
smoky jasper
#

In an editor script i'm trying to load a sprite by its name using AssetDatabase.FindAssets("LevelSpriteSheet_3"). The problem is that "LevelSpriteSheet" is a texture containing multiple sprites and AssetDatabase.FindAssets("LevelSpriteSheet_3") returns the first sprite instead of the third...

reef canopy
#

can i ask something?
when i try to enter in playmode my unity freeze
and my unity Memory start rising to 2gb on task manager
when my physical memory goes 99% my unit star to freeze
you cant do anything except shut it down
any body here can help me to fix this problem?

tired basalt
#

This is the unity editor.log

#

And hot reload is in there

gloomy chasm
tired basalt
#

This is an editor script so idk if that works

gloomy chasm
tired basalt
#

OK Thx I will give it a try

visual stag
gloomy chasm
visual stag
#

Anything that involves asset importing

#

I should probably have looked up what extract asset was before recommending it lol

gloomy chasm
visual stag
#

Ah it's what I thought it was, yes this is important

gloomy chasm
#

Hey, do you happen to know a way to save a single asset by chance?

visual stag
#

"save"?

gloomy chasm
#

Write to disk

visual stag
#

I don't know what you mean. CreateAsset is not it?

gloomy chasm
#

AssetDatabase.SaveAssets() but a single asset instead of all dirty assets

visual stag
#

I think ImportAsset might be that?

#

Honestly it's been a while

patent pebble
#

@visual stag it seems like i was able to make multi-object editing work with SerializeReference by "rebuilding" the inspector after I change multi-selected property values

#

i've been testing a little bit on fresh projects and it seems like they don't explode

#

I still don't fully trust it, but it's a step forward

gloomy chasm
tough cairn
#

im having trouble saving changes to a list , what im doing is :

public override void OnInspectorGUI() 
{
  var script = (XRArmature) target ;
...

  if( GUILayout.Button("Add") )
  {
        script.armatures.Add( ... );
        serializedObject.Update();
        Undo.RecordObject( script , "add" );
  }
#

so im guessing setting script.armatures[ i ] = value ( where armatures is List<T>

#

is not enough too call serializedObject.Update(); ?

#

the problem is that i try edit the component data inside a prefab scene view , it works ok while in that view but when i exit and enter the prefab again the changes are lost

#

ok i think i got it :

int index = script.armatures.Count;
serializedObject.FindProperty("armatures").InsertArrayElementAtIndex(index);
serializedObject.ApplyModifiedProperties();
script.armatures[index] = script.NewArmature( newPoseName );
serializedObject.ApplyModifiedProperties();
Undo.RecordObject( script , "new armature" );
tough cairn
#

List.Add

#

in Editor : OnInspectorGUI

gloomy chasm
#
serializedObject.FindProperty("armatures").arraySize++
tough cairn
#

then can i call list.Add ?

#

or script.armatures[index] = ...

gloomy chasm
#

No, that is list.add

#
var elementProperty = serializedObject.FindProperty("armatures").GetArrayElementAtIndex(index);
// Set values on elementProperty here...
tough cairn
#

im getting out of range error when i use arraySize ++ ( in that last line where i set [ index ] = ... )

#
int index = script.armatures.Count;
serializedObject.FindProperty("armatures").arraySize ++ ;
script.armatures[index] = script.NewArmature( newPoseName );
patent pebble
tough cairn
#

so basically its the same as InsertArrayElementAtIndex( lenght - 1 )

#

in any case this is a bit odd

#

how do i modify existing array element then ?

#

GetArrayElementAtIndex needs UnityEngine.Object but my type isn't

#

i just been doing this script.armatures[index] = value

#

which kinda works ...

gloomy chasm
tough cairn
#

target

#

var script = ( MyMonoType ) target ;

#

is there a way to save prefab ? my script will modify linked transforms positions from that editor component

#

while inside the prefab scene view

gloomy chasm
tough cairn
#

target.list<DataType> where DataType is not Unity.Object

gloomy chasm
tough cairn
#

[System.Serializable] public struct Armature ... not an Unity.Object *

gloomy chasm
#

So to access those serialized fields you use SerializedObject which is the UnityEngine.Object that the field is on.

#

And you use SerializedProperty to access every field and subfield of that UnityEngine.Object

tough cairn
#

i see

gloomy chasm
#
var vector3Property = serializedObject.FindProperty("myVector3Field");
// We now edit the value of the vector3
vector3Property.vector3Value = Vector3.zero`
tough cairn
#

yep i been using it like this

#

vector3Value has get and set

#

it has good support for a range of types

#

but not custom types

#

im not using EditorGUILayout.PropertyField as i don't want to draw it like the way it does

gloomy chasm
#
var customProeprty = serializedObject.FindProperty("myCustomClassField");
// This is a custom class, what do we do, there is no .value for this!?
// We get the field that Unity knows how to serialize! :D
var customFloat = customProperty.FindReletiveProperty("myFloatInMyClass");
customFloat.floatValue = 42;
tough cairn
#

that's sort of what i have so far

tough cairn
#

but it gets a bit ugly when working with lists

gloomy chasm
#

However there is a benefit! It actually supports prefab overrides.

tough cairn
#

T_T

#

i need that

#

but its already too far to change

gloomy chasm
tough cairn
#

guess ill just apply prefab changes ...

rustic warren
#

I'm trying to make a custom editor for Unity
I want to be able to create drawings with 3 colors within the editor
Any suggestions into what I should look into? Unity has so many different custom libraries for editor GUIs.

tough cairn
#

drawings with 3 colors ?

gloomy chasm
rustic warren
#

Yeah I'm trying to make like a heatmap within the editor

tough cairn
#

gizmos ?

tough cairn
#

or just EditorGUI.DrawPreviewTexture ?

gloomy chasm
tough cairn
#

huh

#

oh right he wanted a heat map

#

@gloomy chasm u gonna hate this

#

that's the only place i use serializedObject " properly "

gloomy chasm
# tough cairn

Most EditorGUILayout controls take a serializedProperty as a parameter instead of the value type

#

Also, your code would look a lot cleaner if you just reused the properties instead of getting them twice (and have better performance) 😛

tough cairn
#

yes but this whole mess makes this pretty GUI

tough cairn
gloomy chasm
tough cairn
#

actually i have a diff kind of problem

#

when the code base is not self contained i have troouble reading it

#

when its clean its harder for me to read it

#

im a bit dyslexic

#

🙃

rustic warren
#

Thanks for the info

#

I'm trying to make a super complicated hardware related SDK

gloomy chasm
gloomy chasm
tough cairn
#

ahaha i know u love it

smoky plover
#

How to verticalize my split view?

smoky jasper
#

Is there a way to display the 2D grid cell mouse position in a window or a footer of the unity interface ?

pallid flax
#

What plugins are good for beginners

smoky plover
#

I don't see any orientation

gloomy chasm
fickle quarry
#

Cant seem to get prebuild scene editing to work.
Using 2020.3LTS and the error is in the screenshot below. Building for Android
Here is my code:

using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;

public class SceneStuff : IProcessSceneWithReport
{
    public int callbackOrder { get { return 0; } }

    public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report)
    {
        foreach (var obj in scene.GetRootGameObjects())
        {
            var mr = obj.GetComponent<UnityEngine.MeshRenderer>();
            if (mr)
            {
                mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                mr.receiveGI = UnityEngine.ReceiveGI.LightProbes;
                mr.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
            }
        }
    }
}
gloomy chasm
smoky plover
#

how to use?

smoky plover
#

this is the class definition

gloomy chasm
fickle quarry
#

Ah, nope, will do that right away

gloomy chasm
#

That code will not be included in builds

fickle quarry
#

Yep got it, forgot to do so in frustration with other issues haha

#

Building now, thanks!

smoky jasper
#

In game, to retrieve the cell under the mouse pointer, I do:
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(mousePosition);
mouseWorldPosition.z = 0;
cellPosition = grid.WorldToCell(mouseWorldPosition);
In editor, from an EditorWindow, to retrieve the cell under the mouse pointer, I do:
Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Event.current.mousePosition);
mouseWorldPosition.z = 0;
cellPosition = grid.WorldToCell(mouseWorldPosition);
The result is ok in game but not in editor. Could you please tell me what is wrong ?

smoky jasper
#

Thanks a lot @gloomy chasm 🙂

patent pebble
#

welp, SerializedProperty.isArray is giving me some weird results

#
public static List<SerializedProperty> GetAllArrayProperties(this SerializedObject serObj)
{
    SerializedProperty iterator = serObj.GetIterator();
    List<SerializedProperty> arrayProps = new List<SerializedProperty>();

    while (iterator.NextVisible(true))
    {
        if (iterator.isArray)
        {
            arrayProps.Add(iterator.Copy());
            Debug.Log($"Array property found: {arrayProps.ElementAt(arrayProps.Count -1).propertyPath}");
        }
    }

    return arrayProps;
}
#

I'm getting the arrays and also the elements of the arrays

#

is there a way to get only the properties that are arrays?

#

hmmm is it detecting the string properties as char[] ? 🤔

gloomy chasm
#

Try with just like float arrays or something

patent pebble
#

so how do I go about getting only actual array properties?

gloomy chasm
#

iterator.isArray && iterator.propertyType != PropertyType.StringValue

#

Or something like that

patent pebble
#

any other property type that becomes an array internally?

#

maybe Vectors?

#

maybe Rects too?

patent pebble
#

seems like doing this I can get arrays properly

if (iterator.propertyType == SerializedPropertyType.Generic && iterator.isArray)
{
}
#

I don't know if this can have other side effects, if anybody knows what things I should look out for when doing this please do tell! 😊

tough cairn
#

Getting an asset import warning , nothing seems broken but that's bugs me a lil bit , any tips how to get rid of it ?

Importer(NativeFormatImporter) generated inconsistent result for asset(guid:bc0d75b32f0525842a5d32ee1281a78f) "Assets/XR/Settings/OpenXR Package Settings.asset"
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler ()
patent pebble
#

Is there anything like OnDisable but for a PropertyDrawer?

patent pebble
gloomy chasm
tough cairn
patent pebble
# gloomy chasm What do you need to do?

I'm making a PropertyDrawer for fields that have [SerializeReference]
To support multiselection and all that stuff with lists i subscribe to the OnSelect and OnReorder events of all the ReorderableLists that are currently in the inspector when the PropertyDrawer gets constructed
What I need is a way to safely unsubscribe from those events as the inspector switches the inspected target to a different one

#

Because right now the event subscriptions keep polluting the code and I get many calls to the events

#

So i get a bunch of errors due to SerializedProperties and SerializedObjects being disposed and null

#

and that's... not fun 😓

#

i thought of using the Selection.selectionChanged event, but it won't work because it breaks when there's multiple inspectors

gloomy chasm
patent pebble
# gloomy chasm Does it through any errors or anything?

yes I get errors due to this:

  • Events get called once, I do what I need to do (reorder properties, etc)
    -Then I "rebuild" the inspector window, which disposes of all the SerializedProperties
    -Then the event gets called again and starts throwing errors because the references to the previous SerializedProperties are disposed
#

it doesn't break tho

gloomy chasm
patent pebble
#

is there any way to force the Editor to do garbage collection?

#

i think that could maybe work too

patent pebble
smoky plover
#

the code inside the Editor folder is ignored when building or I have to add the preprocessors if UNITYEDITOR?

icy merlin
#

If you're not using AssemblyDefinitionFiles, code in editor folders will automatically be put in a different editor-only assembly so you don't need UNITYEDITOR guards.

#

If you are using AssemblyDefinitionFiles, you'll either need to set up different assemblies for your editor-only code or guard it with #ifs.

smoky plover
#

with AssemblyDefinitionFiles you mean dll?

icy merlin
#

No, I mean .asmdef files. If you don't have any of those in the folders above your script file, you're not using them.

smoky plover
#

ok, thx. I never used it.

icy merlin
#

They're worth looking at if you ever start to feel like script compilation is taking an annoying amount of time, though they do need some additional planning and organisation to use.

smoky plover
#

and they have nothing to do with namespace right?

icy merlin
#

That's right, they're unrelated.

smoky plover
#

I'm reading the unity doc, they needs to group scripts and so when you change one script the recompile process takes only the groups with atleast one modified script

icy merlin
#

Yep, that's pretty much it. So for larger projects where recompiling every script would take ages they can be a significant time saving.

short prawn
#

Anyone know how I can select a folder in the project window, currently using this which does not work, but it seems to work fine for an individual file:

UnityEngine.Object obj = AssetDatabase.LoadMainAssetAtPath(EditorStaticStuff.BuildToolsSettingsLocation);

                Selection.activeObject = obj;
icy merlin
#

Google suggests that LoadAssetAtPath should work? Folders are weird, it's possible that they don't have a "main" asset.

#

(Folders should be of type UnityEditor.DefaultAsset for the purposes of that method.)

short prawn
short prawn
short prawn
icy merlin
short prawn
#

That's what I started with

#

That exact thread is already open lol

icy merlin
#

(But folders are definitely DefaultAssets, so that should work too.)

#

Weird; maybe it changed, maybe it never actually worked for them either.

#

Or maybe it's something really weird like "Unity only creates DefaultAssets for folders when they're selected".

short prawn
#

uugh ffs, now it's working copying that exact snippet.

#

When it didn't before, so I might mark this as "i dont know why but it does now so stop touching it"

patent pebble
#

@short prawn the code snippet you posted above works for me

#

it selects folders just fine

short prawn
#

w h a t

patent pebble
#

@short prawn are you sure your path is correct?
debug it and paste it here

#

maybe you're using the wrong formatting or something

short prawn
#

Yep, 100% sure the path is correct. Like I say it's working now so I'm going to leave it and move on, spent too long on this stupid tiny thing that only helps me not dive like 7 folders deep

#

Thanks @patent pebble though, appreciate it

patent pebble
#

Maybe a bug, or maybe you had something else changing selections, or maybe your code wasn't recompiled

#

I've had a couple of times where my code doesn't get recompiled correctly even if looks like Unity did recompile it

sharp breach
#

Hey hi! I dont know where to post this but seems editor related.
Any recommendations on how can i get some kind of flag/sticky note over an object with a string?
Its mainly to see on the scene the name of an object

patent pebble
#

@sharp breach this channel is for making editor extensions. For basic Editor functionality there's #💻┃unity-talk

smoky plover
#

How to change the color of a VisualElement?
I use style.backgroundColor but it adds the color, I want to replace it.
I'm trying with MarkDirtyRepaint(); but doesn't seems to work

#

ok, solved

#

i was using MarkDirtyRepaint(); in the wrong way

light hearth
#

I'm trying to make some simple logic where different variables show up in the inspector depending on the value of an enum.

#
[CustomEditor(typeof(PassiveEffectDataContainer)), CanEditMultipleObjects]
public class PassiveEffectEditor : Editor
{
    public SerializedProperty
        PassiveEffectType,
        StatModifiers,
        StatModifierThresholdMin,
        StatModifierThresholdMax,
        TakeDamageOnAttackValue;
    void OnEnable() {
        PassiveEffectType = serializedObject.FindProperty("PassiveEffectType");
        StatModifiers = serializedObject.FindProperty("StatModifiers");
        StatModifierThresholdMin = serializedObject.FindProperty("StatModifierThresholdMin");
        StatModifierThresholdMax = serializedObject.FindProperty("StatModifierThresholdMax");
        TakeDamageOnAttackValue = serializedObject.FindProperty("TakeDamageOnAttackValue");
    }
    public override void OnInspectorGUI() {
        serializedObject.Update();
        EditorGUILayout.PropertyField(PassiveEffectType);
        PassiveEffectDataContainer.EffectType type = (PassiveEffectDataContainer.EffectType)PassiveEffectType.enumValueIndex;
        switch (type) {
            case PassiveEffectDataContainer.EffectType.StatModifiersAtHealthThreshold:
                EditorGUILayout.PropertyField(StatModifiers, new GUIContent("StatModifiers"));
                EditorGUILayout.Slider(StatModifierThresholdMin, 0f, 1f, new GUIContent("HealthThresholdMin"));
                EditorGUILayout.Slider(StatModifierThresholdMax, 0f, 1f, new GUIContent("HealthThresholdMax"));
                break;
            case PassiveEffectDataContainer.EffectType.StatModifiers:
                EditorGUILayout.PropertyField(StatModifiers, new GUIContent("StatModifiers"));
                break;
            case PassiveEffectDataContainer.EffectType.TakeDamageOnAttack:
                EditorGUILayout.PropertyField(TakeDamageOnAttackValue, new GUIContent("SelfInflictedDamage"));
                break;

        }
        serializedObject.ApplyModifiedProperties();
    }
}
#

However, all variables show up no matter what the "PassiveEffectType" enum is set to.

#

Is anyone able to see where the error might be?

mellow oar
light hearth
icy merlin
mellow oar
light hearth
#

I'll try that thanks

#

No it seems to be using the default editor.

#

Since breakpoints arent being triggered

#

Here's the class who's inspector I want to change

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class PassiveEffectDataContainer
{
    public enum EffectType
    {
        StatModifiersAtHealthThreshold,
        StatModifiers,
        TakeDamageOnAttack
    }
    public EffectType PassiveEffectType;

    // Statmodifier
    public StatModifierContainer[] StatModifiers;
    [Range(0, 1)] public float thresholdMin;
    [Range(0, 1)] public float thresholdMax;

    // Take Damage on attack
    public int DamageTaken;
}
#

(Or rather, a scriptable object referencing this class).

icy merlin
light hearth
#

Unless I use property drawers then.

#

I'll look into it, thanks

icy merlin
#

If you're only using it in specific classes, you could write editors for those classes and share a method to draw the common part. But yes, property drawers are the only way to have it "just work" in any class that includes the type.

west drum
#

Does anyone know a good tutorial to create custom UIElement controls? I would like to make my own UXML control.

#

(not using the builder)

median geode
#

Hiya, this is probably a dumb question (dumb for doing it, not dumb thing to ask haha) but does anybody know where the actual file that using UnityEngine.Tilemaps; file is located on a normal install? I'm trying to make a 'Sprinkle Fill' tool for the tile palette. I've been looking for like an hour now and good 'ol google hasn't been able to help much, Thanks!!!

lilac pendant
#

why are you looking for that?

gloomy chasm
#

If it is you can just access it in the Project Browser

glass hatch
#

hi all, i am using a scriptableobject framework. however, when i launch the game in runtime mode, there is a "type mismatch". on the top right corner. may i know what could be causing this?

waxen sandal
#

Sounds like a broken editor class

glass hatch
#

anything i can do to fix it?

tepid light
#

Hi guys, sorry if this isn't the place for this, but not sure who else to ask!
A super simple 2D scene is giving me a framerate of ~25 fps.
BUT if I close the scene window, it shoots up to ~120 fps.
And if I maximise on play i'm getting 250 fps+ !

Anybody else had this issue? I can't dev if I have to fullscreen every time or close the scene window! This unity version is a real mess on mac 😢
I'm on mac, 2020.3.25f1 LTS (but issue exists on all 2020.3 LTS)

jaunty nova
#

@west fog owo who's this

jaunty nova
#

Hey,

cobalt oxide
#

Hello! Does anybody knows how to fix A* NullReferenceException: Object reference not set to an instance of an object error?

jaunty nova
#

Hey,

//in SceneView duringGui
 if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
{
    currentEvent.Use();
}

It seems a left click into the scene view, even used using Event.Use() in a Scene GUI callback will register and select an item.

#

The straightforward way is to just use the right click instead, but since that interferes with rotation, I have to ask if there's a way to prevent this behavior.

waxen sandal
#

No

gloomy chasm
#

Yes, but it isn't fun/nice

#

You can register a event callback on the SceneView UIToolkit Visual Element that uses the mouse input before it gets to the scene view if memory serves

jaunty nova
#

Oh, that is a very interesting method

#

And seems to be straightforward too, in fact, if a little violating of POLA

tardy pecan
#

yo! I'm trying to set the position/size of a button in UIElements for an editor extension, but when I change it in the style it doesn't update, anyone knows why?

#
{
    private Button _button;
    
    public override void SetPosition(float x, float y)
    {
        _button.style.position = Position.Absolute;
        _button.style.left = X;
        _button.style.top = Y;
    }

    public override void SetSize(float width, float height)
    {
        _button.style.width = Width;
        _button.style.height = Height;
    }

    public EditorGridButton()
    {
        _button = new Button();
        Add(_button);
    }
}```
tardy pecan
#

Ok nvm, now only the height is not working for some reason (width is working)

gloomy chasm
#

Are file ids unique?

#

Particularly for subassets. I believe the answer is yes, but would be nice if someone who is more familiar with them could confirm it for me.

surreal agate
#

How do i make visual studio not show me exceptions thrown during a try?

smoky jasper
gloomy chasm
#

You are getting a references to itself

smoky jasper
#

Because I need to set the win variable to a static variable

gloomy chasm
#

It is most likely creating a new window because it has not been registered fully sometimes in the C++ end and so GetWindow can't find it so creates a new one

smoky jasper
#

If i don't "update" the win value in the onenable it is lost when I switch from visual studio to unity

gloomy chasm
#

That is my guess at least

gloomy chasm
smoky jasper
#

ok I try this

#

It seems to work and indeed I should not have this problem without a call to GetWindow.

#

Thanks 🙂

fleet token
#

So, I'm trying to make a PropertyDrawer for a class (class A<>). Thing is, this class is generic, so it can't be serialized. So I make a second class that extends from A, but specifies the type (class B : A<bool>). However, it seems like I cannot FindPropertyRelative for fields that are originally on A? Is that correct? Any way to get around that?

gloomy chasm
#

Also, you should be able find the properties of the base class just fine

fleet token
#

Well, It looks like I'm using 2021.1

#

So maybe my error is in another place?

#

And yeah, it looks like I was reading an old version of the documentation

eternal sapphire
#

is there a way to disable / hide the grid in the animation preview window?

patent pebble
#

I'm curious, what issues do they have?

#

I haven't extensively tested their implementations, but I'm making my own just for learning purposes

#

@stiff vine what version of Unity are you using? Keep in mind the [SerializeReference] attribute is still sort of unstable and still has a bunch of bugs

#

I feel like the issues you described may be more related to Unity's implementation of the SerializeReference stuff and how it integrates with the serialization system
because the drawers from vertx's and mackysoft's are fairly simple and are mostly just UI

#

i'm not an expert on the topic, so take it with a grain of salt

#

it has certain limitations "by design"

#

i've seen a lot of people who frequent this channel advice against using SerializeReference in production pipelines unless it's for something very simple

#

for now I just use it for experimentation and learning projects

#

what are your needs exactly? just polymorphism?

visual stag
#

Can you tell me what version you're using and some example code? Because I've never seen this before and it doesn't really make sense afaik I'm not even drawing the properties, just appending a hacked property decorator

#

I do need to update the thing to be a bit more robust, but for basic usage it should just work

patent pebble
#

the only "battle-tested" solution I've heard people talk about is Odin, I've heard their serialization stuff is pretty good
haven't used it myself, so do some research before committing to it
I don't know if their stuff is modular or not, which may be a pain if you're forced to change your entire workflow just to get polymorphic serialization/UI

#

list<genericClass>
maybe that's related to this?

  • Field value cannot be a specific specialization of a generic type(inflated type).
#

just throwing stuff out there, might not be

#

well, what you're drawing is also the result of the serialization/deserialization process

#

so you have to make sure you're using it appropriately to make sure the serialization system handles the data correctly

visual stag
#

So the header displays twice? Huh

#

Only for list elements?

#

It appears fine where I'm looking, but maybe I don't have the specific setup right to cause it

#

So what's the issue that causes it?

patent pebble
#

ah, you're using NaughtyAttributes in your project?

#

if I remember correctly that completely overrides the way the default inspector stuff is drawn

#

as far as I can tell it mimics the default implementation

visual stag
#

Ah

#

Yeah that'll do it 😛

patent pebble
#

I had Naughty Attributes fuck up with my own tools before, so whenever I need to make a tool or test something I usually go to a clean project

visual stag
#

I'll think about the problem some more, it may or may not have solution...

#

I have absolutely no idea how subclassselector works or looks like

#

None of my use cases have such open type restrictions that that would be relevant

#

but I can think about adding it as an option

light hearth
#

I know that custom classes can't have a custom editor. But I have a scriptable object called AbilitySO that has a list of my custom class PassiveEffectDataContainer:

public enum PassiveEffectType
{
    StatModifiersAtHealthThreshold,
    StatModifiers,
    TakeDamageOnAttack
}
public class PassiveEffectDataContainer
{
    public PassiveEffectType EffectType;

    // Statmodifier
    public StatModifierContainer[] StatModifiers;
    [Range(0, 1)] public float thresholdMin;
    [Range(0, 1)] public float thresholdMax;

    // Take Damage on attack
    public int DamageTaken;
}

I want to show in the inspector different variables depending on the "EffectType" enum through my AbilitySO editor script. Anyone know how to do this?

#

An example of how I "want" it to work (but it obviously doesnt):

[CustomEditor(typeof(AbilitySO))]
public class AbilitySOEditor : Editor
{
    public AbilitySO ability;
    void OnEnable() {
        ability = (AbilitySO)target;
    }
    public override void OnInspectorGUI() {
        serializedObject.Update();
        EditorGUILayout.PropertyField(EffectType);
        foreach (PassiveEffectDataContainer effect in ability.PassiveEffects) {
            switch (effect.EffectType) {
                case PassiveEffectType.StatModifiersAtHealthThreshold:
                    EditorGUILayout.PropertyField(effect.StatModifiers, new GUIContent("StatModifiers"));
                    EditorGUILayout.Slider(effect.StatModifierThresholdMin, 0f, 1f, new GUIContent("HealthThresholdMin"));
                    EditorGUILayout.Slider(effect.StatModifierThresholdMax, 0f, 1f, new GUIContent("HealthThresholdMax"));
                    break;

                case PassiveEffectType.StatModifiers:
                    EditorGUILayout.PropertyField(effect.StatModifiers, new GUIContent("StatModifiers"));
                    break;

                case PassiveEffectType.TakeDamageOnAttack:
                    EditorGUILayout.PropertyField(effect.TakeDamageOnAttackValue, new GUIContent("SelfInflictedDamage"));
                    break;
            }
        }
        serializedObject.ApplyModifiedProperties();
    }
}
#

I guess the question I'm asking how to find a property field within a list?

visual stag
#

working hard or hardly working

visual stag
#

I think that's a problem with Unity, I don't specify the height of the property, just of the header

gloomy chasm
light hearth
gloomy chasm
light hearth
# gloomy chasm I see. What part don't you know how to do?

I have a list of PassiveEffectDataContainer (custom class referenced by a scriptable object). Each PassiveEffectDataContainer has an enum. When the value of the enum changes, i want the fields within the respective PassiveEffectDataContainer to show/hide different variables.

gloomy chasm
light hearth
gloomy chasm
#

Everything in Unity is serialized to a UnityEngine.Object (Components, GameObject, ScriptableObject, etc.). SerializedObject is basically a way to access the serialized data of a UnityEngine.Object.
SerializedProperty is the serialized equivalent of a field, or field of a field of that UnityEngine.Object.

#

So in a PropertyDrawer, the SerializedProperty that it gives you is the field on a UnityEngine.Object that is the type you specified

patent pebble
#

@light hearth a good way of thinking about it is: custom Editors draw for the entire inspector and Property Drawers draw for a field

#

so if you have a list like for example List<SomeCustomClass> and you make a Property Drawer for SomeCustoClass, every element of that list will use the property drawer to draw itself

light hearth
#

Thanks you people, those were some pretty great explanations 🙂

patent pebble
#

so like MechWarrior said, you can decide the logic of drawing however you want it to based on any of the contained SerializedProperties in your custom class

#

you need to know their names to find them

#

so you would do something like ``property.FindPropertyRelative("_myEnum");

visual stag
#

I've sorted a fix for this (I was trying make a fix for 2020+, but it appears like 2021+ is the best I can do). I'll likely make a release tomorrow if I can take a look at the namespace then too.
If you need the fix in the meantime you can try referencing the release branch from git https://github.com/vertxxyz/Vertx.Decorators/tree/release/v1.1.1

patent pebble
visual stag
#

Actually, I may have broke something in the release branch, so hold off on using it until I sort it tomorrow, it's late 😛

#

Wait that's just weird delayed unity stuff... it's fine 😓 I'm gonna sleep

#

SerializedReferences are a huge pain, that's all I can say

#

I think I see how this can happen, and it's the same deal with the nested property drawers. Another thing I'll note down to look at tomorrow

light hearth
#

Thanks for the help earlier! I almost got it working. It's usable, but I'd prefer it if the PassiveEffect fields appread below its respective PassiveEffect in the list of "PassiveEffects" in the inspector, instead of below. Is there a way to solve this?:

#

Here's the code: ```
using UnityEngine;
using UnityEditor;

[CustomPropertyDrawer(typeof(PassiveEffectDataContainer))]

public class PassiveEffectEditor : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {

    EditorGUI.BeginProperty(position, label, property);

    var indent = EditorGUI.indentLevel;
    EditorGUI.indentLevel = 0;

    var effectRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
    var secondRect = new Rect(position.x, position.y + 20f, position.width, EditorGUIUtility.singleLineHeight);

    var effectType = property.FindPropertyRelative("EffectType");
    var StatModifiers = property.FindPropertyRelative("StatModifiers");
    var StatModifierThresholdMin = property.FindPropertyRelative("thresholdMin");
    var StatModifierThresholdMax = property.FindPropertyRelative("thresholdMax");
    var TakeDamageOnAttackValue = property.FindPropertyRelative("SelfInflictedDamage");
#
        effectType.intValue = EditorGUI.Popup(effectRect, "EffectType", effectType.intValue, effectType.enumNames);
        switch ((PassiveEffectType)effectType.intValue) {
            case PassiveEffectType.StatModifiersAtHealthThreshold:
                EditorGUILayout.PropertyField(StatModifiers, new GUIContent("StatModifiers"));
                EditorGUILayout.Slider(StatModifierThresholdMin, 0f, 1f, new GUIContent("thresholdMin"));
                EditorGUILayout.Slider(StatModifierThresholdMax, 0f, 1f, new GUIContent("thresholdMax"));
                break;

            case PassiveEffectType.StatModifiers:
                EditorGUILayout.PropertyField(StatModifiers, new GUIContent("StatModifiers"));
                break;

            case PassiveEffectType.TakeDamageOnAttack:
                EditorGUILayout.PropertyField(TakeDamageOnAttackValue, new GUIContent("SelfInflictedDamage"));
                break;
        }
        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }

    //This will need to be adjusted based on what you are displaying
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
        return (20 - EditorGUIUtility.singleLineHeight) + (EditorGUIUtility.singleLineHeight * 2);
    }
}
fleet token
#

Any idea on why I could be getting this error on my propertydrawer? I believe I'm following pretty much exactly the documentation example

#

As additional info, I have a public array as another property of the Grid class that I does get found by FindPropertyRelative no problem. And of course, property.hasChildren returns true as well.

#

Ah, it seems the problem was the {get: set:}

#

weird

gloomy chasm
fleet token
#

learning moment i guess. wasn't even aware there was a difference between fields and properties and was using the terms interchangably

slim zinc
gloomy chasm
visual stag
#

@stiff vine I pushed an update to the package which is on OpenUPM, it should also add namespaces to the dropdown when relevant. Let me know if there's issues.

smoky jasper
#

Hello, very often I get the following error in the editor: Object reference not set to an instance of an object
UnityEditor.Graphs.Edge.WakeUp I have to restart unity to make it disapears for a while but it always come back. My unity version is 2020.3.23f1.

west drum
#

Hi fellas. I need some guidance, even if it is for a link to a tutorial. I want to create a settings window for a plugin of mine. I guess the most optimal place to have my settings would be in Project Settings as a separate entry, but I am even ok if it is a whole separate window.

I have no idea what to Google, to find help on this topic. Any hint or direction anyone can give me?

west drum
#

@gloomy chasm Thanks!

deep mulch
#

I've been trying to add some packages to my project, yet no matter what project I select, I get this error while importing. It's been getting really annoying, and none of the answers I've seen online have been fully answered (it seems). I've tried a few different solutions that I was able to find, but nothing has worked so far. Has anyone else had this error?

#

Hmmm, seems like closing my VSCode seemed to help, I hope this doesn't cause some errors later on.

molten sierra
#

Hi, is there an event in editor similar to OnValidate, but only fired when user finishes editing a field instead of firing whenever an input is received? (when they press Enter or unfocus the field)

tardy pecan
#

hi! if you're using UIElements, there is a method called RegisterCallbackOnValueChanged (name might be wrong but it's very similar)

#

so you can do
yourElement.RegisterCallbackOnValueChanged(x=>Debug.Log(x.newValue))

#

this will show the field value in the console

molten sierra
#

Thank you!!

tardy pecan
#

nw!

#

hey! Does anyone knows why all my custom property drawer would stop working? They're in an Editor folder and worked in other projects but for some reason they're not being detected or something

#

I believe all editor scripts stopped working actually

#

Except editor windows

patent pebble
#

Is there any event or anything that gets called BEFORE the AssetModificationProcessor.OnWillMoveAsset()?

#

I need to set Unity's selection just before that so it can handle the assets I need

gloomy chasm
patent pebble
#

@gloomy chasm i'm working on an asset processor that needs to keep track of the assets the user INTERACTS with in the project browser, because Unity's handling of selection is... weird
Sometimes the project browser doesn't follow the principle of "what-you-see-is-what-you-get" so it looks like selection is changing while it's actually no

#

example:

#

during that whole thing, the Selection did not change a single time

#

but because asset processors seem to rely on the ACTUAL selection I need to change it before it happens

gloomy chasm
gloomy chasm
patent pebble
#

i'm not sure if it relies on the selection or not... now that I think about it

gloomy chasm
#

It literally is just called when an asset is moved, this includes if you move the assets in the System file browser

patent pebble
#

hmmmm

#

I'm having trouble with moving assets when the drag starts on one of the subassets

#

1 sec, I'll post gif

#

i don't know how to tell Unity "hey, I need you to move both main assets"

#

so I guess I need a way to actually trick Unity into thinking I started the drag action from the main asset instead of the sub-asset

gloomy chasm
primal ore
patent pebble
#

I can live with it, I'm just wondering if it's possible to change it

patent pebble
#

Unity really does not like when assets get fiddled with outside of the editor

primal ore
#

Also you're selecting the orc07 and the Tree1 , so you're not selecting the same kind of files.

The tree1 you're selecting is the sub child of Tree1
Look closer at the gif you created.

patent pebble
#

yes, i know

gloomy chasm
#

If it is adding it to the dragAndDrop idk what to tell you. I guess you could try registering events with UITK, and cache when the mouse is up(I don't think the Drag events would fire, but you could try those too, and if files were moved, and compare that with the secltion?

patent pebble
#

hmmm

#

seems like this is gonna be tricky

#

maybe I can access the drag and drop paths internally before they get used, and modify them

#

similar to this

gloomy chasm
patent pebble
#

i think they do

#

yeah the .paths and .objectReferences seem to have that data

gloomy chasm
#

You can't just change what is being dragged though, you have to do it on drop because someone could be dragging the assets elsewhere

patent pebble
#

gonna try that approach, if it doesn't work I'll just accept my fate and surrender to Unity's way

#

i usually don't like modifying default editor behaviours... but the Project Browser and AssetDatabase stuff... it has so many weird little things that are just plain wrong

gloomy chasm
patent pebble
#

when you instinctively expect a logical behaviour

#

and it goes in the completely opposite way... because Unity i guess

gloomy chasm
#

Can you give an example? I personally have found it perfectly fine.

patent pebble
#

well that example with how dragging from subassets behaves inconsistently depending if you are dragging a single asset or dragging multiple assets

#

there's also some issues with dragging stuff in inspector lists

#

not related to the Project Browser but I suspect it has something to do with how they handle TreeView stuff internally

#

@gloomy chasm like...

#

what the hell is this monstrosity 😓

#

things randomly expand and collapse when doing reordering

gloomy chasm
patent pebble
#

I mean most of the bad stuff I've encountered is not a deal-breaker

#

but it's small things like that that make the user experience less enjoyable

#

I can't put my finger on them and list them all, but I've definitely found a bunch of them I don't like

#

another example, you can't drag assets into a folder if said folder already contains an asset with the same name

#

no UI to resolve conflicts, no notification letting you know what's happening, you just can't do the drag

#

once you get used to all these Unity quirks they're not a big deal, but still a lil annoying

gloomy chasm
#

Fair enough

patent pebble
#

ah! another one popped into mind, the INCONSISTENCY of undo/redo in the Project Window

#

you dragged an asset and a folder? can undo
you dragged an asset and a folder, but your action caused the folder/asset to get unparented? TOUGH LUCK, no undo for you 😠

#

I'm too nitpicky for my own good, that's why I often try to "fix" Unity's quirks when I do some simple tool for some mundane task

#

i guess I just need to accept my fate and start jumping through the hoops instead of walking around them 😢

idle tree
#

I'm getting into writing EditorWindow writing and want to edit prefabs from code.

            for (int i = 0; i < rooms.Count; i++)
            {
                //The code I want to do "right" eg use SerializedObjects/Properties
                rooms[i].doors = rooms[i].GetComponentsInChildren<Transition>();

                //Attempts to do that failed
                SerializedObject so_room = new UnityEditor.SerializedObject(rooms[i]);
                SerializedProperty sp_doors = so_room.FindProperty("doors");

                // this didn't work, SP can't Get Components
                sp_doors = so_room.GetComponentsInChildren<Transition>();

                //this didn't work, can't convert from transition[] to serialized property
                sp_doors = rooms[i].GetComponentsInChildren<Transition>();
            }```
How do I convert the first line to do the same thing but with SerializedProperty/SerialziedObjects?
gloomy chasm
#

Looks like you are close

idle tree
gloomy chasm
idle tree
#

This is tricky very unlike anything I am familiar with when it comes to getting and setting to variables in classes

gloomy chasm
idle tree
#

I see now why people have told me to just setDirty and directly edit the variables instead of doing it "right"

gloomy chasm
#

You almost have it. Using SerializedObjects and SerializedProperties can be a bit extra confusing when working with UnityEngine.Object fields.

idle tree
#
                SerializedObject so_thisRoom = new UnityEditor.SerializedObject(rooms[i]);
                SerializedProperty sp_doorsArray = so_thisRoom.FindProperty("doors");

                Transition[] roomsDoors = rooms[i].GetComponentsInChildren<Transition>();
                for (int i2 = 0; i2 < roomsDoors.Length; i2++)
                {
                    sp_doorsArray.arraySize += 1;
                    var thing = sp_doorsArray.GetArrayElementAtIndex(i2);
                    SerializedObject so_thing = new UnityEditor.SerializedObject(roomsDoors[i2]);
                    thing.objectReferenceValue = roomsDoors[i];
                }```
No errors, able to compile, test running this script now
gloomy chasm
#

There is no need to create a SerializedObject for the door.

for(..)
{
  sp_doorsArray.arraySize++;
  var thing = sp_doorsArray.GetArrayElementAtIndex(i2);
  thing.objectReferenceValue = roomsDoors[i];
}
idle tree
#

Hmm, nothing happens, no changes to the prefab in project

gloomy chasm
#

Make sure to do mySerializedObject.ApplyModifiedProperties();

#

Otherwise the changes will not be applied

idle tree
#
            for (int i = 0; i < rooms.Count; i++)
            {
                SerializedObject so_thisRoom = new UnityEditor.SerializedObject(rooms[i]);
                SerializedProperty sp_doorsArray = so_thisRoom.FindProperty("doors");

                Transition[] roomsDoors = rooms[i].GetComponentsInChildren<Transition>();
                for (int i2 = 0; i2 < roomsDoors.Length; i2++)
                {
                    sp_doorsArray.arraySize++;
                    var thing = sp_doorsArray.GetArrayElementAtIndex(i2);
                    thing.objectReferenceValue = roomsDoors[i];
                }
                so_thisRoom.ApplyModifiedProperties();

Getting very close now, this compiles and runs, the changes are made to the prefab, and Undo entries are made as well.

Minor bug is that right now for example, the expected output of Doors is Door 1, 2, and 3 in array slots 1, 2, and 3, but what I actually get is Door 3 is copied into array slots 1, 2, and 3, and as I undo them, I see that it copied door 1 into all 3 slots, then 2 into all 3 slots, then 3 into all 3 slots.

I think its happening because of the two nested for loops maybe I mixed up an [i] and [i2]

#

thing.objectReferenceValue = roomsDoors[i]; yup this one needed to be i2, now it behaves as expected 👍

idle tree
# gloomy chasm Make sure to do `mySerializedObject.ApplyModifiedProperties();`

I have a bug I am not sure how to solve.
Right now every time I check the rooms, it expands the list, duplicating everything.
I tired to write a Contains method to make sure it makes no duplicates, but failed to do so.
I realized I can just wipe out the list entirely and build a new one every time instead of duplicate checking, but I can't figure out how to "erase" the list

idle tree
idle tree
# gloomy chasm Set the array size to 0
                SerializedProperty sp_doorsArray = so_thisRoom.FindProperty("doors");
                sp_doorsArray = 0;```
I cannot set a serialized property to 0, and I cant set the original to 0 either because I can't make changes in code like that 🤔
gloomy chasm
idle tree
#

Oh, setting its.arraySize to 0 instead of the thing itself?

idle tree
gloomy chasm
#

(If that doesn't make more sense/help then don't worry about it)

idle tree
gloomy chasm
idle tree
# gloomy chasm Yeah, don't worry about it then. No sense getting more confused about something ...
    public static void PopulateArrayWithChildren<T>(GameObject parent, T[] array) where T : UnityEngine.Component
    {
        SerializedObject so_parent = new UnityEditor.SerializedObject(parent);
        SerializedProperty sp_childArray = so_parent.FindProperty(array); // requires a String

        sp_childArray.arraySize = 0;

        T[] validChildren = parent.GetComponentsInChildren<T>();
        for (int i = 0; i < validChildren.Length; i++)
        {
            sp_childArray.arraySize++;
            SerializedProperty thisChild = sp_childArray.GetArrayElementAtIndex(i);
            thisChild.objectReferenceValue = validChildren[i];
        }
        so_parent.ApplyModifiedProperties();
    }

I am refactoring my method out into a generic static method, but I hit a snag - FindProperty require a string and in a generic, the type and name would not necessarily be known.
I could add a string as part of the method argument, but is there a way to get its name from "T[] array" without doing that?

gloomy chasm
idle tree
gloomy chasm
idle tree
#

T is not Time in this circumstance

gloomy chasm
silent raptor
#

Hey, in the Button inspector there is a On Click() feature where you select a GameObject and it updates it's content with variables within the object. I'd want similar access to select any of my objects/classes and get variables values from the selection. How would one accomplish this? Not sure if the channel is correct, sorry if not.

gloomy chasm
idle tree
gloomy chasm
idle tree
gloomy chasm
idle tree
idle tree
#

"Does not exist in current context"

#

VS code's Alt+Enter sollution was to change it from public static to internal

gloomy chasm
idle tree
#

I dont know why it doesnt exist in the current context

#

is it maybe because I'm missing a using Something.Something?

gloomy chasm
# idle tree

Well in the first image it is because you are trying to call it when it is not in a method or Property

#

You can't run code just in the body of a class

idle tree
idle tree
#

here is the massive actual position of it

#

I was trying to avoid posting the entire thing but that didnt help obviously

gloomy chasm
gloomy chasm
idle tree
#

its giving me the error that PrefabEditing doesnt exist in the current context, and I have no idea why

gloomy chasm
#

Sorry, idk

idle tree
#

me either /shrug

#

Ill google around I guess

idle tree
# gloomy chasm Sorry, idk

I found the answer, it sounds dumb to me, but it was able to see it after I moved it to the same folder as the script I was trying to access it from. I don't know why project path matters but

gloomy chasm
#

Those scripts are compiled in to a different assembly

idle tree
#

oh actually in that case I moved the wrong one

#

PrefabEditing WAS in editor, its this EditorWindow that ISNT in Editor

idle tree
tough cairn
#

how to hide the localization thing ? ( that button below gizmos )

idle tree
#

I guess it couldnt find string array, but I passed in the correct name

slim zinc
tough cairn
#

is there an option in the editor ?

slim zinc
tough cairn
#

i got GUI debugging button there

idle tree
#

looks like there is a button in the top left under it

tough cairn
#

^

slim zinc
tough cairn
#

actually have 4 buttons on each corner

#

yea lol i could but i was wondering if its possible to hide that tho*

gloomy chasm
#

😉

tough cairn
#

👀

slim zinc
#

if you only need it few times, you can also use the visual element debuger to pick it and change it's appearance. move, hide, etc.... but it'll reset each time play mode is entered

slim zinc
tough cairn
#

ok never seen this one before , thanks @gloomy chasm

#

ooooo nice , now all of my buttons are working ! ( one of the btns stopped randomly working when that localization overlay appeared * and it wasn't the one under it )

idle tree
#

the null error occurs when sp_childArray.arraySize = 0; so maybe its not being initialized? But I don't know how to initialize an array.

#

Hm wait shit, I think its because I'm passing in a game object for the parent

gloomy chasm
#

^

idle tree
# gloomy chasm ^

All is now well 👍 Thanks a bunch couldn't have done it without you

lean barn
#

Not sure if this is the right channel to post this problem in because I'm new here, but when I try to use visual studio 2019 in unity, I don't get intellisense activated and the files are marked as miscellaneous. I've been surfing youtube and google and they all talk about enabling unity in the installation workload, or checking its connection in external tools, or browsing the files for visual studio, but I cant seem to get anything to work. However, I'm still able to change the C# scripts I want to edit with double clicking in unity and changing it luckily, I just simply want to have intellisense activated.

slim zinc
lean barn
#

where do i get those

pure glade
#

in the visual studio installer

#

i'm having the same issue, and i think i have all of them installed :I

lean barn
#

i have unity development pakcage installed, but theres no c# development package

pure glade
pure glade
lean barn
#

why do you get more installation details than me >:(

#

damn ive been having this issue sense 11:45 and now its 5:25

pure glade
#

ignore the c++ stuff on my screen, it has nothing to do with unity

#

but yeah, i have same dev package as u and same problem

lean barn
#

but da buttons 😳

#

pushy pushy

idle tree
#

https://youtu.be/c_3DXBrH-Is
I tried following this tutorial but I am completely stuck. The entire tutorial hinges on his data being a List<SomeClass> called "gameData"

        currentProperty = serialziedObject.FindProperty("gameData"); // this step I need to do my own properties instead of his properties?        
        DrawProperties(currentProperty, true);```
My data is not a list of classes that contain variables.
My data is a single scriptable object that contains variables.
I am not experienced enough to "just change his code to work for your use case" or whatever, can someone help me to fix this?
lean barn
#

3 peeps with 2 problems, we must wait for 1 savior

lean barn
pure glade
lean barn
#

ayo theres a forum? dang ill check it out

#

I found the issue, i had to check every single box in the generate section. i only had the top 2 selected. i wish all those youtube tutorials would say something about that

pure glade
#

dw, i was just trying to save my own

idle tree
#

How do I run DrawProperties on window.serializedObject?

#

the method that sets it is static, and whatever "thing" is being set there, I can't access it

#

I also cant in the same method store that object because its static

#

it has to be static

#

I need some way to carry over a reference between those two methods to the thing

#

hm wait maybe im dumb and this is easier than I thought

#

nope its not easier than I thought

idle tree