#↕️┃editor-extensions

1 messages · Page 43 of 1

visual stag
glass kiln
#

but its important heal comes after an attack

#

ahh ok sorry

smoky radish
#

Hey guys,
I have 2 questions. Is there any ways to strict array size in inspector ? without writing new PropertyDrawer. Like the array size should be always 10 and can't change the size in inspector.

Another one is, how can I check if someone wants to use my PropertyAttribute with array field ? (Like showing a warning next to that field name in inspector when array field uses that specific PropertyAttribute)

visual stag
#

You could use OnValidate to ensure that the size is correct

distant atlas
#

anyone know what the name of this built-in style is? also, isn't there a way to get the built-in styles apart from UnityEditor.EditorStyles, I remember there's a method for it but I can't recall the name

onyx harness
#

@distant atlas breadcrumb

distant atlas
#

just "breadcrumb"

#

?

onyx harness
#

guieditor.breadcrumbleft

#

guieditor.breadcrumbmid

distant atlas
#

ok thanks

onyx harness
#

Google "Unity editor styles viewer"

#

@smoky radish In your SP you have propertyType. I use it to know if my drawer is targeting the right type.

#

And about your warning, you should look at property decorators.

neat shadow
#

Hey everyone

#

I'm trying to write my own behavior tree editor window that works similar to the Animator window with nodes and connections

#

I have the window created and the graphing part done, but I'm struggling with loading the graph based on the selected asset

#

if anyone could point me in a direction for a tutorial or documentation on this stuff that would be great

#

I'm thinking about using a simple json file to store and load the tree

waxen sandal
#

I'd just use a scriptable object

neat shadow
#

I think I'll go that route

#

I think if I use a scriptable object I can pull it in through Selection.activeObject?

waxen sandal
#

No

#

Oh wait

#

You can

brittle cosmos
#

I put this in general, but maybe it should rather be here ---
So I'm clearing stuff from the editor like so:

for(int i = content.childCount - 1; i >= 0; i--)
    DestroyImmediate(content.GetChild(i).gameObject);

Suddenly I'm getting the error Destroy may not be called from edit mode! Use DestroyImmediate instead.
Which doesn't make any sense

onyx harness
#

It is common to not use Destroy but DestroyImmediate during editor time.

brittle cosmos
#

That's the problem, I'm clearly using DestroyImmediate, but still getting an error about using Destroy

onyx harness
#

Which version of Unity are you using?

#

One of the comment states "You are strongly recommended to use Destroy"

#

And I am using U2017.4

brittle cosmos
#

2019.1.3

#

As I understood DestroyImmediate is used during editor, and Destroy for in-game

onyx harness
#

Reproduce the bug in an empty project and report the bug

brittle cosmos
#

Yeah I guess I could try. Not sure I can though, it was working fine, then just suddenly started happening.

distant atlas
#

@brittle cosmos check the callstack the next time you get that error, so you can see what line of code from your script caused it

brittle cosmos
#

It's literally on the line DestroyImmediate(content.GetChild(i).gameObject);

#

That's it

#

Oh actually above that it in the call stack it has UnityEngine.Object:DestroyImmediate(Object)

#

But that doesn't really make much more sense.

distant atlas
#

hmm weird. your script is in an Editor folder, right?

brittle cosmos
#

Ah well I have an editor script for a MonoBehaviour (in an Editor folder), which show a button that calls a function on its MonoBehaviour

distant atlas
#

I mean the script that calls DestroyImmediate, it's in an Editor folder? and is it in an Editor class, or an EditorWindow class?

brittle cosmos
#

It's an Editor class for a MonoBehaviour. But the monobehaviour which actually calls DestroyImmediate is not in an editor folder

#

The Editor is in an Editor folder, which is inside another folder, but as I understand it's ok to have those in subfolders.

#

I guess an import point is that despite getting this error, the objects are actually being destroyed

neat shadow
#

anybody know how the lines are drawn in the animator window?

#

for the transitions

midnight edge
#

anyone else getting IL2CPP compilers stuck during a headless CI build on Windows Server?

latent bridge
#

Hi Guys! I am trying to do,I have 2 scenes (scene 1 and scene2), in scene1 I have 4 switches that light a bulb that is in the scene2, I do not know how I can change the state (on or off) of that bulb knowing that I have the switches (which are buttons on a canvas) in the other scene, I hope someone can help me

prisma chasm
coral verge
#

hello, does anyone know how to change the syntax theme in visual studio?

distant atlas
#

this is just an spontaneous thought but can you use DOTS in editor scripts?

onyx harness
#

I really feel this is very edge case X)

#

In which world would I need supa power in the editor world

split bridge
#

I'm working on a tween library - being able to preview at edit-time would be super powerful. Unfortunately it's not really supported at the moment. You can create a World at edit time but afaik trying to get systems to run in the same way as at playtime is v difficult.

wispy delta
#

@split bridge I agree it might not be the easiest thing, but if you are updating tweens yourself you could try plugging in to the EditorApplication.update delegate. You could also look at the Editor Coroutines package.

split bridge
#

thanks @wispy delta - sorry this is specifically with ECS (which is what I took SWS's question to be about) - previously had no luck at updating a series of systems at edit-time

onyx harness
#

What is your issue? O_o

#

Oh

wispy delta
#

Ah I gotcha @split bridge
@distant atlas I don't think know if you can do ECS in the Editor but you can definitely run jobs

onyx harness
#

I don't understand why people need ECS in Editor?

#

What is the purpose? 🤔

wispy delta
#

There might be some edge case but yea idk why you'd wanna do that either. Jobs are very useful for expensive operations tho

#

I guess a good reason is if you want to preview something that is normally done at runtime

split bridge
#

I agree it's not that common but the reason I commented was to provide an example - being able to design & preview a complex tween at edit-time using the exact same systems as at runtime (to ensure parity) would be very useful

#

Other uses include things such as timeline workflows

hoary marten
#

hi all, Can I print color text on the console?

whole steppe
regal jasper
#

you can also use the explicit name for the ones that exists in UnityEngine.Color (color=red, color=blue, etc)

whole steppe
#

Can IMGUI be mixed with UIElements?

craggy kite
#

yes, there's a UIElements container that can run IMGUI

whole steppe
#

oh good i don't need to rewrite my propertydrawers 😺

distant atlas
#

@wispy delta sorry I didn't realize I got replies. when I said DOTS I guess I was really just referring to jobs, so I guess that answers it then. in one of my prototypes I'm doing some heavy number crunching that I want to cache to a file instead of having it computed in runtime, but I wanted to take advantage of multicores to make it even faster

wispy delta
#

@distant atlas Coolio. Yea jobs behave exactly the same way in the editor as they do at runtime. The only minor annoyance is working with native arrays/collections. You have to dispose them whenever unity compiles or switches between play mode or edit mode. If the native arrays are stored on monobehaviours you can just add the ExecuteAlways attribute and allocate in OnEnable and deallocate in OnDisable that'll prevent any leaks from playmode changes or recompiling

distant atlas
#

alright, thanks for the tip!

crystal laurel
#

Might be a bit of a dumb question, but I've got an array as part of an inspector script, that I populate during OnEnable() (Well, run a function to populate it during OnEnable) - it's then displayed as a pop up - this works (mostly) fine when running in edit mode, however, when I enter play mode, I get a lot of NullReferenceExceptions, and the pop up doesn't display within the inspector. I've tried serialising the array w/ [SerializeObject], along with making it a public object. Only thing I've yet to try is setting it as dirty. But I'm not sure if that'll work?

#

Quite confused as to how to resolve this, and fix it!

onyx harness
#

What is null?

crystal laurel
#

The array, it seems. The null reference exception comes from line of code I use to set up the pop up/dropdown: SelectedIndex = EditorGUILayout.Popup("Voice to use: ", SelectedIndex, SpeechNameArray);

onyx harness
#

Just check why SpeedNameArray is corrupted

sterile spire
#

is SpeechNameArray a static or a local variable on your editor script?

#

you could try making it static (if it is not), hope it works!... and don't forget to initialize it OnEnable

timber coral
#

I'm trying to create an Importer for Lego LDraw files. They are essentially mesh files but can contain references to other LDraw files. So the 2x4 brick LDraw file can use the Box LDraw file and Stud LDraw file to create it's mesh. I've tried creating:

  1. ScriptableObject for the LDraw file
  2. ScriptedImporter for importing the LDraw files
  3. AssetPostprocessor which combines the mesh created directly from the file with the meshes in the files that are being referenced.
    The AssetPostprocessor then sets completedMesh in the LDraw scriptable object. This seemed to be working, but sometimes I had to re-import the files to get completedMesh to be created. After researching it seems like I may be doing this wrong, and that the LDraw asset cannot be changed after being imported, even in the post processor. Is that right?
wild star
#

Why do values reset when you click off a script with a custom editor?

wispy delta
#

How are you setting the values from the editor?

wild star
#
public class CameraOverideEditor : Editor
{
    CameraOverideArea _CameraOverideArea;
    private void OnEnable()
    {
        _CameraOverideArea = (CameraOverideArea)target;
        if (_CameraOverideArea._Position == Vector3.zero)
        {
            _CameraOverideArea._Position = _CameraOverideArea._Colider.bounds.center - (Vector3.forward * 6);
            
        } 

        if (_CameraOverideArea._Colider == null)
        {
            _CameraOverideArea._Colider = _CameraOverideArea.GetComponent<BoxCollider>();
        }
    }
    [SerializeField]
    Vector3 Up;
    [SerializeField]
    Vector3 Forward;

    private void OnSceneGUI()
    {
        _CameraOverideArea._Colider = _CameraOverideArea.GetComponent<BoxCollider>();
        Vector3 NewPos = Handles.PositionHandle(_CameraOverideArea._Position, Quaternion.identity);

        if (_CameraOverideArea._Position != NewPos)
        {
            Vector3 _Change = NewPos - _CameraOverideArea._Position;
            _CameraOverideArea._Position = NewPos;
            Up += _Change;
            Forward += _Change;
        }

        NewPos = Handles.PositionHandle(Up, Quaternion.identity);
        if (Up != NewPos)
        {
            Up = NewPos ;
        }

        NewPos = Handles.PositionHandle(Forward, Quaternion.identity);
        if (Forward != NewPos)
        {
            Forward = NewPos;
        }

        _CameraOverideArea._CameraUp = Up - _CameraOverideArea._Position;
        _CameraOverideArea._CameraForward = Forward - _CameraOverideArea._Position;
        Handles.color = Color.blue;
        Handles.DrawLine(Up, _CameraOverideArea._Position);
        Handles.color = Color.red;
        Handles.DrawLine(Forward, _CameraOverideArea._Position);

       ```
#

with handles

wild star
#

I fixed it

#

by making Up and Forward variables of the MonoBehaviour

arctic cove
#

ok, i'm still not very good at unity, just finishin up the 2D platformer tutorial, but i want some help with a piece of code i'm tinkering with

#

all that I am trying to do is delete some objects once they have fallen out of the general game area

#

my idea was simply to make them delete themselves after going below a Y value on the map

#

this is what I have so far:

#

hang on has the code appeared yet?

#

because i can't see it on my end

wispy heart
#

it disappeared

arctic cove
#

let me try a screenshot instead

onyx harness
arctic cove
#

here we go

#

oh sorry

onyx harness
#

@arctic cove but to answer you, I don't see any error, what is happening?

arctic cove
#

They’re just deleting themselves immediately

#

Actually let me double check some things

onyx harness
#

It just mean your transform is low at start

arctic cove
#

@onyx harness actually no I figured it out

#

I used gameobject which caused ALL of the objects to be destroyed

#

Sorry I should probably take this to general programming

shadow orchid
onyx harness
#

Setting it programmatically?

brittle cosmos
#

Is there a good way to calculate rects for EditorGUI.PropertyField?

#

eg. placing two properties under each other, is there some built in stuff to calculate offsets, spacing, etc.?

#

Well I found EditorGUIUtility.singleLineHeight and EditorGUIUtility.standardVerticalSpacing

#

I guess you just have to do the rest manually?

brittle cosmos
#

Editor script is useful, and pretty powerful, but seems kind of inaccessible.

#

It's mostly in the documentation but I haven't found it very useful. And other information in the internet is scattered.

#

Maybe that's just me though?

onyx harness
#

A lot of try and try and search

#

@brittle cosmos have you tried GUILayoutUtility.GetRect?

brittle cosmos
#

I have not. Thank you, that looks useful

onyx harness
#

This method is to reserve a space in the GUI layout world.

lone quarry
#

So... if I try to save a scriptableObject, should I use EditorUtility.SetDirty? In the Documentation it said that this function should be avoided

#

*in an Editor window

onyx harness
#

I don't find anywhere your statement

#

can you drop the link?

onyx harness
#

I've search for the word window, there is none

lone quarry
#

what?

onyx harness
#

oh you are talking about Editor

#

Not EditorWindow

lone quarry
#

no

#

I want to save some scriptableObjects from an EditorWindow

onyx harness
#

It doesnt say to avoid it 🤔

lone quarry
#

well it says "The only remaining use (which is used rarely) happens if a non-scene object is modified with other means and with no added undo entry. Use of this approach is unlikely."

onyx harness
#

Rare does not mean to avoid.

lone quarry
#

so... should I use it then?

onyx harness
#

I am misreading unlikely maybe XD

lone quarry
#

😄

onyx harness
#

Yes you can.

#

I do use it in my stuff

#

Never had an issue for now

regal jasper
#

@lone quarry basically you can avoid using that by using SerializedObjects instead, this way you will be properly supporting undo/redo

lone quarry
#

Oh ok, thank you

#

then I'll just keep using it 😄

onyx harness
#

But it really depends on what you are trying to do

#

SerializedObjects might be overkill for many tasks

lone quarry
#

I'm just trying to save ScriptableObjects nothing else

onyx harness
#

Well it should be fine then

lone quarry
#

ok thanks! 😄

distant atlas
#

they way I see it, they're just trying to encourage people to use SerilaizedObject when editing, since that automatically handles recording to undo history for you

regal jasper
#

exactly, because by using EditorUtility.SetDirty (without doing others additional steps) will cause every action to be destructive

visual stag
#

The only time I would use SetDirty is if it's an asset that I don't want to record undos for

#

which is the circumstance they talk about using it for I think

brittle cosmos
#

So I've got an array of objects, each with a bool selected property.

#

eg.

#

I want only one to be selected at a time.

onyx harness
#

And what object are you working on?

brittle cosmos
#

If I just set SerializedProperty.boolValue in OnInspectorGUI will that mess with the undo/redo?
I've got serializedObject.Update(); at the start of OnInspectorGUI, and serializedObject.ApplyModifiedProperties(); but to be honest don't really know what exactly those do. Will they handle all that?

#

It's just an array of Serializable objects

#

My own custom classes

onyx harness
#

Have you tried? 🤔

#

Update() will look at the target and update its data to match.

#

Apply() will set the modifications to target

brittle cosmos
#

I will try, I was just wondering how undo/redo is handled

onyx harness
#

Oh you can try on simple case and see the result

#

No need to implement hardcore stuff

#

And I might even say, never do that

brittle cosmos
#

Actually, how would I do this - is there some way when using EditorGUI.PropertyField to tell if that property has been changed by the user?

onyx harness
#

EditorGUI.Begin/EndChangeCheck()?

#

@brittle cosmos

brittle cosmos
#

Thanks, that's it

brittle cosmos
#

Ok so another problem I'm running into:

#

It seems like editors are created new every time you select the object

#

Which is unexpected, but fine I guess

#

Problem is it seem like there are two instances

onyx harness
#

Oh you don't imagine how works the Editor under the hood XD

brittle cosmos
#

The screen shot above is me selecting it three times

waxen sandal
#

They can't really keep the editor cached for the life time of the application

onyx harness
#

Is it an issue?

waxen sandal
#

So it's better to be consistent and recreate it

brittle cosmos
#

It is an issue. I'm still busy with the thing I was trying to do above, keeping only one item selected at a time.

waxen sandal
#

This is why you have serialization

brittle cosmos
#

So I thought I could store a reference to the currently selected item in editor class, then unselect when a new one is selected. Problem is it seems like there are two editors running, and so only one is updated

#

I can understand recreating it every time, but having two running at the same time is a problem.
Is that expected, a bug, or just something I'm doing wrong?

sterile spire
#

what usually works for me is setting everything that must be remember as static, initializing it OnEnable, and erasing it (if necessary) OnDissable... and I put everything that must be persistent between sessions as serialized information on the editor's target's script

brittle cosmos
#

aah, smart.

sterile spire
#

you can also make every method static, and pass the target as a parameter... so you can have some kind of reusability, coz as far as I know, you can't have two editor scripts running at the same time DX

onyx harness
#

@sterile spire @brittle cosmos Unfortunately, this is wrong.

#

You can have multiple same Editors running in the Inspector.

#

If you have 3 Colliders on a GameObject, you will end up with 3 Editors.

sterile spire
#

just tested it... and that's true O_O

#

but the scripts must be on the same game object... is there a way to activate the editors of the children? or... of another game object, at the same time?

onyx harness
#

Nope

#

The Inspector has a ActiveEditorTracker that create and manage Editors internally

#

It stays in the scope of the selection.

brittle cosmos
#

a static field solves my problem though. I'm not really sure what else to do because there are two editor instances running for a single component.

onyx harness
#

How do you know that?

#

How do you list them?

#

Because, you need to know, whenever you select a GameObject, 1 + N Editors are created.
1 for the GameObject, then N for the Components

#

That's maybe why you see 2 new Editors

#

In order to help you, I need to know the target of your listed Editors

#

To ensure your debugs are not misguiding you.

brittle cosmos
#

So in the screenshot I posted above. I'm logging the instance id on enable. I only have one component, but get six OnEnable selecting it three times.

onyx harness
#

Oh, you log it in OnEnable.

#

It means they all come from your custom Editor

#

And what happens in OnDisable?

#

Can you unlog? So you just keep a list of what is living

brittle cosmos
#

That's selecting the gameobject with my component once, then deselecting it.

onyx harness
#

😃

#

You got it

brittle cosmos
#

hmm, still don't understand why there are two though.

onyx harness
#

It seems strange yes.

#

Restart Unity

#

We never know

brittle cosmos
#

I'll try

#

Didn't help

onyx harness
#

If you don't mind, send me your stuff, I will check, otherwise, move on, I'm sure you have better things to focus on

brittle cosmos
#

True, true. static works for now, I guess no need to waste more time

#

Thanks

cloud wedge
#

is there a way to use AssetDatabase to get all assets in a directory or all assets in a directory of a certain type?

#

ah, FindAssets

#

I gotta say, if that's the right function, LoadAllAssetsAtPath is poorly named

onyx harness
#

Nope, LoadAllAssetsAtPath is very explicit

#

FindAssets should be better

cloud wedge
#

you can have a path to a directory

#

that function name could mean, "give me all the assets in this directory," but it can't be used that way

somber oxide
#

UIElements.ProgressBar doesn't seem to be able to be created via XML. It says that there's no factory for it. How come?

onyx harness
#

@cloud wedge while you are right, Unity never used Path in their API for a folder

#

If I remember correctly 🤔

cloud wedge
#

that's good to know

neat shadow
#

I'm trying to draw transition lines for a Behavior Tree between nodes. I would like it to look similar to the transition lines in the Animator window , but I'm not quite sure the best way to go about it.

#

I can use Handles.DrawLine() but I'm not sure the best way to show the direction of it

onyx harness
#

Can you screenshot me the transition line of animator? 🤔

neat shadow
#

I'm thinking it's a thick line with an arrow texture that rotates in the center?

#

I don't know of a good way to rotate an arrow?? or maybe this is a custom line drawer somwhere?

onyx harness
#

Using matrix stuff

#

This one way I know to do it

distant atlas
#

there's some utility function somewhere that rotates

#

I'll try to find it

calm thistle
#

Hello ! I'm working on UIElements and I try to set ObjectField.objectType from UXML. It's working right now, but I have to specify Namespace + Class + Assembly to make it work with Type.GetType()
(object-type="UnityEngine.UIElements.VisualTreeAsset,UnityEngine.UIElementsModule")
Is there a way to get rid of the Assembly part, like checking in every assemblies?

onyx harness
#

@calm thistle
If performance/time is not an issue for you:

private static Assembly[]    assemblies;

public static Type    GetTypeFromAll(string fullName)
{
    if (assemblies == null)
        assemblies = AppDomain.CurrentDomain.GetAssemblies();

    for (int i = 0; i < assemblies.Length; i++)
    {
        Type[]    types = assemblies[i].GetTypes();

        for (int j = 0; j < types.Length; j++)
        {
            if (types[j].FullName == fullName)
                return types[j];
        }
    }

    return null;
}
calm thistle
#

visual stag
#

I think I misunderstood the question, assuming you were talking about a UXML thing

onyx harness
#

(Funny enough, a dude on unitydev Slack asked the exact same thing yesterday, I just copy pasted)

visual stag
#

Why would you want to do it this way instead?

onyx harness
#

@visual stag I noticed that X)

calm thistle
#

The reason is I'd like to get editor windows from uxml+uss only

visual stag
#

ah, so it is a UXML thing? It's just weird because in c# land we have easier access to the type

#

Why wouldn't you just do typeof(VisualTreeAsset)? I feel I'm missing something

#

maybe that was an example or something...

calm thistle
#

It is, but the question is about Reflection (getting a fully qualified type name form text)

#

I have the type from a string in UXML so I must convert it.

visual stag
#

Depending on your needs there is also

Unsupported.GetTypeFromFullName```
But I suppose that's harder to debug if things don't work out, and is Editor-only. But it's good to know about
onyx harness
#

Haha never noticed this one, shit (Good catch)

calm thistle
#

Editor-only is ok 😃 Thank you !

cloud wedge
#

I want a button on the screen that is only there for ease of development so it shouldn't be there in the actual build. How do I achieve that?

#

there's an EditorOnly tag. Is that exactly what it does?

#

googled and it is

onyx harness
#

Yes

languid raven
#

hello everyone, has someone alredy used pdb2mdb ?

onyx harness
#

Never had to, what is your issue?

languid raven
#

Can't generate a mdb file

#

Always throw an error : Invalid PE file

#

But i find a workaround

#

Use another pdb2mdb exe

#

Downloaded on github

#

It'z weird that the one provided by unity is bugged

rich gate
#

hi, i have an little issue when i try to import a sprite from path

#
GameObject.Find("Slot" +  z).gameObject.transform.GetChild(0).GetComponent<Image>().sprite = Resources.Load<Sprite>(Application.dataPath + "/Icons/Axe_01.png");
#

when i do that, my sprite is white

#

but the path is correct

#

and when i do

Debug.Log(Resources.Load<Sprite>(Application.dataPath + "/Icons/Axe_01.png").name);
#

the debugger say :

#

he don't see the sprite

#

but the path is correct

#

can you help me please ?

onyx harness
#

@rich gate The sprite is white because it is null (not found).

#

Confirm that the asset is setup as a Sprite in the Inspector.

rich gate
#

i have find another way

#

and that work

#

but

#

the sprite have mip map

#

and he is blurring

#

how can i disable the mip map in the sprite generation ?

onyx harness
#

@rich gate Use the other constructor to disable the mip map

rich gate
#

?

onyx harness
#

You see, you should follow my advice above X)

#

Gimme a sec

#

WWW().texture won't allow you to create the texture the way you want

#

You need to do it the proper way.

#

By properly setuping the asset in the editor

rich gate
#

i wish load dynamicaly the assets

#

only when needed

#

because the game will take the item ID, and get the icon path on a SQL

onyx harness
#

Replace Resources.Load<Sprite> with Texture2D

#

Tell me if it returns non-null

rich gate
#

the sprite isn't on the ressource folder

#

because i don't want to load at the game starting

onyx harness
#

If you want me to help you, you need to at least try what I am asking...

rich gate
#

he can't convert Texture2D to Sprite

onyx harness
#

Yep

#

Put that in a Texture2D variable just a line above

#

Don't set the sprite yet

#

If it is not null. Your asset is a valid Texture2D.

#

Then it means, you just need to correctly set it to Sprite in the inspector

rich gate
#

for Ressource.load, the asset need to be in Ressources folder
but i can't put in, he appear just one time, and after a restard, he dessapear

#

i'm not stupid...

#

i have already try the Ressources.load

onyx harness
#

Well for your information

rich gate
#

and Ressources are loaded at the game starting

onyx harness
#

Resources.Load() loads from any Resources folder

rich gate
#

i don't want that

onyx harness
#

Your asset is in Assets/Icons/

#

It can't be found by Resources

#

Hum..

#

You just wrote that above

#

If you know that, why is your asset still in Assets/Icons?

rich gate
#

i have make a Ressources folder before

onyx harness
#

and it was not working?

rich gate
#

and i have Debug.Log the lenght of the Ressources

onyx harness
#

You must have done something wrong.

rich gate
#

i have get 30 the first time

#

and after a restart

#

i get 4

onyx harness
#

How do you get the "length"?

rich gate
#

the first time i have get 30

#

the second, 4

onyx harness
#

What happened if you click through all of them

#

and play again?

rich gate
#

idk

onyx harness
#

Because Unity editor does not load effectively all the assets at start

#

If you click on them, Unity will load them and will "know" them. (Therefore appearing in the result of FindObjects())

rich gate
#

but another question

#

that work perfectly like that

#

but that add MipMap to the icon

#

how can i disable the mip map ?

hoary surge
#

import settings didn't work?

rich gate
#

import settigns don't load at start ?

hoary surge
#

import settings should be constant as far as I know

onyx harness
#

WWW is loading from a distant path.

#

It is not reading any import, since it is raw data.

hoary surge
#

public Texture2D(int width, int height, TextureFormat textureFormat = TextureFormat.RGBA32, bool mipChain = true, bool linear = false);

#

mipchain = false

#

also it's possible to convert texture2d to sprite

#

I've done it but I'd need to dig up the code.

onyx harness
#

He did that already

hoary surge
#

ahh

onyx harness
#

But since its texture is not properly set, he sees blur stuff

hoary surge
#

sorry late to the party

onyx harness
#

😃

hoary surge
#

I was wrestling with a BSP/DFS/BFS implementation in C# and the lack of pointers make me sad

onyx harness
#

DFS BFS?

hoary surge
#

So party = late

#

depth first search, breadth first search

onyx harness
#

stack pointer ?

#

Oh

#

I thought it was assembly by reading BSP X)

hoary surge
#

Honestly twas a interview question I choked on 😛

#

got home and had to sort it out

#

mainly because it was annoying

onyx harness
#

How good are they as lookup algorithm?

rich gate
hoary surge
#

DFS complexity is O(V+E) and Breadth first is O(|V|+|E|)

rich gate
#

no mip map !

#

thanks you @hoary surge

hoary surge
#

DFS and BFS are the 2 most standard tree algos that I know they vary on implementation though

#

hence why C# doesn't have a tree or graph structure

#

It's been like 20 years since I had to worry about trees, dfs or bfs though heh

rich gate
#

RGBA32 is the better format ?

hoary surge
#

It's larger

onyx harness
#

@rich gate this is what I told you about look out the other constructor XD

hoary surge
#

"Better" is up to the artist to decide along with the system requirements

#

well not that the artist dictates system requirements, but... that the system requirrements dictate what's possible

onyx harness
#

@rich gate also, I hope you don't plan on making it work on a build, because this code won't work outside the editor

rich gate
#

DXT5 is not lighter ?

onyx harness
#

It is.

hoary surge
#

DXT5 is compressed

#

so it should be smaller

onyx harness
#

But you need to fill its prerequisites

hoary surge
#

in theory but all compression algos have things they can't compress all that well

#

or a point at which things look like poo on a poo cracker

#

That looks like in game GUI you are making not designer stuff

#

and for that editor only is going to back fire on you

warped prism
#

If I have an editor field which expects an instance of the type's children, what would be the cleanest way to make the input?

#

Maybe wrapping it around an enumeration?

#

Is there something superior to that?

onyx harness
#

You are expecting an instance of a Type and you would like to wrap it around an enum? 🤔

#

What is the idea behind?

warped prism
#

there is a World singleton

#

which expects generator logic

#

dependency injection, I believe it is called

#

Now I might make them scriptable objects instead

onyx harness
#

If you want to make them persistent

#

it is good way yes

warped prism
#

they don't really have to exist past initialization

onyx harness
#

Still, they have to persist at some point no?

warped prism
#

how do you mean?

onyx harness
#

'they don't have to, past'
It means they have to, before X)

warped prism
#

well, yeah, they obviously have to exist during

#

but not after

whole steppe
#

do UIElements have something built-in for making text areas like IMGUI? if there is, i'm not seeing it.

#

I'm guessing I'll have to write a stylesheet for it

rich osprey
#

Does anyone know how to (or if it's possible) to draw a unity event in a custom propertydeawer? When I put my custom attribute over a unity event it basically removes the custom unity event inspector widget and just draws it as a series of properties

onyx harness
#

@rich osprey code code

rich osprey
#

what?

onyx harness
#

Drop some code if you would like more help

sage summit
#

Is it possible to set a custom Scriptable Object icon (usually located in Gizmos folder) dynamically by a property of Type Image provided within the class?

visual stag
#

@rich osprey

UnityEventDrawer eventDrawer = new UnityEventDrawer ();
eventDrawer.OnGUI (position, property, label);```
#

It also has a .GetPropertyHeight method

#

You'll find it in UnityEditorInternal

vast wadi
#

Hello guys. What i want to do is scroll the hierarchy window with the mousewheel while dragging an item.
What I have so far:

        EditorApplication.hierarchyWindowItemOnGUI += CustomScroll;
    }

    static void CustomScroll( int pID, Rect pRect ) {
        if ( Event.current.type == EventType.DragUpdated ) {
            Debug.Log("drag");
        }
    }```

Can anyone help me? Am I on the right track?
hardy locust
#

as i mean, build a server build from an editor script

urban monolith
#

How to properly delete .cs file? If i delte from vstudio it works fine, but if i delete from Unity it goes apesh*t and then vstudio starts throwing error "cannot add project to solution becuase project Game alrady exist"

#

and as soon as i launch unity editor with the file deleted it ruins the solution

#

so it throws error

sage summit
#

usually deleting in Unity should work as VS automatically should reload the project.

#

you could try deleting the .sln and .csproj files, as those will be regenerated new in unity

urban monolith
#

figured unity just ruins .sln by adding same project like 8-10 times for no reason so i just copied .sln from backup and that did the trick

warm jacinth
#

hey there, I made a quality setting level per platform we want to target for my game, and I created a quality setting preset file to save them. I would like to apply this preset just before building the game, so during runtime I can select the level depending on the platform. I've seen that you can use ApplyTo with a preset object, but it take an object in parameter. Where can I find the QualitySettings object? thanks!

#

Presets of type 'UnityEngine.QualitySettings' can't be set as default.

#

rip me

warm jacinth
#

I came to a workaround, loading the qualitysettings asset by code, and applying the preset on it

#
            SerializedObject qualitySettings = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath(qualitySettingsAssetPath)[0]);
            qualityPreset.ApplyTo(qualitySettings.targetObject);
            qualitySettings.ApplyModifiedProperties();```
deft sundial
#

hi

#

can somebody help on what to put in Object[] assets

#

wait this isnt the place

gray portal
#

Hello everyone, is there any way to make a script automatically include other scripts whenever I add it to a GameObject? So for example, if I have scripts A, B and C, I want to drag A to the GameObject I want and by adding it scripts B and C are also added.

onyx harness
#

@gray portal [RequireComponent]

gray portal
#

That easy, huh? Thanks! Follow-up questions:

  1. Can these scripts be added minimized? (In the above example, only B and C would be minimized)
  2. Can I control, through either inspector checkboxes or buttons, each script's state? E.G. by ticking a checkbox, I would disable B and vice versa.
#

Sorry if these are obvious, googling didn't show up anything.

onyx harness
#
  1. Not really, for that there is no easy solution, you need to dive into the Inspector & Editor code.
#
  1. Yes technically you can.
#

@gray portal

gray portal
#

@onyx harness Thank you for the info!

hardy mantle
#

Hi guys, do you know if there's any way to make a .unitypackage via script?
I.e. to automate the steps of Export package and then selecting a bunch of files manually?
It looks doable taking into account that unitypackage is basically tar.zip with assets+meta and path
But wanted to make sure there's not a solution already done

onyx harness
hardy mantle
#

doh, perfect, thanks!

deft sundial
#

how can i use BuildPipeline.BuildAssetBundleExplicitAssetName

#

any example?

midnight hollow
#

I'm into EditorScripting lately. Since we're working on 2D games with frame by frame animations managing sprites/animations was a pain in our last project.
Learning => making a AnimationClipCreator. Still rough around the edges, needs further adjustment, but I'm pleased with the results so far 😃

south pawn
#

how do i tell if an object is a folder?

#

or an asset is a folder

#

nevermind, got it, AssetDatabase.IsValidFolder(string path);

onyx harness
#

@hidden night This channel is not really used for advertising.

hidden night
#

hmmmm

#

sorry

onyx harness
hidden night
#

Okay Thx 😄

visual stag
#

@whole steppe just ask the actual question

zealous ice
#

We'd much rather have you ask "How do you add two ints in C#?" than "Can someone help me?"

#

For this dropdown? I would go with simple vertical layout group

#

Then you can populate it with dropdown labels or resource labels

#

I don't think there is a built-in feature for that

visual stag
zealous ice
#

Good idea, I missed it's existence

whole steppe
#

@zealous ice Thanks for suggesting the vertical layout group. Ill research this and how to use it .

heavy tiger
#

How to i make a popup dialog when i launch the editor but JUST when the editor is launched ?
I tried this:

[InitializeOnLoad]
public class Welcome : EditorWindow
{
    static Welcome()
    {
        Init();
    }

    [MenuItem("Example/ShowPopup Example")]
    static void Init()
    {
        Welcome window = ScriptableObject.CreateInstance<Welcome>();
        window.position = new Rect(Screen.width / 2, Screen.height / 2, 250, 150);
        window.ShowPopup();
    }

    void OnGUI()
    {
        EditorGUILayout.LabelField("This is an example of EditorWindow.ShowPopup", EditorStyles.wordWrappedLabel);
        GUILayout.Space(70);
        if (GUILayout.Button("Agree!")) this.Close();
    }
}```
The documentation claims that the [InitializeOnLoad] attribute works when the editor launches but 
1-  it also fire anytime the editor compile scripts 
2- when it fires on launch the dialog box fires before the editor so it sticks it self in the upped corner and dies when the editor comes after
onyx harness
#

@@heavy tiger Use time properties to define if you are on the very first frame.
So you are saying it instantly dies?

heavy tiger
#

well i dont know if it dies it just get covered by the editor but its not the problem, the problem is that i just want a popup window to apear when you launch the editor but the only thing i found to trigger the creation of this popup is [InitializeOnLoad] but it initialize every time something changes in the editor not just when it launch

#

i compile code, it fire the the initialize

#

i play the game it fires the initialize

visual stag
#

Mikilo suggested a solution to that

heavy tiger
#

i dont understand a time property ?

#

isn't there a event "editorLoaded" or a OnStart() for the editor ?

visual stag
#

No

heavy tiger
#

ok

visual stag
#

Give EditorApplication.timeSinceStartup a go

heavy tiger
#

ok i'll see

midnight hollow
#

Alrighty then. Finished my little AnimationClipCreator! :)
Since our workflow is based around frame by frame animations with packed Sprites (using TexturePacker!) this tool will come in handy for our next project(s)

What we can do:

  • drag either the packed PNG or the TexturePacker-File itself into the list
  • or select single sprites

The Creator loads each single Sprite-Assets which is packed, puts it into a list and sorts it by name. It#s important that the naming works, so each Sprite is put in the correct AnimationList, and by naming I mean the actual name and the indexnumber at the end.

Then the actual clips are created using the sorted animationlists and the settings (eather single or global), works pretty well now 😄

onyx harness
#

@heavy tiger Fyi this is what I have at launch :

Log
Time
time=0
timeSinceLevelLoad=0
deltaTime=0
fixedTime=0
unscaledTime=0
fixedUnscaledTime=0
unscaledDeltaTime=0
fixedUnscaledDeltaTime=0.02
fixedDeltaTime=0.02
maximumDeltaTime=0.3333333
smoothDeltaTime=0
maximumParticleDeltaTime=0.03
timeScale=1
frameCount=0
renderedFrameCount=0
realtimeSinceStartup=2.541775
captureFramerate=0
inFixedTimeStep=False

Log
EditorApplication
projectWasLoaded=NULL
editorApplicationQuit=NULL
projectWindowItemOnGUI=UnityEditor.EditorApplication+ProjectWindowItemCallback
hierarchyWindowItemOnGUI=NULL
update=UnityEditor.EditorApplication+CallbackFunction
delayCall=UnityEditor.EditorApplication+CallbackFunction
hierarchyWindowChanged=UnityEditor.EditorApplication+CallbackFunction
projectWindowChanged=UnityEditor.EditorApplication+CallbackFunction
searchChanged=NULL
assetLabelsChanged=NULL
assetBundleNameChanged=NULL
modifierKeysChanged=NULL
pauseStateChanged=NULL
playModeStateChanged=NULL
playmodeStateChanged=NULL
globalEventHandler=UnityEditor.EditorApplication+CallbackFunction
windowsReordered=NULL
contextualPropertyMenu=NULL
delayedCallback=NULL
s_DelayedCallbackTime=0
<>f__mg$cache0=NULL
<>f__mg$cache1=NULL
isPlaying=False
isPlayingOrWillChangePlaymode=False
isPaused=False
isCompiling=False
isUpdating=False
isRemoteConnected=False
scriptingRuntimeVersion=Legacy
applicationContentsPath=D:/Program Files/2017.4.24f1/Editor/Data
applicationPath=D:/Program Files/2017.4.24f1/Editor/Unity.exe
isTemporaryProject=False
timeSinceStartup=16.5604106733162
isSceneDirty=False
currentScene=
#

After a compilation:

Log
Time
time=1.930204
timeSinceLevelLoad=1.930204
deltaTime=0.3333333
fixedTime=1.92
unscaledTime=69.58876
fixedUnscaledTime=69.57855
unscaledDeltaTime=46.11824
fixedUnscaledDeltaTime=0.02
fixedDeltaTime=0.02
maximumDeltaTime=0.3333333
smoothDeltaTime=0.2737909
maximumParticleDeltaTime=0.03
timeScale=1
frameCount=10
renderedFrameCount=10
realtimeSinceStartup=74.30346
captureFramerate=0
inFixedTimeStep=False

Log
EditorApplication
projectWasLoaded=NULL
editorApplicationQuit=NULL
projectWindowItemOnGUI=UnityEditor.EditorApplication+ProjectWindowItemCallback
hierarchyWindowItemOnGUI=NULL
update=UnityEditor.EditorApplication+CallbackFunction
delayCall=UnityEditor.EditorApplication+CallbackFunction
hierarchyWindowChanged=UnityEditor.EditorApplication+CallbackFunction
projectWindowChanged=UnityEditor.EditorApplication+CallbackFunction
searchChanged=NULL
assetLabelsChanged=NULL
assetBundleNameChanged=NULL
modifierKeysChanged=NULL
pauseStateChanged=NULL
playModeStateChanged=NULL
playmodeStateChanged=NULL
globalEventHandler=UnityEditor.EditorApplication+CallbackFunction
windowsReordered=NULL
contextualPropertyMenu=NULL
delayedCallback=NULL
s_DelayedCallbackTime=0
<>f__mg$cache0=NULL
<>f__mg$cache1=NULL
isPlaying=False
isPlayingOrWillChangePlaymode=False
isPaused=False
isCompiling=False
isUpdating=False
isRemoteConnected=False
scriptingRuntimeVersion=Legacy
applicationContentsPath=D:/Program Files/2017.4.24f1/Editor/Data
applicationPath=D:/Program Files/2017.4.24f1/Editor/Unity.exe
isTemporaryProject=False
timeSinceStartup=91.9078805639157
isSceneDirty=False
currentScene=Assets/Plugins/NGTools/Demos/NGConsole/NGConsole.unity
#

Then when I play:

Log
Time
time=0
timeSinceLevelLoad=0
deltaTime=0.02
fixedTime=0
unscaledTime=0
fixedUnscaledTime=0
unscaledDeltaTime=0.02
fixedUnscaledDeltaTime=0.02
fixedDeltaTime=0.02
maximumDeltaTime=0.3333333
smoothDeltaTime=0
maximumParticleDeltaTime=0.03
timeScale=1
frameCount=0
renderedFrameCount=0
realtimeSinceStartup=1.050501
captureFramerate=0
inFixedTimeStep=False

Log
EditorApplication
projectWasLoaded=NULL
editorApplicationQuit=NULL
projectWindowItemOnGUI=UnityEditor.EditorApplication+ProjectWindowItemCallback
hierarchyWindowItemOnGUI=NULL
update=UnityEditor.EditorApplication+CallbackFunction
delayCall=UnityEditor.EditorApplication+CallbackFunction
hierarchyWindowChanged=UnityEditor.EditorApplication+CallbackFunction
projectWindowChanged=UnityEditor.EditorApplication+CallbackFunction
searchChanged=NULL
assetLabelsChanged=NULL
assetBundleNameChanged=NULL
modifierKeysChanged=NULL
pauseStateChanged=NULL
playModeStateChanged=NULL
playmodeStateChanged=NULL
globalEventHandler=UnityEditor.EditorApplication+CallbackFunction
windowsReordered=NULL
contextualPropertyMenu=NULL
delayedCallback=NULL
s_DelayedCallbackTime=0
<>f__mg$cache0=NULL
<>f__mg$cache1=NULL
isPlaying=False
isPlayingOrWillChangePlaymode=True
isPaused=False
isCompiling=False
isUpdating=False
isRemoteConnected=False
scriptingRuntimeVersion=Legacy
applicationContentsPath=D:/Program Files/2017.4.24f1/Editor/Data
applicationPath=D:/Program Files/2017.4.24f1/Editor/Unity.exe
isTemporaryProject=False
timeSinceStartup=102.622675942627
isSceneDirty=False
currentScene=Assets/Plugins/NGTools/Demos/NGConsole/NGConsole.unity
heavy tiger
#

Idk what this is

#

A cfg file but for unity ?

onyx harness
#

@heavy tiger Oh sorry, it is the values in the static class Time & EditorApplication.

#

Copy them in any text file and alt-tab them.
You will see what comes out

coarse hull
#

for a text area in a unityeditor window, how would I loop through the text and color specific parts specific colors in the text area?

visual stag
coarse hull
#

I've been searching for a while, can't find anything that makes any sense at all

#

because unity has 5 different ways to do the same thing via code that are in different namespaces, when talking about unity editor ui

onyx harness
#

@coarse hull Can you be more explicit? O_o

coarse hull
#

in what way?

onyx harness
#

"loop through the text and color specific parts specific colors"

coarse hull
#

"EditorGUILayout.TextArea"

#

how would I color different text in it different colors

#

example: looking for letter a, recolor to blue

#

rest is green

onyx harness
#

Isn't Rich Text enough?

#

It's not rocket science, just some tags to wrap

coarse hull
#

how do you use that in a text area?

onyx harness
#

The text you provide to TextArea(). It must be like this:
TextArea("<color=green>We <color=blue>a</color>re green</color>")

coarse hull
#

you can do that?!

onyx harness
#

The documentation vertx pointed to you is pretty explicit

#

Yep

coarse hull
#

I'm dumb

#

thanks guys!

onyx harness
#

I understand it is in the Unity UI doc, that's why you were disturbed

#

@coarse hull Make sure the style used by TextArea() has Rich Text enabled.

coarse hull
#

how do you do that?

onyx harness
#

As a last argument, you can provide a specific style to TextArea (or more generally, to any GUI methods)

coarse hull
#

oh that's what that means

onyx harness
#

If you provide none, the default GUIStyle for this GUI will be used

#

The one used by the editor is EditorStyles.textArea

#

And I just checked, and it is set to false by default

#

You need to create a copy of textArea

#

By doing :

GUIStyle style = new GUIStyle(EditorStyles.textArea);
style.richText = true;
#

Remember to always create a copy of a style, and never modify built-ins!

coarse hull
#

see this is why I am so confused

#

docs use this text = EditorGUILayout.TextArea(text, GUILayout.Height(position.height - 30));

#

then there are like 30 different ones

onyx harness
#

GUILayoutOption are different

#

It is just a convenient way to override UX details

#

GUIStyle gives the global rendering, and the options override some stuff

coarse hull
#

how do I put text into this? GUIStyle style = new GUIStyle(EditorStyles.textArea);

visual stag
#

You don't

onyx harness
#

You.. dont?

visual stag
#

you pass style to the TextArea function

onyx harness
#
GUIStyle style = new GUIStyle(EditorStyles.textArea);
style.richText = true;
EditorGUILayout.TextArea("<color=green>We <color=blue>a</color>re green</color>", style);
coarse hull
#

wait but I need a text area where I can put text into that is colored

#

ohhhhhh

#

🤦 🤦 🤦 🤦 🤦 🤦 🤦 🤦

#

thanks again xd

onyx harness
#

You need to lookup method overloads

coarse hull
#

I really do

onyx harness
#

@coarse hull Also, cache the style, don't create a new one every single frame

coarse hull
#

got it

coarse hull
#

@onyx harness for every OnGUI I have to loop through everything, remove all html stuff, then add new html back. Is there a simpler way to do color that isn't html? If there is html then I can't use html in what I am doing

onyx harness
#

I know no other technique to color text.

coarse hull
#

darn

visual stag
#

it's not html for a start, but just store the string and use a ChangeCheckScope to see if the string changes and alter it there

onyx harness
#

I would probably cache your colored text.

coarse hull
#

@visual stag but I just checked, CCS doesn't give a specific scope

visual stag
#

uhwhat

coarse hull
#

oh wait it does

#

but that wouldn't help

visual stag
#

Are you changing your string elsewhere?

coarse hull
#

I am making a colored script editor in unity

#

so if they modify stuff I need to remove and readd color anyways

visual stag
#

Is the only place your string changes in the TextArea?

coarse hull
#

yes, except color has to change the string currently

#

oh and when it loads the file

visual stag
#
using (var cCS = new EditorGUI.ChangeCheckScope())
{
    //text area here
    if (cCS.changed)
    {
        //colour and cache your text here
    }
}```
#

and also colour and cache your text when you load the file

coarse hull
#

but the issue is if they change text in a spot let's say (<c> means color):
<c>static</c>
they do this
<c>staatic</c>
that means it only modified in the middle, not allowing me to modify the color according (or remove it)

#

they can't see or modify html

visual stag
#

I really don't know what you mean

coarse hull
#

oh you are saying cache it for the next frame

#

@visual stag how would I handle using html?

visual stag
#

crying

coarse hull
#

like if I have html in the file, how do I make it ignore the richtext

#

while my color additions still working

visual stag
#

there is a way to generate strings that get ignored by the rich text parser, I'll see if i can find it

#

but it's a bit of a pain to be honest

coarse hull
#

if you could find it that would be great!

visual stag
#

I can't find the resources. But I think you can either replace the angle brackets with U+3008 and U+3009, or I think you can put another tag immediately after the opening bracket. Like this word is <<b></b>color=red>red<<b></b>/color>. I think I've done the latter one before, but I can't say if it scales or the pain points. That's why I mentioned crying 😛

onyx harness
#

Use this trick /⧸ XD

#

The second 'slash' is hidden, but will disable rich text

#

@coarse hull Oh crap, I think misunderstood what you were looking for...

#

TextArea is for editing text, not displaying it

#

-_-

visual stag
#

Yeah, I'm really not sure how it all works out

coarse hull
#

I am trying to display and edit

#

both xd

#

vertx I already found both sites that said those two things, neither would work

visual stag
#

If the text area is really wigging out during editing you could use a textArea when the user is editing, and then use something with that style when you're not. Whatever you end up doing it doesn't sound very friendly 😛

coarse hull
#

-_-

visual stag
#

lol that longer face got bot'd?

onyx harness
#

I just tried TextArea with rich text, it works, but it is obviously not convenient at all to use

coarse hull
#

exactly

#

doesn't help that stuff randomly highlights everything

onyx harness
#

But clearly

#

Your way of doing it is wrong

#

You can't display '<tag></tag>' and apply itself to itself

#

By design, your idea is wrong

coarse hull
#

?

#

what do you mean?

#

How do you edit a text area from code while the user is editing it?

mystic swift
#

How can I propagate an RGB value to sprites, and then have each sprite modify it according to its own desires for Saturation, Brightness and Opacity? In editor, so that this can be done dynamically, like a sprite theming mechanism.

smoky radish
#

Hey guys,
if you are interested I've published 2 repositories for showing ScriptableObjects in dropdown menu in Inspector as a PropertyAttribute, this one for selecting between ScriptableObjects and this one for multi selecting.

deft sundial
onyx harness
#

@mystic swift get the texture, GetColors() from the texture, replace the colors you want, SetColors(), Apply.

#

@smoky radish you did it! 😇

mystic swift
#

@onyx harness Sorry. I have no idea what texture you're talking about.

onyx harness
#

@mystic swift Texture is the base of a Sprite

#

Sprite comes from a Texture

#

@deft sundial i've never seen a question that is so clueless

mystic swift
#

@onyx harness I don't think that has anything to do with what I'm asking about. Imagine a colour component script attached to a master object. Changing its value changes the sprite renderer colour of a dozen or so "children", each of whom sets their own opacity, saturation and brightness upon this base RGB value they've "taken" from the master.

#

Because RGB is the language of Unity, yet I'm wanting to use that only as a Hue, and then act within each "child" sprite based on that Hue, and change to various levels of saturation, brightness and opacity from that Hue, there needs be some.... here's where I'm confused.

onyx harness
#

@mystic swift lol, that is lightyears from what I understood X)

#

Look for OnValidate()

mystic swift
#

@onyx harness Cheers!

smoky radish
#

@onyx harness Yup 😄 That was some weeks which I wanted to publish it on github. Thanks for your help. I appreciate. What is your github id ?

onyx harness
#

@smoky radish Github id? I almost never use GitHub but here is mine: Mikilo

#

I don't know if it helps you X)

opaque lion
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagment;

public class MainMenu : MonoBehaviour
{
   public void LoadScene()
    {
        SceneManager.LoadScene(NormalWorld);
    }
}
#

Assets\Lifexplorers\Nature\Scripts\MainMenu.cs(4,19): error CS0234: The type or namespace name 'SceneManagment' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)

#

Any help?

onyx harness
#

Management

#

Not Managment

opaque lion
#

OH

#

OK

#

Ok now I got another problem

#

I'm watching this tutorial and theres no MainMenu.LoadScene

#

2:13 to be exact

#

I followed the same steps

#

Halp

onyx harness
#

Because your GameObject has no MainMenu Component on it? O_o

opaque lion
#

What?

#

You mean my canvas?

onyx harness
#

I guess yes

opaque lion
#

It's there.

#

Bottom One

#

I know none of this stuff

#

What do I do :c

onyx harness
#

What about your MainMenu code?

opaque lion
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour
{
   public void LoadScene()
    {
        SceneManager.LoadScene(NormalWorld);
    }
```}
#

Also this is whatever I got in the console

#

Assets\Lifexplorers\Nature\Scripts\MainMenu.cs(10,32): error CS0103: The name 'NormalWorld' does not exist in the current context

#

The NormalWorld scene exists and is in the build along with all world types

onyx harness
#

lol

#

It is normal

#

This error is a compilation error.

opaque lion
#

Huh?

onyx harness
#

It means, your script is not up to date

opaque lion
#

The scene name is NormalWorld

onyx harness
#

You need to fix it

opaque lion
#

WELL GOD FUCKING DAMN IT

onyx harness
#

You forgot quotes then

opaque lion
#

I GOTTA UPDATE UNITY

#

I HAVENT UPDATED IT IN 8 MONTHS

onyx harness
#

"NormalWorld"

opaque lion
#

It had no quotes

#

It's whats inside the qotes

#

quotes

onyx harness
#

Updating Unity is nothing related to your issue

opaque lion
#

oh

onyx harness
#

NormalWorld in your code is a variable

#

But you never declared it anywhere

#

It does not exist

#

That's why

opaque lion
#

How do I make it a variable

#

Or declare it

onyx harness
#

What is the tutorial saying?

#

I can't guess X)

#

If you tell me your scene is named NormalWorld

#

Just quote it

opaque lion
onyx harness
#

SceneManager.LoadScene("NormalWorld");

opaque lion
#

Oh

#

IT WORKED

#

THANK YOU

#

Now I gotta copy and paste this process for 4 other world types

#

oof

onyx harness
#

Your tutorial is showing LoadScene(1)

visual stag
nimble stag
#

Hello,
I have a question about linked objects with other objects. The point is that I have a door that has a controller with a button to open it and the button is still linked to another object that the button allows / disables and I need something that would somehow make the line of connected objects visible. Is this possible? It occurred to me to do it through EditorWindow and in that somehow write down the objects, it would probably be, but rather if something does not exist on this one.

burnt tulip
#

can i ask for help here?

vestal perch
#

@burnt tulip just ask, if anyone will be able to help, they will answer

burnt tulip
#

I just started using Unity 2019.2.0b5 version. I got this problem when i create a script in unity and try to open it with VS17, the page is blank. The older versions of unity works just fine with VS. I cant seem to find a fix for this problem. If someone knows the problem plz help 😃

vestal perch
#

u use double click in unity or even opening manually from file folder shows blank file too?

burnt tulip
#

if i open the file outside of unity it shows the code 😃

vestal perch
#

did you switch your default code editor in unity settings to new VS?

burnt tulip
#

yes i did check that VS17 or 19 was used in the settings.

#

i just find it frustrating if i use unity 2018 it works with no problem, but in 2019 version it cant seem to open any script in a meaningful way 😛

vestal perch
#

well 2019.1 works just fine )

#

I didn't try .2 yet

stark geyser
#

Yep, .2 and .3 uses new plugin which is not 100% yet

burnt tulip
#

i will give it a try with 2019.1.7f1 version

#

yes it worked with this one. I can't believe i just spent my day trying to fix this 😄

#

thanks for the help guys 😉

sterile spire
#

hi! is there any way to draw an image on scene gui from an editor script? something like Handles.DrawSolidDisc but... instead of drawing a disc, it draws a sprite

#

(i mean... without instantiating a gameobject with a sprite xD just an image drawn into the scene when the object is selected)

sterile spire
#

thanks for the links! but I was thinking in something that let me draw a .png image into the scene... I've read the documentation of EditorGUILayout, but couldn't find any method to draw .png images in the scene :C

nimble stag
#

Can I add dynamicaly gameobject field after press button?

#

into editorWindow?

sterile spire
#

@nimble stag do you have an editor script?

onyx harness
#

@sterile spire Use GUI.DrawTexture()

#

@nimble stag Technically yes.

sterile spire
#

@onyx harness seems like i am going to have to learn to use the rect ;n;... I has been running away from that since I started to learn editor scripting hahaha.... thanks for the help!

onyx harness
#

The Rect is just a position relative to the top-left corner of the window

#

Make some tests, it's nothing fancy

sterile spire
#

when you say it that way, it really doesn't sounds fancy xD... ok! will give it a try

onyx harness
#

Just do some GUI.Label(new Rect(15, 15, 100, 100), "Test")

#

See the result

nimble stag
#

@onyx harness Technically? What I Need is after button find all gameobject what I want and put in editorwindow

onyx harness
#

For that I guess you have an array of GameObject

#

When you press the button, you create a GameObject, add it to the array

#

In your Editor, loop over the array with your stuff

nimble stag
#

Yeah that is make sense... But What I make this array? I today find this cool stuff (editorwindow) ...

onyx harness
#

It is cool indeed 😄

nimble stag
#

Complete dynamically editor probably not works, right? ... If I make a dynamically fields after select gameobejct and press button -> show linked gameobject via scripts ...

#

Is it possible to do this?

onyx harness
#

If I understand you, yes.

nimble stag
#

What I this do? I dont understand why not put in editor dynamicaly fields after press button ... Then it comes to me that I can't do what I want to do

#
        {
            for (int i = 0; i < m_WallTorchs.Length; i++)
                EditorGUILayout.ObjectField(m_WallTorchs[i].gameObject, typeof(GameObject), true);
        }
        else
            GUILayout.Label("Neni Torch");```
#

This works similarly what I want 😃

onyx harness
#

That's a good start!

nimble stag
#

Thanks 😃

nimble stag
#

@onyx harness Thanks for a little help 😃 That is amazing! Finally, I don't have to click through it and look for linked object via scripts! https://ctrlv.tv/B9tU

onyx harness
#

Well done!

wild star
#

Can I detect when a handle is clicked on?

whole steppe
#

How to get rid of this gap between the label and the actual object?

onyx harness
#

@whole steppe labelWidth

whole steppe
#

How to use it on something like this @onyx harness

#

EditorGUILayout.ObjectField(extra.Configuration, typeof(ExtraCampaignData));

onyx harness
#

It is in EditorGUI or EditorGUIUtility I don't remember

#

Just Google it

whole steppe
#

Ok!

#

Thank you, it worked 😄

sterile spire
onyx harness
#

@wild star I would say HandleUtility.s_NearestControl might be a clue.

severe python
#

Is there any guides/documentation for the UI Elements GraphView?

whole steppe
#

How would I redraw an editor based on the value of something, such as an enum? (using UIElements)

onyx harness
#

@whole steppe if (value) Repaint() ?

visual stag
#

You need to register a changed event on the control

#

and then call a function that clears and rebuilds

#

It really depends on the context

#

whether you're in control of the editor yourself

#

You can also just cache the entire hierarchy and unparent and build/reparent a different cache if it's the kind of thing that changes a lot

#

UIElements is good for that sort of thing

whole steppe
#

Yeah, i did that first part, but wdym by clear and rebuild?

visual stag
#

you have a function that builds your entire UI, or just the part of the UI that changes based on the enum

#

So just call Clear on the relevant VisualElement

#

and recall the function that builds the children based on the state of the enu,m

whole steppe
#

Ah, I see

onyx harness
#

Hahaha I'm so out of the game about UIElement XD

visual stag
#

@onyx harness it makes so much more sense having a persistent UI 😛

whole steppe
#

Thanks to both for helping, I got it now

onyx harness
#

Don't tell me... I don't know who got the idea of IMGUI and more over, who approved it O_o

visual stag
#

I love IMGUI, it's really easy 😛

#

it's just difficult to do complex things

#

complex things are easy if you have state

onyx harness
#

Don't get me wrong, IMGUI is supa nice for prototyping.
But I am talking about IMGUI approved for runtime 🤔

visual stag
#

omg I remember programming my first UI in OnGUI back in the day

#

such a different era

onyx harness
#

I can imagine X)

#

I can't wait to have my hand on their future visual UI editor 😃

visual stag
#

I can't wait until it actually looks and feels like something I'd like to be using 😛

onyx harness
#

What is it lacking right now?

visual stag
#

Other than it being buggy, it just doesn't feel like it has good UX and is extremely clunky

#

Very early days though, so it's likely improved a ton since I checked it out a few weeks ago

onyx harness
#

Few weeks ago? Oh gosh...

severe python
#

If doing complex things is difficult, then is it really easy?

#

but even so, like, text alignment and imgui, aligning buttons? How about aligning custom popups?

#

shakes his head, no

#

never, again

#

takes IMGUI out back and executes it with extreme prejudice

surreal quest
#

Anyone know (specifically for property drawers if it matters) if theres a way to show something generically? Like if I have a value, and I don't know what it will be, is there a way to just display it as it would defaultly be displayed? Whether its a int, a string, or some custom serializable struct?

regal jasper
#

EditorGUI.PropertyField does exactly that (or EditorGUILayout.PropertyField if on a CustomEditor)

surreal quest
#

Right, but I need a serializedproperty for that right? What if I have a literal like, int? Like

int bob = 5;
regal jasper
#

on a propertydrawer you already have access to the serializerproperty

surreal quest
#

Okay, but I'm trying to get a specific value. Like in the case of a dictionary. If I have a Dictionary<int, string> or something, and I'm trying to get each key and draw each key to the editor, but I dont know if its gonna be an int, or if itll be a double, or whatever - even a custom struct, and I need to get each value to draw each one, and i just have the value?

regal jasper
#

Dictionary is not serializable, if you are serialiazing it with a ISerializatioCallbackReceiver using Lists, then you can access the list property through FindPropertyRelative and so its individual values

surreal quest
#

I realize a dictionary is not seralizable, I realize alternative options, and that did not answer my question.

regal jasper
#

You can create a SerializedProperty from anything that is seriablizable by Unity, then you can use a PropertyField to draw it as it originally is

#

EditorGUI/EditorGUILayout.PropertyField is the answer for your question

whole steppe
#

I'm trying to use UXML and I have an enum field, but I'm not sure if I am passing in the type correctly.
<editor:EnumField type="MyEnum"></editor:EnumField>
In the inspector, the enum dropdown is empty.

#

In order to set the right enum, I have to do it in my editor code, which works

#

But I feel like I shouldn't have to be doing that

nimble cedar
#

Is it fair to say Github for Unity is terrible? I'm at my wits end getting it to work properly enough to allow me to push anything beyond the freaking .gitignore and .gitattributes files.

#

It won't even allow me to commit anything. 😦

#

I've removed the extension and whatever else github leaves behind and tried it a second time following the instructions on the github for unity site... Same result.

#

Even more fun, the command line stays frozen when I try to open it from the extension.

#

Never mind. I figured it out. The command line thing is still screwed up. But it was something I left out when attempting to commit. Sigh.

hoary marten
wanton girder
#

Copying assembly from Temp to Library issues of course. I've had these before, not positive how I got rid of them. Been forums searching for about an hour.

Anti-Virus has an exception for the project folder.

Tried unchecking the 'Read-Only' windows explorer option however it gets stuck and doesn't find some of my asset files.

#

Seems to be a fairly common issue. Tried recompiling scripts however my Unity just doesn't want to do that.

gloomy chasm
#

How do I get a property of a property that is a class?
Example. I have this serializedObject.FindProperty("_myClass"), where _myClass is a class that contains another field that is something like private float _myFloat;. How do I get _myFloat from serializedObject?

slate pecan
#
var prop = serializedObject.FindProperty("_myClass");
var myFloatProp = prop.serializedObject.FindProperty("_myFloat");
var myFloatValue = myFloatProp.floatValue; 
#

@gloomy chasm

regal jasper
#

It is wrong, instead of prop.serializedObject.FindProperty("_myFloat"); you should do prop.FindPropertyRelative("_myFloat");

gloomy chasm
#

Ah thank you both! I was close.

wanton girder
#

Getting the same problem as before. Copying Assembly from Temp to Library failed.

I've restarted Unity many times, Restarted my PC.
I've excluded it from my Anti-Virus.
And tried unchecking the 'Read Only' box in properties of windows explorer however it's failing to do so for some of my assets.

#

Been forums searching and no solutions.

#

My only other option right now is to 'Reimport All' I guess?

glacial canopy
#

I had a weird permissions issue with folders on my machine once. The solution was to duplicate the whole folder and delete the original. That got me my write permissions back and problems went away. I think the problems started when I rsynced the folder from one machine to another.

wanton girder
#

Okay I'll try that. Thank you.

wanton girder
#

I think the issue is because I imported a package, the scripting runtime version changed however I'm not sure how to fix this. I've gone into my configuration settings of the player (Edit -> Project Settings -> Player -> Configuration ) and made sure everything is up to date. Seems like while changing scripting runtime, it's corrupted my assembly files. However upon deleting my library folder in an attempt to rebuild all of my assembly files I just get the same error anyways.

wanton girder
#

Update: Duplicating the file did not work, the file is still read only. Could this be due to a virus?

tacit jasper
#

im not sure if this is even relevant @wanton girder

#

but if you installed any of your assets using "pip" you might need to reinstall with the "-e" paramater

#

which IIRC makes the assets editable

regal jasper
tacit jasper
#

I will move or re-write my unfortunately massive post. My apologies

#

I misinterpreted the name of the channel

regal jasper
tacit jasper
#

I'm not so bad on the ML side, it's Unity and C# that are my obstacles

#

I'm learning though

#

slowly

regal jasper
#

Well, welcome to the community, I am sure that the people on the #💻┃code-beginner channel will be very helpful for you then!

tacit jasper
#

thanks very much @regal jasper

barren moat
#

Hey there, I am working on a little editor tool. Wondering if the following is possible through the editor API:

  • Generate a meta file for a new asset created by new FileStream (rather than AssetDatabase.Create)
  • Create a new script component on an asset and assign its UUID (despite the script not having been compiled yet).
  • Get the UUID of a component attached to a gameObject.
  • Assign a component by UUID to the new uncompiled script component.
#

Taking a step back, the UX flow is this:

  1. Select an object with an Animator component
  2. Generate a new MonoBehaviour script
  3. Refresh the directory that the script was created in so that the user can see it (currently it's not appearing)
  4. Assign the new script to the selected object
  5. Assign the Animator component on the object to the new script's serialized field
#

I'm certain this is possible, but ideally I wouldn't have to get down into editing the actual YAML.

random flume
#

Trying to display my sprite on my Editor window. How can I create the sprite field ? The same one which appears when you click on any sprite at the bottom right?

visual stag
#

can you screenshot which field you mean?

#

If you're talking about the preview window it's using EditorGUI.DrawPreviewTexture

#

and if you want the checker you can reflect to EditorGUI.DrawTransparencyCheckerTexture first

wheat turtle
#

Hey, so I am writing an editor window script, this is my code

GUI.backgroundColor = editingDir1 ? focusColorPositive : focusColorNegative;
                    using (new GUILayout.VerticalScope("Box"))
                    {
                        GUI.backgroundColor = defaultBackgroundColor;
                        MakeDirectionArrows(index, i, j);
                    }

so like the background only changes sometimes but my bool editingDir1 is changing everytime i use scrollwheel, i am not sure why
this is gif of the issue -> https://gyazo.com/69ee10034b58b41b98d9aebe468b03e9
i feel like that the editor is having some kind of a lag or something
like when i move the wheel real fast and for long
it does change the color after an inter

#

does it have to do something with the using statement?

#

but i do need to change it back to default before calling anything in the statement

random flume
#

Ah yes it was DrawPreviewTexture! @visual stag Much love man

random flume
#

var style = new GUIStyle(GUI.skin.label);
style.normal.textColor = Color.white
This seems to change the color of all text in the inspector too

onyx harness
#

You must have done something wrong

random flume
#

Or maybe I should restart Unity?

#

Like that is pretty much my code

barren moat
#

How can I programmatically create a csharp file with a meta file in an editor script/

regal jasper
#

Just create a file with the extension .cs and then call AssetDatabase.Refresh()

barren moat
#

Cool, that's what I'm doing. 😃

#

I was worried that the reimport would cause a compile and kill the script

#

But I guess it will wait?

#

We'll see

#

I want to get the meta file before the script ends.

regal jasper
#

if it has compiler errors, yes, it will

barren moat
#

Oh, that's okay.

#

It should fail in that case

regal jasper
#

you can listen to when the recompile finishes

#

there is an event for it somewhere

barren moat
#

But can I persist state over the compile?

#

Hm, wait, nvm

barren moat
#

Cheers.

#

I'll play around with it.

#

Problem is that I want to add a generated component to an object

#

But I can't call AddComponent<T> when T doesn't exist in the code that's running!

regal jasper
#

hmm, this is will be a little tricky, but you can achieve that with AssemblyReloadEvents (it has some limitations, but you can overcome those by subscribing to EditorApplication events once the recompilation finishes

#

but well, hope that works for you

dire urchin
#

I am editing blendshapes on an asset, and setting it to dirty in an editor script, and all goes very well until I reopen the project

#

all changes are lost. I have been looking everywhere for how to actually save the modified asset, but I get countless suggestions to setdirty and save the project, both of which do not solve the problem in my case.

#

Has anyone been able to modify an fbx asset's mesh and keep the changes through a project reopen?

regal jasper
#

@dire urchin the FBX asset is kind of "read-only", if you want to persist the modifications you will need to create a prefab out of it first AFAIK

dire urchin
#

Thanks. I think I found a good solution by writing an asset postprocessor instead of an on demand editor. It does save changes so it is obviously not read only, but I guess unity does not offer that kind of access on demand?

regal jasper
#

oh right, forgot about the postprocessor 🤦

smoky radish
#

Hey guys,
I found out using Resources is not a good approach to find assets in the project. (https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity6.html)
Although I just use it for loading ScriptableObjects and it is better than other type of assets like material, prefab, textures and so on but it still increases size of the build (Especially if creating mobile game).

So I want to know if it is good to use AssetDatabase instead of Resources for loading ScriptableObjects which are used in editor and PropertyDrawer ?

onyx harness
#

@smoky radish If I had to choose between AssetDatabase and Resources. I would pick the former for "most" cases.

#

AssetDatabase is clear on its use, it is an editor-only API.

#

But it some rare cases, Resources might be the proper tool.
Especially for methods like FindObjectOfTypeAll()

#

(Instead of using Object.Find())

#

Resources implies to have the assets in a Resources folder, which is not convenient, even for editor-only assets.

smoky radish
#

@onyx harness So you think I should use AssetDatabase in my case ?

onyx harness
#

Yes

#

If AssetDatabase can do what Resources is providing you. Use AD

#

@smoky radish

smoky radish
#

Okay. Awesome. Thanks. It does what I want.

novel heath
#

I'm trying to do some animator editor scripting, and i've got a reference to my state withUnityEditor.Animations.AnimatorState state = context[0].animatorObject as UnityEditor.Animations.AnimatorState;. I've got a transition with a few conditions on it pointing to the next state, but in the debugger i'm not seeing the conditions array as empty and the destinationState as null... i'm kind of at a loss here. anyone have any thoughts on why these would be empty?

visual stag
#

If you're trying to set something from an editor context it needs to be dirtied.
The options are:

SerializedObject/SerializedProperty
https://docs.unity3d.com/ScriptReference/SerializedObject.ApplyModifiedProperties.html
(https://docs.unity3d.com/ScriptReference/SerializedObject.ApplyModifiedPropertiesWithoutUndo.html without undo)

Undo.RecordObject
https://docs.unity3d.com/ScriptReference/Undo.RecordObject.html
(https://docs.unity3d.com/ScriptReference/PrefabUtility.RecordPrefabInstancePropertyModifications.html> also required for prefabs)

EditorUtility.SetDirty
https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html (most lazy)

If something is changed and not dirtied, that change is transient and will be wiped.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Serialized Object: How-to
https://unity.huh.how/programming/editor-issues/serialisation/serializedobject-how-to

waxen sandal
#

@visual stag You forgot developer mode

visual stag
#

...?

waxen sandal
#

Open help > about

#

Type internal

#

welcome to a new world

visual stag
#

I know

#

is this something people use often? I've literally used it like once

waxen sandal
#

I use it all the time

#

Using the GUIView debugger

#

Using internal debug mode on the inspector

visual stag
#

The GUIView debugger I just access via reflection, and I've only needed the internal debug mode the one time I've used it 😛

#

Access Developer Mode via Help/About Unity and typing internal.
This mode adds icons for window repainting, the IMGUI Debugger, extra Debug options for the Inspector, and extra settings for the Console amongst other things.
(Window/Analysis/IMGUI Debugger)
Turn it off the same way you turned it on.

#

If you feel like we need it 🤷

waxen sandal
#

😄

gloomy chasm
#

I want to check before I put in the work to do it. I should be able to recreate the drawer for the UnityEvent type so that it supports methods with more than one parameter right?

wispy delta
#

It's done here although I didn't look into how ^

gloomy chasm
#

Oh, cool. Well thanks for the reply and the link!

tame echo
#

I'm using NGUI for UI, but it doesn't seem to respect the new SceneVis controls -- the colliders gizmos, etc stop being drawn, but not the actual textures of the UI. NGUI author has no idea. Anyone know if there's a piece of code I should add to prevent those elements from drawing when their SceneVis is set to hidden?

acoustic timber
#

Hello all, is this the correct place to ask for some help on a collision script?

barren moat
#

@acoustic timber probably not, colliision is not editor.

#

Is anyone able to help me with code generation? I'm genereting monobehaviours in the editor, and I want to attach them to an object:

AnimatorWrapper.GenerateAndRefresh(toGenerate); 
for (int i = 0; i < animators.Count; i++) {
  var scriptName = toGenerate[i].GeneratedScriptAsset.name;
  var prevComponent = animators[i].gameObject.GetComponent(scriptName);
  if (prevComponent == null) {
    var scriptType = toGenerate[i].GeneratedScriptAsset.GetClass();
    Debug.Log(scriptType); // NULL
    animators[i].gameObject.AddComponent(scriptType);
  }
}
#

I think the problem is that the type doesn't exist in the script because it's just been generated.

plucky inlet
#

@barren moat you probably should refresh the asset database after generating the type

barren moat
#

I do

#

(updated script)

#
public static void GenerateAndRefresh(IEnumerable<AnimatorWrapper> wrappers) {
  var generated = new List<(AnimatorWrapper, string)>();
  foreach (var wrapper in wrappers) {
    var scriptAssetPath = wrapper.Generate();
    if (scriptAssetPath != null) {
      generated.Add((wrapper, scriptAssetPath));
    }
  }
  AssetDatabase.Refresh();
  foreach (var (wrapper, path) in generated) {
    var type = AssetDatabase.GetMainAssetTypeAtPath(path);
    var scriptAsset = (MonoScript) AssetDatabase.LoadAssetAtPath(path, typeof(MonoScript));
    if (scriptAsset == null) {
      Debug.LogError($"Could not find generated file {path}!");
    }
    if (wrapper.GeneratedScriptAsset == null) {
      Debug.Log($"Created '{path}'", scriptAsset);
    } else {
      Debug.Log($"Regenerated '{path}'", scriptAsset);
    }
    wrapper.GeneratedScriptAsset = scriptAsset;
    EditorUtility.SetDirty(wrapper);
  }
}
plucky inlet
#

probably wait until the refresh is done in some callback
(i don't know which one 😃

#

e.g. InitializeOnLoad will get you reload in the editor

barren moat
#

Nice.

#

I am a bit confused about what happens when the code is reloaded

#

I thought it would kill the script tbh

plucky inlet
#

it would - you have to continue per partes 0)

regal jasper
#

@barren moat I think that your issue is being with persisting the data so that you know which script to add after, right? If that's the case, you can create a temporary json file in some place to save that info and then later delete it

barren moat
#

@regal jasper presumably yes that's the problem.

#

Types don't just appear in the code after importing the script, right?

#

It's kind of annoying because I'd like to basically do what I see when a script is missing in unity

#

Ideally I could just put an invalid component on the object and then assign the MonoScript by its GUID.

#

I think I will put a hidden GO in the scene and assign references to it

#

in serialized field

#

Then when the compiler calls back I'll flush the changes out

plucky inlet
#

i don't understand this: "Types don't just appear in the code after importing the script, right?" why wouldn't they ?

barren moat
#

I don't know, I don't understand C# enough

plucky inlet
#

are you making animation wrapper btw ?

barren moat
#

Yes

plucky inlet
#

types do appear in the assembly once it's compiled (reloaded)

barren moat
#

Oh nice, even during the execution of a script?

#

That is wild

plucky inlet
#

no, you have to reload - which unity does for you when asset is changed

barren moat
#

Right, well I can call AssetDatabase.Refresh() and continue

#

So it doesn't kill the script immediately

plucky inlet
#

it's not that dynamic - far from any live code

barren moat
#

Yeah, I didn't expect it to continue at all

plucky inlet
#

yea I'm not sure about all intricacies of AssetDatabase.Refresh tbh

barren moat
#

Fair enough.

#

So while I've got you

#

This is my currrent plan

#

This whole thing runs after you click a menu option, and is operating on Selection.gameObjects

#
  • generate scripts for each component
  • reload to create meta files
  • fetch the GUID of each created script
  • create a temp GameObject in the scnee
  • put script GUID and target object in serialized list on object
  • on compiler callback attach all those scripts ot their associated objects
  • destroy temp GameObject
#

Sound like it might work?

plucky inlet
#

what's the end goal ? -- attach generated component on the objects selection right ?

barren moat
#

Yep.

plucky inlet
#

well you should have the generated type/s after reload available as normal .net type so there should be need to manipulate GUIDs directly - that

#

would be the ideal case

barren moat
#

Except I need to hold on to the animator references

#

They're in the scene

#

I can't assume that the selection didn't change during reload

#

And I need to hold on to the assets that were generated too

plucky inlet
#

I'd probably try that direction first - basically your goal should be to get updated domain with new types

#

yep the selection will change - prob. worth to focus bookkeeping on that instead

barren moat
#

There's a [DidReloadScripts] attribute that will probably help me

plucky inlet
#

oh yea that one

barren moat
#

Taht's my guy

#

I reckon I put that on a hidden GO in the scene

#

Or a hidden SO

plucky inlet
#

I don't want to mislead you entirely 😃 - there are couple of hidden assumption which need testing

barren moat
#

Something that can persist past the code reload

plucky inlet
#

yes

barren moat
#

(it's okay, it's been hidden assumptions all the way)

#

It's taken so much code to get it this far

#

lol

#

I've got asset change modifier to regenerate the scripts when the controller changes

#

And of course the code that actually generates the scritps 😒

#

I really thought I'd just bang it out haha, but it seems unity isn't exactly streamlined for this

#

Anyway, fun project. I'll try to do that last bit soon

plucky inlet
#

yea modifying code on the fly is not very straightforward -

barren moat
#

Then I'm going to try to make a package manager compatible repo

plucky inlet
#

the project looks useful if it will work seamlessly :]

barren moat
#

I just found out that you can :)

#

It does work really nicely

plucky inlet
#

esp. since the whole animator setup is not very user friendly

barren moat
#

The idea is to statically verify the animator usage

#

And autocompete etc

plucky inlet
#

it looks like a great visual tool for e.g. state machines, but the manual setup is always a pain

barren moat
#

Gonna do shaders next

#

Material wrapper

#

I'll open source it, but for now it's just in a branch of our game

plucky inlet
#

bringing all the strings into types right - seems like a noble quest ;0)

#

post a link occasionally - i'll check out the animator thing it should be useful

barren moat
#

I can share the source now, the only thing that doesn't work is attaching the scripts

#

If you want to give it a try

#

But all the file watching and generation etc works like charm

#

You just need to drag them on after creation

#

No biggy, just a bit of a nicer experience

plucky inlet
#

I'm not sure if there isn't some non public API for this tbh - maybe worth to take look somewhere in editor c# reference - i'm not that of a digger myself tbh )

barren moat
#

I asked a unity employee and he said he would ask around

#

And then told me that it would be difficult

plucky inlet
#

hah

barren moat
#

oh man, I didn't even think about this

plucky inlet
#

btw on a general note: storing things in a hidden GO in the scene is not very user friendly - although fully possible and probably workable
but you can use ScriptableObject for storing any data - you'll get serialization in play mode for free - would need to handle lifecycle events properly though

visual stag
#

When Unity creates a script it just uses File.WriteAllText and then AssetDatabase.ImportAsset, which can then be immediately AssetDatabase.LoadAssetAtPath'd and returned

plucky inlet
#

@visual stag will that work with a new type ?

visual stag
#

Of course, that's what happens when you create a new script, no?

plucky inlet
#

new type causes reload - hence the callbacks discussion above

visual stag
#

Ah, alright, I've not been following along 😛

plucky inlet
#

you could probably LoadAssetAtPath for a new script but I have no idea what that gives you since the type might or might not be in currently loaded domain