#↕️┃editor-extensions

1 messages · Page 89 of 1

gloomy chasm
#

I think there is a pinned video about them. And you can find a good number of tools on github that use it. And there is always the Shader Graph source code you can take a look at.

cosmic lintel
gloomy chasm
valid wharf
#

assigning my material to a custom inspector.
How do I show it's properties in the custom inpsector?

plucky nymph
#

So, need some help with a blocking point:
Im working on a property drawer, specifically one that renders a List<T>
To add to that list, I am using AdvancedDropdown. In order to add to the list on item selected, I created a delegate that was publicly accessible.

I found that if I tried to add to the list by assigning an inline method to the delegate, it didnt work. It would run, and call debugs etc, but it would never add to the list. I think this is due to the nature of SerializableObjects (adding to the list is done by adding like this:

SerializedProperty newAction = prop.GetArrayElementAtIndex(prop.arraySize++);

So, I created a List<string> at class level in the PropertyDrawer, and added to it when an item was selected. Then, during every OnGUI, I add whatever items are in the class list to the property list, and clear it.

In my initial tests, i thought this was working fine, but now that I have two instances of the property in the inspector (the property drawer is for a list of lists...), whenever I add an item, its only adding it to the first property, not the one I want it to add to.

All relevant code here, mainly in SequenceEditor.cs https://github.com/DraconInteractive/SequenceSystem.git

plucky nymph
#

ah, fixed it 🙂

opaque zenith
#

Why can't get I get the initial opening of an editor window to dock to the desired type? It's only upon closing that window a new one opens that docks correctly

#

I'm using things like HasOpenInstances to make sure there isn't an instance opened up somewhere that has to be closed first

#

nvm, I saved in instance in my main script and used if (!mainEditorWindow.docked) mainEditorWindow.Close();

#

so basically having it to do the auto close for me... however, if I can get it to initialize properly would rather do that just for ease of mind

gloomy chasm
opaque zenith
opaque zenith
# gloomy chasm How are you opening the window? That changes a lot of how it works. I also don't...

Basically, I'm trying to remove using GUILayout.Toolbar as my way of changing between different editor extensions I setup and was looking at just having new things open up as docked tabs instead. However, struggling with finding a way to deal with ShowUtility still. FocusWindowIfItsOpen() almost solved some of my problems when used in Update(), but, it was causing the window to focus even when not in Unity.

gloomy chasm
opaque zenith
opaque zenith
#

It worked the same as GetWindow was, it wasn't opening it docked

#

but if I closed window through the above method even with createwindow it would open backup as docked

gloomy chasm
opaque zenith
#

I didn't do it as .show(). I just did CreateWindow<MainEditorWindow>(typeof(MyEditorWindow)); let me try

gloomy chasm
#

nvm don't need to do Show() since it already does it.

gloomy chasm
opaque zenith
#

That was something I was wondering. Is Update() going off before MyEditorWindow is even going? Guess I could do a debug.log to check. Maybe I should do this OnOpen();

#

or check if an instance exists of MyEditorWindow

opaque zenith
#

change the createwindow back to getwindow due to the extra functionality that comes with it.

opaque zenith
# gloomy chasm Extra functionality?

Just GetWindow will check for an instance of the editorwindow first before creating a new window if one doesn't exist. So, just the extra, most likely unnecessary, check

opaque zenith
#

@gloomy chasm just since you help me a lot figured I'd show you something for fun I've been doing. I wanted to have more control over my enums, so put this together to not only do that, but, to give me more learning of the unity editor fun things. Have this all done through scriptable objects now instead of actual enums

opaque zenith
#

This is obviously way easy to do without an editor, but, my goal was to prevent someone not familiar with scriptableobjects and the organization already in a project to be able to create and remove enums without having to actually look at the project hierachy

#

and doing it through SOs

crimson estuary
#

SceneView.cameraDistance cannot be modified?

#

It says cameraDistance has no setter

gloomy chasm
crimson estuary
#

It won't let me modify or set the value

#

Oh, Rider says it has no setter, Unity's console says it's read only

crimson estuary
# gloomy chasm And?

Is there some way that I don't know to just ignore that fact and somehow set it anyways?

gloomy chasm
crimson estuary
#

I don't think I have access to the source code

#

How else would I go about adding zoom functionality?

#

I could move the pivot point back to "emulate" that but then I can't orbit a selected object

gloomy chasm
crimson estuary
#

Oh, well, I see.

That still doesn't really help though

crimson estuary
#

well, I won't be able to use whatever I may find there anyways, and I'm not even advanced enough at programming to figure it out in the first place

gloomy chasm
#

What is it that you are trying to do in this case?

crimson estuary
#

Set a custom zoom sensitivity and prevent it from zooming in too close

#

Because my mouse does fine scrolling, eg, not line-per-line (which I assume unity expects), so every tiny little tap at it causes the zoom to go flying

#

Is there any other way whatsoever to modify the zoom on the camera?

#

@gloomy chasm I really hope I'm not bothering you by pinging, but you're the best at helping me

gloomy chasm
#

@crimson estuary Checkout line 481 and down to 496

crimson estuary
#

okay, lemme give that a look

#

well this looks like it does the zooming, and it will zoom to where the mouse is hovering, but that's all I can glean

gloomy chasm
crimson estuary
#

I looked at that, it only contains things like fov or clipping

#

I need it to zoom towards center, as I want it to keep the pivot point locked to the focused object

#

Alright, maybe a macgyver solution is needed. Is there any way to emulate me pressing mouse buttons in script?

#

I suppose I could just use the scroll event and then send a fake one at a custom interval

gloomy chasm
crimson estuary
#

Yeah, I need it to zoom in and out to the focused object

gloomy chasm
#

Then that code is literally what you want.

crimson estuary
#

The bit you linked?

gloomy chasm
#

Yeah

#

Well almost

crimson estuary
#

That's !zoomTowardsCenter, I assume that's for if you're not focused on anything it'll zoom to where you've moused over

#

But that would also break the focused object pivot point

#

let me check out earlier parts of this

#

They would probably handle the centerpoint zooming

gloomy chasm
#

This code is actually not bad for what it is, and well structured making it easier to look through.

crimson estuary
#

Is this the actual source code or is this decompiled?

gloomy chasm
#

Actual source code.

#

Reference only.

crimson estuary
#

much comment lack \s

#

It's actualy pretty clear

#

Well, I see how it gets a zoom delta, but not quite sure how it applies it. And if I could, none of this is accessible, unless I'm missing something?

#

So what I can figure is that view.size is the "zoom"

gloomy chasm
crimson estuary
#

But all of this stuff is inaccessible, isn't it?

gloomy chasm
#

Correct.

#

You would need to do it your self. But it isn't that much.

crimson estuary
#

I see. Well, then I need to access view.size, which the Rome that all roads lead to

#

I'll see if that's accessible

#

Oh! There's SceneView.size

#

Can I ask not for technical help, but an opinion?

What's a reasonable cutoff distance for zooming closer? I currently am at 0.1 but that will clip me clear into a default cube. But I'm afraid if I make it too far like 1 or 0.5 it'll be too far for fine details that I (or whoever might want to use this) to use

#

Another opinion is if I should have separate behavior for orthographic mode. I don't know if it'll be necessary to orbit so much in that mode. I know 2D mode should not orbit at all, but should orthographic be the same?

twilit peak
#

hi i have this text in a txt file but when i preview it in unity it gets displayed weirdly. does anybody know of a way to display it normally or stop the weird resizing?

crimson estuary
#

Looks like wordwrap

#

Try make the window a bit wider?

#

Oh wait, no

#

it's tab size not being consistent

#

Maybe use spaces instead of tabs?

twilit peak
#

aight will try

#

nope its still not displaying correctly

crimson estuary
#

Can you send me the file?

twilit peak
#

sure

crimson estuary
#

Well it shows properly in the chat lol

twilit peak
#

yeah lmao

crimson estuary
#

Displays properly for me too

twilit peak
#

it displays properly in notepad but just not in unity editor

crimson estuary
#

Breaks when I don't use a monospace font

twilit peak
#

ohhh okay

#

hm any way i can make unity use a monospace font for previewing the text?

crimson estuary
#

I don't see any way to, I just tried

#

It's a pretty plane though

twilit peak
#

ah alright

#

ahah its not mine i just grabbed it from a website for placeholder art

crimson estuary
#

aw okay

twilit peak
#

thanks for the help tho

#

appreciate it

crimson estuary
#

np, sorry I couldn't solve it

twilit peak
#

nws

crimson estuary
#

Okay, my program works now almost 100%, but I realized an issue. Because I'm always overriding the orbit of the camera, it breaks my ability to click the 3D Compass gizmo. Is there any way to check if I'm moused over that gizmo?

crimson estuary
#

I think I'm done! I fixed the issue, and I think the whole plugin is done and ready!

wintry frigate
#

hey i know this might be a little bit offtopic for here, but i trust/love you guys here in editor extensions, when i'm reading in an assembly with mono.cecil like AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(asmFile); then i do some stuff and i want to write it back out

#

i can do some stuff, successfully, and stepping through with debugger shows cherries all the way through, but then i can't like, write it back out

onyx harness
#

What do you mean write it back?

#

Oh modify the assembly with Cecil

wintry frigate
#

write it back

#

the modification part (according to locals in debugger) is working fine, iterates through what i need to do... i just can't seem to save it back out and the errors are not helping me

#

i think i might need some kinda ____stream or somethign

wintry frigate
#

i did it

gloomy chasm
#

Advanced question. Is there so way to read text from a IMGUI window? Or I guess read controls? Is there any way to hide certain controls?

#

(of course no access to the actual code)

waxen sandal
#

Maybe look at the IMGUI debugger

onyx harness
#

Read might be a hard task, but you need to look at how does the debugger.
Hide is impossible, since you are reading it it is drawn already

stuck olive
#

And it works fine when adding via UI Builder.

#

but if i try to add it using:

VisualElement veTest = new MyElement();
root.Add(veTest);

It spawns but without any of its children despite LOGGING a childcount

left widget
#

have a look at the UI Toolkit debugger, it's quite handy for that sort of thing

gloomy chasm
#

@waxen sandal @onyx harness Yeah, took a quick look at the Debugger last night and I may be able to get label names with it. Thanks!
It looks like it also gives you the Rects so while I can't hide them, maybe I can draw over them and do a fake 'grayed-out' which is second best.

#

A project for next weekend though.

onyx harness
#

Over drawing is what the debugger does already, but it's so far from hiding

#

I already feel you are wasting your time if your real purpose is to hide and not just learn about the mechanic under the hood

tropic prairie
#

How come when I use VSCode or Visual Studio community 2019 intelisense (did i spell that right) wont work, ive switched editors and installed the C# VSCode extention but it still wont work

#

is this the right channel to ask?

gloomy chasm
waxen sandal
tropic prairie
#

ok

onyx harness
waxen sandal
#

Oh I had a fun imgui debugger issue today, the overlays weren't matching the actual clickable area 🤔

#

Or drawing area

stuck olive
# gloomy chasm What is `root` in this case?

Root is my ui window, but it can also be any VE.

I found my problem, when spawning it in code with constructor, i have to use the constructor in my derived class to add children. The example i linked and followed ONLY fires when adding ur element via the UI Builder apparently

#

I also found that constructor works fine for UI Builder, so unless im specifically trying to add attributes for use in uxml or UI Builder inline, i can ignore that example entirely

lilac thorn
#

okay guys i think u heard this question 100 times, so i am sorry to bother u. my autocopletion in visual studio code is not working. How to fix that. the obvios problems do i already have fixed

stuck olive
#

@lilac thorn from Visual Studio you can try:

Build > Rebuild Solution

lilac thorn
#

i use visual studio code, i dont even have the build option

stuck olive
#

if that fails, you can also try browsing to your project folder, deleting Library, obj, temp and any VS files like *.sln, .vs etc

#

delete everything but Assets, Packages, ProjectSettings

#

maybe keep User Settings too if you have that folder

#

seeing as you're in VSCode, i have one question

#

did Unity/VSCode autocompletion ever work for you on your current workstation?

#

you may need an extension, i recommend "Unity Code Snippets"

lilac thorn
#

i installed unity yesterday, so no i didnt

#

okay, but i tryed a lot of these extensions and nothing worked

stuck olive
#

i recommend this one

lilac thorn
#

that i work in 2d doesnt do anything right?

stuck olive
#

nah

#

and you have your external tools set like this?

lilac thorn
#

yes

#

so i reload atm lets see

stuck olive
#

sorry if this is a terrible question, but other people who have had similar problems have made this mistake... you ARE opening VSCode by double-clicking on a script in Unity yeh? I've seen people try to open CSharp files from VSCode directly using "Open" etc

lilac thorn
#

no xd. just doble click in unity on the file

stuck olive
#

algud...

#

hm i can only imagine it may just be that you need snippets extension....

#

oh.... VSCode doesnt give you any .NET warnings in the debugger by any chance?

lilac thorn
#

no it doesnt

stuck olive
lilac thorn
#

and i work for one word rn but then stoped again

stuck olive
#

oh...... thats even weirder :S

lilac thorn
#

yes

#

okay every time i open vsc i works for one sec

#

shall i maybe call u so u can see it?

stuck olive
#

well... i may be out of ideas... my usual list of troubleshooting includes

  • deleting trash files like Library, .sln, .vs, temp etc
  • checking external tools is set right
  • code snippets installed
  • .net installed
#

ah i cant at the moment, ppl sleeping nearby, its ok i get what you're saying, but dont think im familiar with that particular issue :S

lilac thorn
#

okay thank u anyways, i will write again if something changes

stuck olive
#

^^

#

do you happen to be on a network managed PC?

#

when im at work in the office, i get all kinds of issues with VS and VS Code cos of how managed our systems are by IT

lilac thorn
#

no private pc at home

stuck olive
#

hrm

stark geyser
#

@stuck olive No memes/reaction gifs, please.

stuck olive
#

my bad, soz

lilac thorn
#
    Failed to load project file 'd:\Programmieren\Unity Projekte\Rimworld\Unity.InternalAPIEditorBridge.001.csproj'.

d:\Programmieren\Unity Projekte\Rimworld\Unity.InternalAPIEditorBridge.001.csproj
c:\Users\Morten.vscode\extensions\ms-dotnettools.csharp-1.23.12.omnisharp\1.37.10.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1216,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

so thats a warning i get

and then 100 of this

    Attempted to update project that is not loaded: d:\Programmieren\Unity Projekte\Rimworld\UnityEngine.TestRunner.csproj
stuck olive
#

hey, that's progress!

#

that's what ya get for trying to make rim world

#

buttt

lilac thorn
#

ahaha xd. i just need a name

stuck olive
#
Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version
#

this is pretty key ^

#

so i have seen people go through the motions and install .NetFramework and Core, but I've usually found success by giving it the version that it wants as well so you may need to install that specific version

#

the developer pack there may get you one step further

lilac thorn
#

okay and were to safe that? does it matter?

stuck olive
#

doesnt matter where ya save it, when you run the installer it will go to the right place

#

maybe close unity and VSCode as you do this

#

once it finishes, reopen project, try open script again, pray for best

lilac thorn
#

nope not realy

stuck olive
#

; ;

#

gonna try it on my end to see if i remember something in the process...

lilac thorn
#

damn

#

i works

stuck olive
#

oh great ^^

#

maybe it just needed to wake up lol

lilac thorn
#

i just needed a new script. idk whats work with the old one

#

both were empty

stuck olive
#

ah ok, well thats good news either way

lilac thorn
#

but ty so much

open verge
#
sectionCompleted.boolValue = true;
EditorGUILayout.BeginHorizontal();
sectionCompleted.boolValue = EditorGUILayout.Toggle(sectionCompleted.boolValue, GUILayout.Width(10f));
EditorGUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();

Question about seriealized properties!

#

How come that when I give a value to a seriealized property, then draw the toggle that uses this seriealized property, this value doesn't change when using the toggle?
It must come from how seriealized properties work, but i have no clew why it does this 🤷‍♂️

gloomy chasm
open verge
#

oh so my value is indeed changed, but just overrided the next frame?

gloomy chasm
#

Yup

#

You are doing

  • Set true
  • Get value
  • Draw value
  • Set to input value.
open verge
#

ohh all right i see

burnt dove
#

How can I check inside an EditorApplication.modifierKeysChanged or EditorApplication.Update if a given key is pressed down?

ashen pulsar
#

How can I smoothly blend between 2 animated ABC caches ?
I have 2 spheres deforming and I would like to run the first animation in loop, then transition to the second cache.
I have attached an ANIMATOR to the first cache and added the second cache as animation, but the playback is incorrect. How can I blend between 2 caches. Even if is not ABC is ok, but I have no idea what else to try

gloomy chasm
opaque zenith
#

okay, so I think I have this editor extension almost to a point I really like. However, I that randomly my unity window hangs like it is refetching all the data?

#

I know that it would be useful to see my code, but, it is kinda long, so was wondering if anything off the top of anyones head first to look at

opaque zenith
#

I might be having to much happening at repeated intervals. Like, I have a setdirty, saveassets, refresh happening after every time one of these data values is added or removed

opaque zenith
#

okay, it looks like the repaint() is what is causing the problem

#

at least if I am looking at this correctly

#

InspectorWindow.Repaint causing 77.4% of the spike when that happens

#

what confuses me though is that the inspector is already updated and can still do things for a couple of seconds before this hang?

#

oh, there is 3 spikes, the ones after that is RepaintAllProfilerWindows()

ivory fulcrum
#

Hey, if I'm trying to replace a texture in a Sprite Renderer in the editor in C#, do I have to save the modified texture pixels to the image file and then somehow set the texture file to the sprite renderer or is there an easier way to do it?

#

This is what my "save textures" method looks like:

public void SaveTexture()
        {
            // Save the texture to the output file
            canvas = new Texture2D((int)clippingRect.width, (int)clippingRect.height);
            canvas.SetPixels32(imageCanvas);
            canvas.Apply();

            renderer.sprite = Sprite.Create(canvas, new Rect(clippingRect) { x = 0, y = 0 }, new Vector2(0.5f, 0.5f));
        }

imageCanvas is the new image

#

Everytime I do this it just clears out the texture from the SpriteRenderer

floral sedge
#

@visual stag

#

should i do this?

#

it's still doesn't work

visual stag
#

no, if map is null it won't change between Layout and Repaint.
What do you do when the error appears?

floral sedge
#

the map became not null

visual stag
#

how does that occur?

floral sedge
#

i modified the value of map via a toggle

visual stag
#

Try adding a change check to the toggle and exiting GUI there perhaps

floral sedge
#

it's ODIN ... i don't know how to control it

visual stag
#

Wherever you change the state in this case is where you should exit the GUI. I don't know how odin works either

floral sedge
#

should i check it in inspectorUpdate function?

#

or i can only check it in OnGUI?

visual stag
#

it's only relevant in OnGUI

#

if that's happening in the base.OnGUI, try wrapping that in a change check and exit if a change happens. It's probably not ideal, but if it works 🤷

floral sedge
#

still not work. :(

#

it's so weird. it should work based on your advise

visual stag
#

): sorry, I can't be of more help
To describe the issue that's happening clearly:
OnGUI is broken up into a few passes, one Layout, one Repaint (and some extra)
When Layout occurs it allocates a stack of rects for use with Repaint.
When Repaint occurs it expects that stack to be allocated in the exact same way, when it isn't it will throw that exception.
If you're doing a structural change in the middle somewhere and calling ExitGUI that just throws an exception which ends the GUI frame and it then repaints again.

#

So if you have a list of items that changes between phases that you're drawing, then drawing a new one when the stack doesn't expect it requires you to exit the GUI. The error is totally harmless, but obviously should be avoided because it's annoying as all hell 😛

floral sedge
#

your words are helpful. thanks a lot 👍

gloomy chasm
#

I have not been paying any attention to the conversation. But if you have a harmless error than you can always use a try catch

floral sedge
#

😂 but it will be called per frame, doesn't it cause the low performance?

visual stag
#

Not necessarily always because sometimes it's just a LogError and not an exception

gloomy chasm
#

(I have literally no context for what I am saying. I am basically just responding to the last sentence in vertx's last message 😛 )

floral sedge
#

😆

floral sedge
#

i solved it by checking the map manually.

#

it's so weird. the GUI.changed and BeginCheckChanged occurs at Repaint phase but it called later than below code.

#

@visual stag

#

maybe the changed check happened in next repaint phase

visual stag
#

maybe, either way, glad you've got a fix 👍

floral sedge
#

thanks for your help.xD

burnt dove
#

How can I change the object that is being shown in an UnityEngine.UIElement.InspectorElement? Using .Bind(obj) only works the first time. What I am missing? Must I force a redraw or something? How?

#

I noticed that I destroy and create a new inspector, but that sounds expensive

gloomy chasm
burnt dove
#

Ok, thought it also has an .Unbind method, but doesn't work 🤔

grim walrus
#

Has anyone figured out the "multi layered" dropdown that UnityEvent has?

steep talon
#

Writing here cause there's no channel specifically for this... anyone knows how to make custom timeline tracks reset their value when deselecting the gameobject with the playableDirector they appear on?

#

I have the problem that my custom timeline tracks edit values in the scene during previeuw but those values dont get reset and in the end always get saved

wispy delta
#

I'm trying to make some editor settings that will assist in globally changing the mip bias of textures in my project.

I have an AssetPostprocessor with the OnPreprocessTexture event function so I can grab the textures importer and set the mip map bias based on my settings

private void OnPreprocessTexture()
{
    TextureImporter textureImporter = (TextureImporter)assetImporter;
    if (textureImporter != null && ShouldSetBias(textureImporter))
    {
        textureImporter.mipMapBias = MipSettings.GetOrCreateSettings().bias;
        textureImporter.SaveAndReimport();
    }
}

Then in my MipSettings gui, you can change the bias field and click an "Apply" button. I'd like the apply button to reimport all the textures in the project, which will indirectly cause the mip bias to be updated via the asset post processor mentioned above.

The problem I'm having, is that reimporting the assets doesn't trigger anything on my post processor. Unity just doesn't run it.

if (GUILayout.Button("Apply", GUILayout.Width(50)))
{
    // find all texture guids
    string[] guids = AssetDatabase.FindAssets($"t:{nameof(Texture2D)}");
    foreach (var guid in guids)
    {
        // get the texture path
        var path = AssetDatabase.GUIDToAssetPath(guid);
        // and importer
        TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;
        
        // if the asset has a texture importer, and the post processor should set the bias
        if (importer != null && MipBiasPostProcessor.ShouldSetBias(importer))
        {
            // reimport the asset
            Debug.Log("Reimporting " + path);
            AssetDatabase.ImportAsset(guid, ImportAssetOptions.ForceUpdate);
        }
    }
    // and refresh the asset database because that sounds
    // like a thing I should do?
    AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
}
visual stag
#

AssetDatabase.ImportAsset takes a path not a GUID

#

or whatever way around that goes

wispy delta
#

oh my god thank you haha

#

ah that start/stopediting thing is perfect. i had a feeling that would be a problem!

visual stag
#

otherwise when you click that button... you're gonna be waiting a while lol

#

I have had that regret

opaque zenith
#

I set this up to add more to my custom enum editor I'm working on. I kinda wanted to try and get away from the ongui and stuff. I haven't tried setting up events in the editor scripts. I was having a difficult time figuring out how I wanted to initiate my enumdata script. Will this cause any potential problems down the road?

burnt dove
#

I am having an odd problem, from C# I can create ObjectField elements, but from UXML files I get the error "Unkown type: 'UnityEngine.UIElements.ObjectField'". 🤔. How can I fix that?

wispy delta
#

Is it possible to invert a FindAssets query? I don't see it mentioned anywhere online so I'm guessing not, but I'd like to get all sprites without a certain asset label so I can easily exclude assets from a bulk operation by simply adding a special label

opaque zenith
#

ohh nvm, That isn't what you asked. I wonder if you can do a ! somewhere with the label

waxen sandal
#

I don't think so

opaque zenith
#

You could do an AssetDatabase.FindAssets for sprites, then do a foreach on each of those and to not load that sprite if its of a certain label

plucky nymph
#

Hey all 🙂
Writing a custom inspector for a class that has public List<T>. Im trying to make it only render a single element of that class, with some nav buttons to flip through the whole thing. The question is: do I have to spend a bunch of time making the output of the classes data manually, or is there a 'RenderDefaultDrawer' kind of function to allow me to render it as if it was standalone?

visual stag
#

EditorGUI.PropertyField draws the drawer for something

rose saddle
plucky nymph
#

Yeh my main thing is that im not sure if I can get the property for the object, I think I can only get it for the array as a whole. I will check out CreateEditor, thanks for the resource!

rose saddle
waxen sandal
#

Yes that's the default behaviour

#

You can iterate over a lists items just find by doing Next(true) or GEtArrayItemAtIndex

#

Doing CreateEditor is not a good idea to do in OnGUI, as you need to manage the life time properly. So it's a no go in propertydrawers

onyx harness
opaque zenith
#

What causes my editorwindows to occasionally stop opening and having to do reset layout?

#

looks like there was a failure to destroy the window.

onyx harness
#

Because when you open a window, you usually call GetWindow() which will first look for an existing instance of the window

opaque zenith
#

ya

onyx harness
#

And since there is one (even if corrupted), you won't see anything

opaque zenith
#

okay, should I destroy the instance then

#

every time

onyx harness
#

Yes

#

no

#

Only if corrupted

opaque zenith
#

okay, I haven't done anything yet with these catch functions, is that how you would suggest handling that, or just an if statement

onyx harness
#

There is no catch

#

since there is no exception

opaque zenith
#

gotcha, thanks again for the help!

onyx harness
#

Take this

#

This is how you get rid of an orphan/corrupted window

opaque zenith
#

okay, ty!

onyx harness
#

And this is m_Parent

#

Notice that you don't call Close() on the window.

#

You must destroy it.

opaque zenith
#

I started using a singletoneditowindow script to pair with an instantiateonload atribute. Would it be best to put that oprhan method in the check in the singleton script?

onyx harness
#

I have no idea how is your singleton made

#

I call the orphan check every single time i open a window.

opaque zenith
#

oh okay

#

guess that would make most sense anyway

#

anyways

onyx harness
#

You have no choice, it must be done prior to open your window

#

Or you will see a silent bug

opaque zenith
#

ya

waxen sandal
#

I guess Close relies on the parent?

#

Never really had this issue so I didn't have to fix it :p

onyx harness
#

I would say kinda yes, as I am not sure of the code under, but since the parent is null, closing does not bubble up correctly.
While if you destroy, you destroy the GUIView the EditorWindow resides in, which embarks his buddy on the way

waxen sandal
#

👍

opaque zenith
#

Okay, so now that I hopefully have that working. I want to today try to better understand setdirty, saveassets, and refresh. I think these are what are causing me to have to repaint hangups

#

I know that I seem to need to refresh assets, at least for the project hierarchy to display new scripts I make in the editor window

#

but I don't feel like I need to setdirty and save assets after every change I do. The setdirty is confusing me a bit since I thought I needed to do that save changes to scriptable objects I do from code, but might be doing it excessively

burnt dove
#

How can I display a custom type in an UIElement? InspectorElement doesn't seem to support arbitrary types.

burnt dove
#

How can I do for example?

[Serializable]
public class Alfa { public int a; public int b; }

Alfa alfa = new Alfa();
InspectorElement inspector = new InspectorElement(alfa);
#

That doesn't work

#

@gloomy chasm

gloomy chasm
burnt dove
#

😢

gloomy chasm
#

If you don't want to specify the elements for each you will have to use SerializedObjects, and SerializedProperties, with PropertyFields.

burnt dove
#

I was playing around with [SerializedReference] but I guess I will have to use ScriptableObjects then, they are far easier 😆

gloomy chasm
#

What is it that you are doing that makes it more difficult to use the attribute?

burnt dove
#

I was using reflection. Didn't know that PropertyField did support SerializedReference

#

mm, I'll try using PropertyField then

gloomy chasm
burnt dove
#

PropertyField doesn't seem to work if I give to it a SerializedProperty which cames from a type that requires [SerializedReference] to be serializable

#

Well, at least I can fallback to ScriptableObjects

gloomy chasm
burnt dove
#

If I have:

public class Alfa : MonoBehaviour {
  [SerializeReference]
  private IMyInterface array;
}

// Editor
root.Add(new PropertyField(serializedObject.FindProperty("array")))

The field isn't shown

gloomy chasm
#

Unlike normal serialized fields, ones that are serialized with [SerializeReference] can be null, and will be unless you set their value.

visual stag
burnt dove
iron drift
#

Does anybody have an idea how to work with PresetTypes? I'm using an ObjectField to Referenzen Presets and onChange I would like to evaluate the PresetType, but I can't figure out how to check, for example, if the PresetType is TextureImporter.

There is no static PresetType.TectureImporter and I wasn't able to use the PresetType Constructor so far.

waxen sandal
#

@onyx harness Do you happen to know anything about this serializedproperty.unsafemode?

onyx harness
#

@waxen sandal not at all

#

seeing the code, I'm not sure how I would use it

#

Seems heavily related to Binding

#

which is purely UIT

#

An area I dislike 😄

waxen sandal
#

Well it disables some checks, wondering if it actually makes it faster or if the check is neglectable

#

And how "unsafe" it actually is

#

We're doing a lot of validation with serializedproperties, so much that calling Next() is actually a real bottleneck

onyx harness
#

when I see that I can understand why on huge scale

#

I would say, if you are safe yourself, I would go into it 😄

waxen sandal
#

Yeah I'll probably just enable it and compare some quick benchmarks

onyx harness
#

Keep me in the loop please, sounds interesting

waxen sandal
#

Sure, I'll let you know

#

I don't think we get any exceptions while running our validator so it should be "safe"

onyx harness
#

Well the check seems to be "check if at the end"

#

Not the hardest to do yourself 🙂

waxen sandal
#

Yeah exactly

opaque zenith
#

so I was checking Debug.Log(serializedObject.hasModifiedProperties); and it returns false even after I add something through code not the scriptableobject. Do you not need to setdirty on a scriptableobject on everything on a scriptableobject?

gloomy chasm
opaque zenith
#

I guess I could just restart unity and see

gloomy chasm
opaque zenith
#

so, I'm not setting through those, persea. I have my scriptableobject instance I'm adjust values on, but, the "get info" part doesn't rely necessarily on the scriptableobject to have that data. However, I want to make sure that data is saved to the scriptableobject so when I check to get the data, it won't go through the process involved if the data already exists

#

atm the default inspector updates correctly, but want to make sure it saves. I guess I'll just check haha, just enjoy the chat

#

did just get this error Importer(DefaultImporter) generated inconsistent result for asset(guid:9f8e9c9c30d734674a446d6bdab62eb9) "Assets/ScriptableObjects/Enums/Test" is this because of the fact I deleted the last Test I made, and then made a new one? I think I read somewhere about GUID data and other things aren't actually deleted after removing an asset till you restart unity?

opaque zenith
gloomy chasm
opaque zenith
# gloomy chasm Well what are you doing. If you are editing an asset and not setting it dirty, a...

So where I'm at atm is I have a scriptableobject singleton, have the asset of it. Then in editorwindow I have it getting and setting data from the scriptableobject through my singleton doing EnumData.Instance. I just created a new Enum that does .add to the lists on the scriptableobject and restarted unity and it seemed to have saved the data. Sorry, I know this isn't really a problem. Just trying to understand it more

#

now this most recent test didn't save, but kept the previous data wasn't saved either haha

ivory fulcrum
#

I was told that I want a custom importer, but I want to interject between the point where the asset is turned into a Texture2D, And what I have right now is a button that is supposed to modify an image and its position. The problem is that the last step of replacing the asset doesn't work. I create a sprite and attach it to the sprite renderer and the image that was there that the button operated on disappears. I know everything else works because I tested it individually. The only problem is saving it to the asset database so that it has the modified data. I'm trying also to avoid modifying the original files that it imported or generate any other files

gloomy chasm
opaque zenith
#

Okay, so, I moved on back to some InitiateOnLoad things and made me curious more about understanding scriptableObject instances, combined with the normal singleton pattern.

#

is a script I made

#

which worked when I put a setter in the singleton pattern to make the instance = this loadassetatpath

#

but without it, the debug for the instance is 0, for example. When I click on the EnumData scriptableobject it also would populate the EnumData.Instance, but, not before then?

ivory fulcrum
#

Sorry MechWarrior99, Ok. So I have image files with a large amount of surrounding transparent space around each image. They're imported into a prefab where individual game objects represent each image which acts as a "layer" that can then be stacked on top of the image below it. This works because all of the images are the same size, and all of them are positioned at 0,0. But, it's wasteful and inefficient in terms of performance because each image could have several hundred empty pixel rows and columns around the actual image data.

So I've written a button that crops out those empty pixels leaving just the actual image in the center, and also calculates how the positioning should be adjusted so that the image is in the same place on the canvas as it was before (so that layering still works). The problem is that now that I've got all that working, I need to put the newly created Texture2D as a Sprite into the sprite renderer for the corresponding object.

I thought maybe I could just generate a sprite and assign it, but that just makes the image disappear from the canvas and when you go to the gameObject in the editor and check the sprite renderer component, "sprite" is blank.

Because this is built into the editor, I'm trying to abide by some rules: Don't create extraneous files in the assets directory, apply the graphic to the sprite renderer, and don't modify the files the image was imported from

gloomy chasm
#

There is no reason for it to be in update. If you wanted you could have it in a separate method that get calls and also have an initOnLoad attr on it.

gloomy chasm
ivory fulcrum
#

Because those are the original assets the user is working with presumably

#

That would still be a somewhat destructive change that would be hard to reverse if the user needed to

gloomy chasm
# opaque zenith good point!

This is what I do for my own and I call it in the get; accessor for the singleton instance field.

[InitializeOnLoadMethod]
        private static void SetInstance()
        {
            if (_instance != null)
                return;

            string[] guids = AssetDatabase.FindAssets($"t:{nameof(LibraryData)}");

            if (guids.Length > 0)
            {
                _instance = AssetDatabase.LoadAssetAtPath<LibraryData>(AssetDatabase.GUIDToAssetPath(guids[0]));
            }
            else
            {
                _instance = CreateInstance<LibraryData>();
                AssetDatabase.CreateAsset(_instance, LibraryConstants.RootPath + "/Asset Library.asset");
                AssetDatabase.SaveAssets();
            }
        }
opaque zenith
#

Yeah, appreciate it. I hate when I derp like this lol. Made an entire different script to do the initialize than put it in the singleton

#

like, went in a full circle when I didn't need to

gloomy chasm
#

lol

opaque zenith
#

this scriptableobject enums is going to eventually build into other things. I just keep getting stuck wanting to perfect this base part lol

gloomy chasm
onyx harness
#

What I see is an instance that will force load at init even though it might never be use.
Go for lazy loading like any common singleton pattern

#

If everybody was doing like that, reload might take precious seconds just for those

gloomy chasm
#

Oh that! Yeah this isn't my normal pattern. I normally use the Lazy<T> class. But for this particular one I did it this way. I had a good reason for doing it this way I think, but I can't remember now so I was planning on reverting it back.

The more I think about it I think it is just leftover this way from refactoring.

vapid prism
#

How can I store editor data that persists through domain reloads? Also is there a hook I can listen to, to know when a reload occurs?

opaque zenith
#

@onyx harness @gloomy chasm hows this look?

#

also, is there a way to make this a singleton for everything? I've noticed online different singletons for every inheritance. Can't you just do a generic inheritance?

gloomy chasm
#

If this is not for editor only then you need to wrap the code that is editor only in a #if UNITY_EDITOR or Unity can't built.

opaque zenith
#

that confuses me, is that even possible? For this to be called doesn't there mean there is an asset?

gloomy chasm
opaque zenith
#

oh okay, so I should keep the system.linq resources also for if this ie being accessed outside the editor?

opaque zenith
# gloomy chasm What?

my other check was _instance = Resources.FindObjectsOfTypeAll<T>().FirstOrDefault(); I should leave that outside of the #if UNITY_EDITOR so I still have some method if trying to access the instance at runtime

#

?

#

Not that I will. Just wondering

gloomy chasm
#

Yes.

#

btw the is no need to do

T t = AssetDatabase.LoadIns...;
_instance = t;

Just make that one line and directly assign the instance to _instance.

#

Also for CreateInstance, there is a generic version of it so you can just use that instead.

opaque zenith
#

I didn't quite understand the create instance generic part. I thought that was what this already is hehe

#

also did add if (tGuids.Length > 0) forgot that in SS

ivory fulcrum
#

Here's the code as it stands right now. The "return" at the end of the foreach loop in "ModifyAllImages" is so that it only processes the first image until I get the process correct.

#

TextureViewerWindow.ShowTextureViewer(sprite) is a custom window that shows the results of the cropping.

#

The cropping works, the realignment works. It's just applying those changes to the prefab in such a way that it can be undone, doesn't change the underlying files, but persists when saved and is included in the final build

#

I was told I need a custom importer, but I'm unsure from the documentation how to do that.

gloomy chasm
peak wigeon
#

There's some way to make this work? This is a struct array

waxen sandal
#

Enable rich text

opaque zenith
#

so, I've been tracking guids in some of my editor things for just in case I need them... when do I need to use Guids vs just a path? Would it be anywhere I don't know the default path, like different OS?

gloomy chasm
#

Basically if you want to reference an asset without loading it, there is almost no reason to use path instead of guid.

opaque zenith
gloomy chasm
#

Correct

ripe fossil
opaque zenith
#

oderwat.indent-rainbow is extension identifier

ripe fossil
#

Very nice, thanks a bunch. I've been using a simple line identation visualization for years in VS, but this is far nicer!

opaque zenith
#

haha thanks, was looking at how to get that

opaque zenith
#

So I made a separate script to solve this, but, made me wonder. Is there a way to bypass compile errors? Like, create a method that does certain things, but, if the variables and stuff don't exist yet, to make the errors null?

onyx harness
#

No

opaque zenith
#

okay, thanks!

#

hmm I guess I could just put the method in the class that doesn't exist yet with if UNITY_EDITOR conditions

onyx harness
#

maybe using a DLL

#

But I'm not sure

opaque zenith
#

oh dang, I'm noob enough with unity haha. I'll learn about DLL stuff soon

opaque zenith
#

so I think I accomplished what I was wanting to do, though not exact, through the class itself and #if UNITY_Editor and OnEnable()

#

I guess I could just do awake instead though? or both?

opaque zenith
#

Mech got me hooked into #if UNITY_EDITOR. I was trying to not use it outside of editor scripts directly, but, it has actually made my life easier to just include editor things in the scripts themself 😦

gloomy chasm
gloomy chasm
#

Ugh, trying to track down all of the validation methods for the menu items in Assets/ menu is a pain.
Also comparing items to figure out what is missing from the menu.
(Trying to make the Assets/ menu customizable)

onyx harness
#

Using Menu I guess?

gloomy chasm
#

Sadly less than half of the items in the menu are added via [MenuItem] the rest are added in C++...

onyx harness
#

EditorGUIUtility.SerializeMainMenuToString() is not enough

gloomy chasm
#

I have not seen that before. What does it do?

onyx harness
#

Get all the top menus

#

But it is not looking at validation methods

#

just fetches all the menus

gloomy chasm
#

Ah, well it only returns "Assets" when I use it in the project browser. So unfortunately not that helpful in this case.

onyx harness
#

When you use it in project browser?

#

How do you use it "in"?

gloomy chasm
#

What I am doing right now is subscribing to the EditorApplication.projectWindowItemOnGUI event and catching the Event.current if it is a ContextClick, using it and calling my own menu.

#

I haven't tried figuring out how to replace the menu for the Add button yet. I'm thinking maybe using UITK to put an overlay over the button and catch the click event first. If there are better ways to do this I am more than interested.

onyx harness
#

I'm not even sure to understand where lies your issue

gloomy chasm
#

Those look promising, I will check them out thanks!
My issue is two fold. First, trying to get all the menu items for the "Assets/" menu.
Second is getting the validation methods for the menu items that have them.

onyx harness
#

First is solved.
2nd is partially possible as you discovered.

gloomy chasm
onyx harness
#

You can't. Some are not present in C#

gloomy chasm
#

Yeah, I figured that was the case. I think I should be able to recreate them though. I hope.

onyx harness
#

Recreate them?

#

Except manually, I dont see how

#
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
    foreach (Type type in asm.GetTypes())
    {
        foreach (MethodInfo method in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
        {
            MenuItem[]    attributes = method.GetCustomAttributes(typeof(MenuItem), false) as MenuItem[];

            for (int i = 0, max = attributes.Length; i < max; ++i)
            {
                MenuItem    menuItem = attributes[i];

                if (menuItem.menuItem.StartsWith("CONTEXT/") ||
                    menuItem.menuItem.StartsWith("internal:"))
                {
                    continue;
                }

                //if (menuItem.validate == false)
                {
                    string    label = menuItem.menuItem;
                    int        n = menuItem.menuItem.LastIndexOf(" ");

                    if (n != -1)
                    {
                        if (menuItem.menuItem[n + 1] == '%' ||
                            menuItem.menuItem[n + 1] == '#' ||
                            menuItem.menuItem[n + 1] == '&' ||
                            menuItem.menuItem[n + 1] == '_')
                        {
                            label = menuItem.menuItem.Substring(0, n);
                        }
                        else
                            label = menuItem.menuItem;
                    }
                    else
                        label = menuItem.menuItem;

                    Debug.Log(menuItem.menuItem + " " + menuItem.priority + " " + menuItem.validate + " (" + label + ")");
                    //this.Build(root, menuItem, label);
                }
            }
        }
    }
}
#

This is to fetch the menus, I guess you did something similar

#

A lot are missing

gloomy chasm
#

You can use the TypeCache to get them which is nice. But as you said, a lot are not returned. So for those I need to either find the validation method in the C# code, or if they are not there, create my own validation method that that mimics the funcinality.

onyx harness
#

I dont like TypeCache, I mean not for now

gloomy chasm
#

Why is that?

onyx harness
#

Was not reliable enough when it first came out

gloomy chasm
#

Ah, I have not had any problems with it my self as of yet.

onyx harness
#

Was returning empty results on 2nd domain reload

gloomy chasm
#

It's to bad that ExtractSubmenus doesn't include the key bindings too.

onyx harness
#

At least you have the paths, which you can recover from

gloomy chasm
#

Yeah, for sure will still save me a lot of time. I guess I will use it along with getting the MenuItems to get what info I can. Then just do the rest manually.

onyx harness
#

In my method, I do call ExtractSubmenus to construct all the paths.
Then use the above code to recover bindings when available

gloomy chasm
#

OH! I wonder if I can use Menu.RemoveMenuItem and Menu.AddExistingMenuItem instead! Any idea what string existingMenuItemId is?

onyx harness
#

I dont understand

#

First you want to fetch

#

now you want to modify?

#

Dunno

gloomy chasm
#

I just want to be able to customize the items in the Assets/Create/ menu.

magic spire
#

hi, i need help on how to access an asset, so I downloaded Bolt, and imported it, I can see the files under the project tab, but idk how to access it

onyx harness
onyx harness
gloomy chasm
gloomy chasm
magic spire
gloomy chasm
gloomy chasm
onyx harness
#

Priority can be recovered

#

Some might be missing as well

gloomy chasm
#

It can? Besides with MenuItem?

onyx harness
#

Priority is in MenuItem

#

With the code above, you can recover all those stuff

gloomy chasm
#

Yeah, but that is like less than half of the items in the create menu sadly.

onyx harness
#

yep

gloomy chasm
#

And I never did figure out what string existingMenuItemId was, so just using AddMenuItem with an EditorApplication.ExecuteMenuItem

onyx harness
gloomy chasm
onyx harness
gloomy chasm
gloomy chasm
# onyx harness

What version is that on and do you remove the items first or anything?

onyx harness
#

When I did my first test on Menu in 2018.3, it was "working"

#

I was able to add, remove

#

And it was not super reliable

gloomy chasm
#

Maybe something changed between then and 2020.3. AddMenuItem works reliably and it isn't that much more annoying to use. So that's fine I guess.
Is ExtractSubmenus public in a different version?

onyx harness
#

Yeah I'm sure it is more reliable now, like TypeCache

sage crater
#

guys is there a way to make my dropdown stay on the value selected in inspector like it would if it was an enum from monobehaviour?

onyx harness
#

Yes

sage crater
gloomy chasm
#

I see, I was under the impression that the screenshot was from your own stuff. I see where it is from in the source. My mistake for assuming things.
But strange, AddExistingMenuItem should work... I will take a look at the code I guess and see if I can find any differences.

onyx harness
#

By setting currentEffect

onyx harness
# onyx harness

Me naming variable text4? You are insulting me right now🦉

gloomy chasm
onyx harness
#

It comes from dnSpy, common naming I would say from disassemblers

gloomy chasm
#

Oh! Are you using that to look at newer version's source code since the repo is no longer being updated?

onyx harness
#

I almost never use the official repo

gloomy chasm
#

Oh really? Why is that?

onyx harness
#

I found jumping from a disassembler much efficient

#

I only use GitHub when I dont have dnSpy around

#

Also I can scan between multiple versions at once

gloomy chasm
#

Taking a look at it, it seems pretty nice. Is there anything you gotta do to use it with the editor? Also, is there a different repo to use now since the current one is archived? Or is it still good?
(I have never used something like it before)

onyx harness
#

You just need to drop DLLs in there and it will scan them

#

I don't think the official repo is abandonned, is it?

#

I was using ILSpy first, then discovered dnSpy which has a much better UX and dark theme

#

For API search I use my NG Unity Versioner, for implementation I use dnSpy

#

using dnSpy will have a part in my tutorials

gloomy chasm
#

Says it is readonly now, last update was 6 months ago.

#

When I check it out, if I can't figure something out would you be alright if I ask you, or would you prefer I not (totally get if not)?

onyx harness
#

figure what? How to use dnSpy?

#

You will see, it is rather simple to use it

#

Like a kid in a sandbox

gloomy chasm
#

Cool, that's good!

ivory fulcrum
#

Alright, I think I've made some progress. I can change the texture data just simply by using renderer.sprite.texture.SetPixels32() and then renderer.sprite.texture.Apply()

#

But the problem is that the object is still the original height and width, even though the underlying texture is now much smaller so it puts it in the bottom left of the rect instead of just making it the same size. Is there a way to resize a game object with a sprite renderer without messing with the "scale"?

#

Even if it's in world coordinates that would be fantastic

gloomy chasm
ivory fulcrum
#

It does not, but I think I can add one?

gloomy chasm
ivory fulcrum
#

Right I mean from the C#

gloomy chasm
#

Yes.

#

AddComponent<RectTransform>()

ivory fulcrum
#

and then I think there's an EditorUtility static method I need to call against it

ivory fulcrum
#

Sorry, PrefabUtility

#

PrefabUtility.ApplyAddedComponent()

gloomy chasm
#

AH

ivory fulcrum
#

Yeah, because otherwise it's an "override"

#

So if later the user creates a prefab variant, it comes with that RectTransform

#

Not that I can think of when they would, but I do think the user would expect that behavior

#

Thank God for C# Idioms:

if (!renderer.gameObject.TryGetComponent<RectTransform>(out var newTransform)) 
  newTransform = renderer.gameObject.AddComponent<RectTransform>();
ivory fulcrum
#

No that didn't quite work. I got a light gray block that was the full size of the original image. Not sure why.

#

Maybe I need to do the texture edit first and then the rect transform?

#

idk

#

Is there a way to change the size without a rect transform that I'm missing? like how does the importer set the size?

waxen sandal
#

@onyx harness unsafeMode seems to save ~10%

#

Actually, more like 20% went from ~240s to 200s

#

(as you can imagine this is A LOT of iterating over serializedproperties)

onyx harness
short prawn
opaque zenith
#

I'm trying to create some editor scriptableobject assets with MenuItem attribute. It can only be used on methods, so, do I just make my method create an instance, then create asset?

waxen sandal
#

CreateAssetMenu

opaque zenith
#

errr whoops

#

I should have clarified

#

I don't want it under the asset menu is what I'm trying to achieve

waxen sandal
#

You can override the path no?

#

Ah no

opaque zenith
#

I don't know

waxen sandal
#

In that case, menuitem with your own creation

opaque zenith
#

okay, cool

waxen sandal
#

IIRC there's no magic way for that

#

Could check reference source and see what they do

gloomy chasm
#

Iirc they handle it on the C++ side.

opaque zenith
#

there is just some things in the editor script I'm working on that I want to save data to essentially so that it doesn't have to be regotten every time, but not put it onto what I'm creating a custom editor for to keep the code separated for my own personal preference. I know editor already extends scriptableobject

waxen sandal
#

🤔

#

But why

#

You can handle it all on the C# side

opaque zenith
#

so just was thinking about how to best approach the creation of it

#

without having it in the asset menu with regular assets

#

I don't necessarily like the route some people go where they do createassetmenu, create the SO, then comment it out lol

waxen sandal
#

You can just do CreateAsset with a scriptableobject as item

opaque zenith
#

Guess that's true. Could essentially put a section in the asset menu that is editor specific assets

#

I think I might go the route we were talking about earlier though, because I can put a check in the method to make sure only one of that scriptableobject exists

split bridge
#

You could also just comment out the menu item once you've created an instance.

opaque zenith
#

Yeah, I just don't like that route because it feels... uhhh how do I say this? Like a band-aid solution?

split bridge
#

What you want to do is a little odd though right? You don't want to create assets through code, instead you want to create them via the UI.. but only for yourself, and then sometimes you don't want the menu option to be visible?

#

Unless I misunderstood

opaque zenith
#

I want to create a scriptableobject that holds data for the custom type my editor script is for, for editor side of things so that the data it is storing doesn't have to be found basically every time I need access to it. I can do the if UNITY_EDITOR stuff and not do this at all, however, due to my own annoying way of preferring things it hurts my eyes and stuff to mix that into things that go into builds, so I have a menuitem for my editor things called editor, and thought hey, maybe I'll make a category in that for editor scriptableobjects

#

idk if that helps

split bridge
opaque zenith
split bridge
#

The most annoying part with those is (afaik) they require a static path. When making an asset where a user can freely move it around, you need to do more of the work yourself (but it isn't much).

opaque zenith
#

yeah, the current thing I'm working with will work perfectly in adding to that haha. It's actually why I I'm trying to do this further, because I didn't want to store GUIDs and Paths and things on my build objects lol

waxen sandal
split bridge
opaque zenith
#

Is there a way to find out all the default attributes that exist for editors? I seem to only be able to find that attributes exist, and then the specific pages for attributes, like, filepathattribute.location when I need them

waxen sandal
#

Reflection

#

Probably no doc page for them

split bridge
#

Wouldn't be surprised if Mikilo already had a reference page for them 🙂

opaque zenith
#

I like that singleton you shared. Have switched things over to it now to basically a projectmanager script with all my different menu items and things

#

now, where it says

    public void Log()
    {
        Debug.Log("MySingleton state: " + JsonUtility.ToJson(this, true));
    }

Can I do an ondestroy? Haven't actually checked if things like ondestroy happen in editor scripts

#

on application quit rather

opaque zenith
#

found it

#

and i guess you never need to unsubscribe from these type of events because the quitting unsubscribes? lol

waxen sandal
#

Yes

#

Not really unsubscribe more it doesn't exist anymore

opaque zenith
#

ya haha

#

I did mine a little different. This should still work right? Guess I can just test

#

oh guess it needs to be static

waxen sandal
#

Why do you need that?

opaque zenith
#

did it

#

uhh, nothing specific yet. Just thought it would be something fun to setup after that link

#

Might be nice to have for a controlled area to put all my intializeonload and potential persistent data between unity sessions

marble willow
#

I installed the vscode vibrancy extension
and when I start up vs, the background gets transparant for a second and then turns normal again

waxen sandal
#

Wrong channel

opaque zenith
#

if anyone was wondering, this worked perfect

gloomy chasm
waxen sandal
#

If you're using the API correctly you shouldn't hit these checks so it's "safe" to enable

#

Which makes it 20% faster on a large project

waxen sandal
opaque zenith
#

err well

gloomy chasm
waxen sandal
#

Large amount of objects

gloomy chasm
opaque zenith
#

for ease of seeing in inspector I would need to still create the scriptableobject?

waxen sandal
#

It wouldn't surprise me if we do more than a million Next calls

#

FilePath

#

If you create it in Assets you should just be able to select it

#

It'll automatically create it for you

opaque zenith
#

ohh cool. I'll look into that. Thanks guys

gloomy chasm
gloomy chasm
opaque zenith
#

I feel so like blah. I finished making this scriptableobject enum data thing days ago, but, now I'm trying to perfect it. I want to share it also, so trying to optimize it the best I can first

waxen sandal
#

To validate correct settings

gloomy chasm
#

Well that would do it I suppose.

waxen sandal
#

😄

opaque zenith
#

only a million? Get back to us when a million and 1. That's the real struggle

waxen sandal
#

A million is a very low ball estimate

gloomy chasm
#

I wouldn't be surprised if it was more than a million

waxen sandal
opaque zenith
#

haha I know. I just wanted to act cool and be a part of the convo

waxen sandal
#

Get it working, get it working well and you're done

gloomy chasm
opaque zenith
#

I'll try to get back to you soon on that! I broke up a lot of code before I went to bed last night, so putting it back together right now with some of this new info

#

Admittedly I need to get better at version control

#

because I keep breaking working things

opaque zenith
#

is this the correct way of accessing both editor and scriptablesingleton<T>

#

Guess I can just use filepath without inheriting from scriptablesingleton?

waxen sandal
#

Probably nit

wispy delta
#

I have just discovered the DrawGizmos attribute which should let me draw gizmos from an editor instead of from within a component, yay. The problem I'm running into is that Handles don't seem to be interactable from within the event, presumably because the Gizmos and Handles API are distinct 😫. I would just write the handle logic in MyCoolComponentEditor.OnSceneGUI, but I need them to be visible in the scene even when the object is not selected. I tried hooking into the SceneView.duringSceneGui delegate from the editor's OnEnable event function, but that requires you first select the object before the handles are always drawn. The key point here is that I need to use the Handles API, I need them to be interactable, and I need them to always draw. It's easy to draw gizmos always, but I cannot find a way to do it with handles 👍

autumn maple
#

Hey, anyone!

Is there a way to toggle Cloud Diagnostic through script?
I want to query the players before allowing crash reports and such to be sent automatically.

But I don't find anything in the API or on the web

waxen sandal
#

You should be able to load the settings file in projectsettings as Object (or the right type if you can find it) then change it using serializedproperties

waxen sandal
wispy delta
#

could FindObjectsOfType, but that would only give me the objects that exist in the scene when the assembly reloads

waxen sandal
#

Yes

#

You can keep searching for new ones though

#

You can't really have both

wispy delta
#

not sure if i wanna FindObjectsOfType every tick just to make sure all available components are having their handles drawn tbh 😦
since gizmos have the ability to be drawn even when the object is not selected, I was hoping I was missing something simple that would allow the same for interactable handles, but if that's not in the cards I'll move on

waxen sandal
#

@gloomy chasm @opaque zenith At least 40000 files, around ~200 scenes, 8000 complex scriptableobjects that have probably more than 300 valid serializedproperties and then all other assets and prefabs (which likely contain a similar amount)

waxen sandal
#

I also lied yesterday, it's more like 27% with unsafeMode @onyx harness @gloomy chasm

onyx harness
waxen sandal
#

You mean open the assets as text?

onyx harness
#

SO is supposed to be the easier and quicker way.
But, maybe if done cleverly, loading an asset as text (when available of course) and deferring it in a job/thread might multiply your workforce and then only load the asset in a SO when required in the main thread.

waxen sandal
#

Yeah I thought about that but it would mean a lot of rewriting and some things might not be as trivial to do

onyx harness
#

Trickier yes it is, less straight, but might be more powerful because of multithread

waxen sandal
#

This validation code has existed since before I joined, if I were to redo it I would probably do it byt ext

onyx harness
#

Then again, I don't know what kind of check you do

waxen sandal
#

A lot 😛

onyx harness
waxen sandal
#

Checking whether references are valid, whether we're not accidentally referencing a texture that should be in a spritesheet, whether the prefab is disconnected, and probably more

#

Then we also have a bunch of things for specific components, asset bundles, attributes that denote whether a property is required etc...

onyx harness
#

OK I see, well my conclusion is by text is potentially better

waxen sandal
#

Oh, giving good errors is probably harder by text as well since you'll have to figure out what object it belongs too etc...

#

Either way, by text is probably faster but harder to maintain

onyx harness
#

NG Missing Script Recovery checks for broken references, I do handle thousands of assets.
I did not implemented multithreaded algorithm, but I know it's a way if I want to scale up

#

Yaml is not hard to stupidly parse

#

You can easily find the 'path'

#

But it is not out of the box obviously

#

But hey, you did it already and it works

#

If it works, it works! Gj

waxen sandal
#

Exactly why I'm not in a hurry to rewrite it

opaque zenith
#

can you make a method that is a customtype instead of the class itself? Or is there a way to access an inspectorsGUI from other scripts?

#

Like, I know how to make custom editors automatically themself, but, have been wondering this

waxen sandal
#

What

onyx harness
opaque zenith
#

Sorry! When I use [CustomEditor(typeof())] is it possible to use this attribute on a method instead of the class?

onyx harness
#

no

waxen sandal
#

You can make your own attributes though if you meant that

opaque zenith
#

I need to learn that. You guys keep giving me more on the todo list haha

gleaming adder
#

the image gets rotated but half of it gets cut off

gloomy chasm
gleaming adder
#

It's a known bug since 2007 *Edit: it may be since 2013 and I got my dates wrong but let me double check

#

I'm just not sure if there's a "known" way to get around it

gloomy chasm
gleaming adder
#

thank you for looking at this, those two links describe the problem -- if you rotate using the rotatearoundpivot it is clipping to the original rect (which obviously cuts off part of the image if it's not a square)

#

I think the way to "fix" it would probably just be to draw it to a new texture and then try and rotate that before drawing it, but it's just a pain. No worries if you don't find anything thanks for checking!

gloomy chasm
gleaming adder
#

That's new to me I'll check it out thanks!

gloomy chasm
#

@gleaming adder And just because I had it up. This is the code for the RotAndPivot if that helps.

// Helper function to rotate the GUI around a point.
        public static void RotateAroundPivot(float angle, Vector2 pivotPoint)
        {
            Matrix4x4 mat = GUI.matrix;
            GUI.matrix = Matrix4x4.identity;
            Vector2 point = GUIClip.Unclip(pivotPoint);
            Matrix4x4 newMat =  Matrix4x4.TRS(point, Quaternion.Euler(0, 0, angle), Vector3.one) * Matrix4x4.TRS(-point, Quaternion.identity, Vector3.one);
            GUI.matrix = newMat * mat;
        }
gleaming adder
#

Thanks!

opaque zenith
#

okay, I fixed my problem by just copying the ScriptableSingleton over and changing its : ScriptableObject where T : ScriptableObject to : Editor where T : Editor

gloomy chasm
opaque zenith
gloomy chasm
onyx harness
#

Because he is not aware of CreateCachedEditor()

onyx harness
#

Or he has something malicious in mind

gloomy chasm
# opaque zenith ya that

I feel like whatever it is that you are doing, you either shouldn't be or you are going about it in a bad way.

opaque zenith
#

I'm not sure if malicious, but, I was using it to create scriptableobject data that was saved and loaded on recompiles and also take advantage of this filepathattribute you guys were talking about

#

but still learning this editor stuff didn't know about things like this createcachededitor

gloomy chasm
opaque zenith
waxen sandal
#

They are recreated when the code recompiles and properties are reapplied

#

But they won't persist between sessions

#

Nor if it's destroyed by e.g. deselecting

opaque zenith
#

yeah, so doing it this way I don't need an extra SO and instead just save this editor as the SO and maintain the customtype on it also

#

when I load back in the donkey kong remains

#

between sessions

#

but again, IDK if that is malicious?

waxen sandal
#

Nah

opaque zenith
#

okay, cool! Thanks guys! Enjoy the daily convo and help

gloomy chasm
#

In UITK I have an container with flex direction row. It has three children, the first two have set width while the last is a text field set to flex grow.
It seems the field is growing the the full width of the parent container, and completely ignoring that some of the width is taken up by the other two elements, so it goes offer screen. Any ideas why it does this, and more importantly how to fix it?

opaque zenith
#

then you can specifically constrain the textfield without anything happening to the other 2 elements

gloomy chasm
#

Flex grow should just grow it to take up the the available space in it's parent, but for some reason it is not registering that the other two fields are in-fact taking some of that space up.

opaque zenith
#

I've only messed with UI so much to the point I know it required more depth studying of it lol

gloomy chasm
#

UITK is a lot like web dev with XML+CSS if you are familiar with those.

opaque zenith
#

I am not. I shouldn't even really be working this deep into Editor stuff yet, but I find it so enjoyable

gloomy chasm
#

Yeah, it is really fun sometimes. Other times, like right now, I am in the 5th circle of hell...

ivory fulcrum
#

I DID IT! Thanks for all of your help guys!

#

280 lines of code, and I have a button that reimports textures in the correct format, crops out the extra transparent borders, and repositions it to be in the same place as before the cropping. All without modifying the original asset file (png or whatever format)

gloomy chasm
#

Yay! Nice job!

void shoal
#

Does anyone know how can I draw a custom inspector for a custom class which is not derived from mono behavior?I want to make this int field visible if allow sell is checked

gloomy chasm
opaque zenith
#

IDK if any of you are like me, but, tfw you wake up in the morning and close a 100 tabs in browser because of opening a new tab for everything you search for Unity

gloomy chasm
#

In UITK, I have a PropertyDrawer for a collection type. But I can't figure out how to update the elements in it on Undo/Redo. Any ideas?

opaque zenith
#

the last comment I think

gloomy chasm
opaque zenith
opaque zenith
#

PropertyField needs to be bound to a SerializedObject to show something. When creating a visualTree from CreateinspectorGUI(), the editor automatically binds the created tree to the inspected serializedObject. Any element added afterwards will need to be bound manually by calling Bind(serializedObject)

gloomy chasm
opaque zenith
#

oh okay cool

#

I'm just trying to help because i know there is sooo much info out there for things that google searches don't always give the desired results. I'm all about more eyes on something can help find things haha

gloomy chasm
next thistle
#

Hey so does anyone know where the xbox live configuration wizard is in unity 2021.3.11f1 personal?

steel spade
#

Does anyone know how to use sprite sheet as custom font in Unity? I have this sprite sheet and I want a text object in Unity to use this sprite sheet as the font.

ivory fulcrum
#

TextMeshPro

#

There are plugins as well that you can download from the asset store, but TextMeshPro is included

wispy delta
#

Is it possible to start an editor coroutine that persists domain reload? I'm a noob when it comes to build pipelines, but we're trying to make a routine that runs our build operation. The issue I'm running into is I think the coroutine is getting wiped when unity recompiles for a new build target and the domain is reloaded. This seems like something most build pipeline ppl probably have to work around, does unity provide anything to help in this matter? Or does the build operation need to get chunked up into distinct pre-build, post-build logic?

tldr: can I use an editor coroutine to author my build pipeline flow without the domain reload associated with recompiling for different platforms killing it?

onyx harness
#

You can't.

wispy delta
#

That was my fear, thank you for confirming. Do you have any advice or references on how to author a build pipeline knowing that your code will get wiped by domain reload?

onyx harness
#

Use EditorPrefs ou SessionState

#

Write a kind of serializable coroutine

#

Serialize it in the SessionState.
When it reloads, check SS if anything is available, boom deserialize then proceed

#

Easier said than done

wispy delta
#

thank you, that makes sense 👍

onyx harness
#

I have started to make my own coroutine a long time ago

#

I already planned on making it serializable

#

I never finished it

#

I don't know if it solves your issue

wispy delta
#

sounds like a tough problem to solve in a generic way, but I'd be your first customer 😉
as always I appreciate you sharing your expertise, I'll check out the link!

onyx harness
#

My pleasure

#

Several publishers use it for their publishing process

gloomy chasm
#

Re-asking my question from yesterday. Any ideas why a UITK element set to flex grow would ignore the width(defined in uss) of it's siblings and grow to take up the whole space of it's parent instead of whatever space is remaining?

ivory fulcrum
#

Is the element itself the container?

#

in HTML/CSS we often use nested containers to manage that sort of stuff

#

Though admittedly, it's been a long time since I've done HTML/CSS stuff

#

And I know I've seen some interesting behavior from HTML/CSS

gloomy chasm
#

The problem was that for some reason all of the elements had their flex shrink set to 0.

ivory fulcrum
#

That... does seem bizarre.

wispy helm
#

I made an editor script, am I allowed to show some screenshots in here or nah? 🤔

gloomy chasm
wispy helm
ivory fulcrum
#

Is there a way to set the thumbnail of a .asset file from Unity's C#?

onyx harness
#

Yes

zinc spoke
#

Is there a way to edit an array of a class (which is serialized) in a custom EditorWindow

onyx harness
#

Yes

zinc spoke
#

so not the Editor but actually the EditorWindow

#

how

onyx harness
#

SerializedObject

zinc spoke
#

I've tried

onyx harness
#

How hard?

zinc spoke
#

too much

onyx harness
#

Show me

zinc spoke
#

I get this error but I set the Serialized object in the OnEnable method

onyx harness
#

wavesProp is null, right?

zinc spoke
#

yeah

waxen sandal
#

waves is private and not serialized

onyx harness
#

Well, make it non null 🙂

zinc spoke
#

It works now thanks guys

onyx harness
#

Dont think the serializer orbits around Inspector.
The serializer is the ground for everything

zinc spoke
#

xD

ivory fulcrum
onyx harness
#

Do you know how to do it without code?

ivory fulcrum
#

No. nor with code. I found "AssetPreview.GetMiniThumbnail" and thought maybe I could use that to get the Texture2D and then use SetPixel32 to change the image to a proper thumbnail, and then use Apply, but the problem is that I don't know if there's an easier way nor if that method will give me the reference to the Texture2D or a copy

onyx harness
#

An asset is based on a script.
The icon comes from this script.

#

If you set an icon on this script.
The asset will reflect it.

ivory fulcrum
#

Hmmm. Well, I suspect that the original script doesn't implement that. Is it a magic method or a magic property/field?

onyx harness
#

No magic

gloomy chasm
ivory fulcrum
#

I don't think it's an SO

onyx harness
#

An asset is an SO

#

Somehow

gloomy chasm
ivory fulcrum
#

It's a game object saved as a .asset file and then a bunch of GOs added to it.

#

ahhh

#

But it derives from MonoBehavior? I don't have much experience with SOs

gloomy chasm
ivory fulcrum
#

No, I'm saying the script at root game object is a script that derives from MonoBehaviour

gloomy chasm
ivory fulcrum
#

Create a game object, save it as an asset, then open the asset and add game objects to it. Assign a monobehaviour script to the root game object, and you have what I have

gloomy chasm
ivory fulcrum
#

ahhhh

#

yeah, I goofed, it ends in .prefab

#

ok. I'm barking up the wrong tree

waxen sandal
#

Anyways there's still a m_Icon you can set

ivory fulcrum
#

Is the ObjectPreview the thumbnail?

gloomy chasm
#

Pick what gets the result you want.

ivory fulcrum
#

I guess the MiniThumbnail, but if I use that method to get it, can I change it?

#

like if I overwrite the pixels, and then apply, will that change the icon?

#

or would I want the cached icon?

onyx harness
#

probably cant on most

gloomy chasm
#

Yeah, and even if you can, I feel like that isn't a good thing to do. Using reflection to set m_Icon is probably what you want to do.

ivory fulcrum
#

So, as far as reflecting, is that in "GameObject" or "MonoBehaviour" or "Object"?

ivory fulcrum
#

Also, what type is m_Icon?

#

Wait... is m_Icon part of SerializedObject?

#

@gloomy chasm

honest vortex
#

hey guys, is there a way to draw a debug label in world coordinates, without adding any object to the actual scene? I'm trying Handles.Label but it seems to be only in regards to the camera?

gloomy chasm
opaque zenith
#

think I am using nameof(T) wrong? It was working at one point, but, now it is just returning the character T on valid methods instead of the name anymore

ivory fulcrum
#

MechWarrior99: I'm having trouble finding m_Icon. I'm not sure if it's part of SerializedObject/SerializedProperty, or Object, or MonoBehaviour, or what it's part of. Do you know where it is that I'm looking for it?

gloomy chasm
gloomy chasm
honest vortex
gloomy chasm
opaque zenith
onyx harness
honest vortex
opaque zenith
onyx harness
#

Naaah, I stopped helping people, I just drop one word or two once in a while

gloomy chasm
opaque zenith
gloomy chasm
# opaque zenith haha and because of you and other people in this channel, you guys always so hel...

Oh btw, I figured out how to search for and hide fields in the inspector based on their label. However I decided to put it on the "Maybe I will come back to this at some point" burner because the only way to do it is to set the target for the IMGUI Debugger, than get the draw/other commands.
But I also crashed unity 3 times while doing, and it seems rather unstable... Also of course doesn't work with UITK so would need another system for that.

#

My bad, I meant that for @onyx harness...

opaque zenith
#

I've been debating using more labels speaking of that

gloomy chasm
#

Too may replys in one spot for my brain 😛

opaque zenith
#

seems that using things like findassets with labels is the most superior way to findassets for example

gloomy chasm
opaque zenith
onyx harness
gloomy chasm
opaque zenith
#

Looking at playing around with LockReloadAssemblies if I'm creating and removing assets, is the creating of changing of a script the only time I need to actually have an assembly reloaded?

waxen sandal
#

Or deleting or moving

#

But it won't trigger so no need to lock them yourself unless you're doing something with code gen or something

opaque zenith
#

I keep getting scared to ask things like this. This works, but, is this a good way of writing something like this?

#

other parts if relevant to my question

#

I value you guys as really smart and things like this as a waste of your time, but, also you guys are the only people I feel like I can easily ask silly questions like this to

gloomy chasm
opaque zenith
gloomy chasm
#

Also, there is no reason to store the path in a serialized field if you have the GUID. If you want you can just cache it in a none serialized field. The GUID will never change for any asset, and getting the path from a guid is quite fast.

gloomy chasm
gloomy chasm
opaque zenith
gloomy chasm
#

Also, the only reason the GUID would not be valid is if the asset was deleted or manually edited like I said before.

opaque zenith
opaque zenith
#

whoops

gloomy chasm
gloomy chasm
#

I mean it doesn't matter now since you are removing the path stuff, but still.

opaque zenith
#

yeah, I just realized that now. Thanks for points that out, forgot to edit that

gloomy chasm
opaque zenith
#

it works because the path was valid in my testing haha

opaque zenith
gloomy chasm
opaque zenith
# gloomy chasm Ah yeah, I realized that after I sent the message.

I also did it this way instead of one of our previous ways we talked about on the check for the guid length because of the errors unity throws having mulitple classes with the same name I knew if I could just get exactly "EnumData" it would have to be the right script, though, after talking to you about this I haven't added any checks for namespaces

#

No one will actually delve this deep into this for a lot of these things to be a problem, however, I have fun thinking about what if and seeing if I can solve it haha

ivory fulcrum
#

I still can't find m_Icon

#

Are you sure it's m_Icon?

gloomy chasm
ivory fulcrum
#

Tried this:

if (sProperty is null)
            {
                sProperty = property;
                var iconProperty = sProperty.FindPropertyRelative("m_Icon");
                Debug.Log($"Type of Icon: {iconProperty.serializedObject.targetObject.GetType()}");
            }
#
if (sProperty is null)
            {
                sProperty = property;
                var iconProperty = sProperty.serializedObject.FindProperty("m_Icon");
                Debug.Log($"Type of Icon: {iconProperty.type}");
            }
#
if (sProperty is null)
            {
                sProperty = property;
                var iconProperty = sProperty.FindPropertyRelative("m_Icon");
                Debug.Log($"Type of Icon: {iconProperty.serializedObject.targetObject.GetType()}");
            }
#

and this:

#
Texture2D Icon
        {
            get => (Texture2D)IconFieldInfo.GetValue(rootObject);
            set => IconFieldInfo.SetValue(rootObject, value);
        }
        public LayerShrinker()
        {
            var goType = typeof(UnityEngine.Object);
            var goTypeInfo = goType.GetTypeInfo();
            IconFieldInfo = goTypeInfo.GetField("m_icon");
            Debug.Log($"m_icon is a {IconFieldInfo.Name}");
        }
#

I tried in place of UnityEngine.Object GameObject and MonoBehaviour

#

IconFieldInfo is readonly FieldInfo IconFieldInfo

#

I also tried the other way of getting the icon from PrefabUtility and modifying the resultant Texture2D and it's not "readable"

gloomy chasm
#

What is sProperty?

ivory fulcrum
#

sProperty is SerializedProperty sProperty and is assigned first with the property from OnGUI or GetPropertyHeight

#

Whichever is run first

#

basically both check if the value is null, and if so, sets it to the property passed to either method

gloomy chasm
#

You can't get fields like that from UnityEngine.Objects. You need to create a SerializedObject of the value and then get the m_Icon property from that

ivory fulcrum
#

That's what I tried in the first three snippets isn't it? or....

gloomy chasm
ivory fulcrum
#

SerializedProperty

#

I tried getting the SerializedObject and modifying that

gloomy chasm
#

Sorry I mean what type is the property of.

#

.intValue .floatValue etc.

ivory fulcrum
#

... oh you mean of sProperty.SerializedObject.targetObject?

gloomy chasm
#

No, I mean the sProperty it self

ivory fulcrum
#

I have no idea

gloomy chasm
#

What....

ivory fulcrum
#

I can tell you that sProperty.SerializedObject.targetObject is LayeredCharacterBehaviour

gloomy chasm
#

Then how are you expecting to get a field that is only on UnityObjects from it...?

#

You are in affect trying to get a Texture2D field from a float field. It is not possible at all.

ivory fulcrum
#

Ok. That makes sense, I need a SerializedObject for the root game object right?

gloomy chasm
#

It is like doing

float foo = 2.5f;
foo.m_Icon = new Texture2D();
ivory fulcrum
#

Ok

#

So how do I get the SerializedProperty or SerializedObject of the right type

#

sProperty is property in public void OnGUI(Rect position, SerializedProperty property, GUIContent label)

gloomy chasm
#

Just try getting the field from the serialized object since that is a serialized representation of a UnityEngine.Object

ivory fulcrum
#

I did that in snippet 2

#
if (sProperty is null)
            {
                sProperty = property;
                var iconProperty = sProperty.serializedObject.FindProperty("m_Icon");
                Debug.Log($"Type of Icon: {iconProperty.type}");
            }
gloomy chasm
#

What is the serializedObject of in this case?

ivory fulcrum
#

But if I'm understanding you correctly, that's not right because that's the serializedObject for LayeredCharacterBehaviour which is a script attached to the root game object of the prefab

#

serializedObject is the serializedObject of the serializedProperty of the LayeredCharacterBehaviour class which derives from MonoBehaviour and is the attached script of the root game object of the prefab

gloomy chasm
#

Looks like MonoBehaviors don't have it. I just tested it with prefabs and ScriptableObjects and it worked fine.

ivory fulcrum
#

Is there a way to get the SerializedObject of the prefab rather than the MonoBehaviour?

#

If all you have is the latter?

gloomy chasm
#
var comonent = (MonoBehavior)sProperty.serializedObject.target;
using (var prefabSerializedObject = new SerializedObject(comonent.gameObject) 
{
    var iconProperty =prefabSerializedObject.FindProperty("m_Icon);
}
#

There you go @ivory fulcrum

ivory fulcrum
#

Alright, I'll try that.

#

Thank you

#

Oh. One last question. m_Icon, is that a Texture2D or something else?

gloomy chasm
#

yup

ivory fulcrum
#

Hmmm. It's null.

#

Do I just assign it?

#

as a new texture2d?

gloomy chasm
ivory fulcrum
#

iconProperty.serializedObject.targetObject = (UnityEngine.Object)rtex.ToTexture2D(); the object is read only?

#

rtex is a render texture

#

is this what I want?

iconProperty.SetGenericValue(rtex.ToTexture2D());
#

n/m that's Naninovel specific

#

And it's only for generics

#

you can't assign to targetObject because it's readonly

#

And it's null

gloomy chasm
ivory fulcrum
#

because it's null

#

iconProperty.serializedObject.targetObject is null == true

gloomy chasm
#

Show me your code please.