#↕️┃editor-extensions
1 messages · Page 43 of 1
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)
You could use OnValidate to ensure that the size is correct
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
@distant atlas breadcrumb
ok thanks
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.
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
I'd just use a scriptable object
I think I'll go that route
I think if I use a scriptable object I can pull it in through Selection.activeObject?
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
It is common to not use Destroy but DestroyImmediate during editor time.
That's the problem, I'm clearly using DestroyImmediate, but still getting an error about using Destroy
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
2019.1.3
As I understood DestroyImmediate is used during editor, and Destroy for in-game
Reproduce the bug in an empty project and report the bug
Yeah I guess I could try. Not sure I can though, it was working fine, then just suddenly started happening.
@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
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.
hmm weird. your script is in an Editor folder, right?
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
I mean the script that calls DestroyImmediate, it's in an Editor folder? and is it in an Editor class, or an EditorWindow class?
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
anyone else getting IL2CPP compilers stuck during a headless CI build on Windows Server?
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
You likely want #💻┃code-beginner
hello, does anyone know how to change the syntax theme in visual studio?
this is just an spontaneous thought but can you use DOTS in editor scripts?
I really feel this is very edge case X)
In which world would I need supa power in the editor world
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.
@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.
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
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
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
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
hi all, Can I print color text on the console?
Debug.Log("<color=#FFFFFF>Hello World!</color>")
debug log supports rich text: https://docs.unity3d.com/Manual/StyledText.html
you can also use the explicit name for the ones that exists in UnityEngine.Color (color=red, color=blue, etc)
Can IMGUI be mixed with UIElements?
oh good i don't need to rewrite my propertydrawers 😺
@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
@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
alright, thanks for the tip!
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!
What is null?
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);
Just check why SpeedNameArray is corrupted
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
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:
- ScriptableObject for the LDraw file
- ScriptedImporter for importing the LDraw files
- 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?
How are you setting the values from the editor?
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
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
it disappeared
let me try a screenshot instead
This is #💻┃code-beginner
@arctic cove but to answer you, I don't see any error, what is happening?
They’re just deleting themselves immediately
Actually let me double check some things
It just mean your transform is low at start
@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
do some of you know how to get a smoother scale
https://gyazo.com/5b39d0258de384f442710973b0a2387f
Setting it programmatically?
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?
Nice. Getting ReorderableList to work.
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?
A lot of try and try and search
@brittle cosmos have you tried GUILayoutUtility.GetRect?
I have not. Thank you, that looks useful
This method is to reserve a space in the GUI layout world.
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
I've search for the word window, there is none
what?
It doesnt say to avoid it 🤔
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."
Rare does not mean to avoid.
so... should I use it then?
I am misreading unlikely maybe XD
😄
@lone quarry basically you can avoid using that by using SerializedObjects instead, this way you will be properly supporting undo/redo
But it really depends on what you are trying to do
SerializedObjects might be overkill for many tasks
I'm just trying to save ScriptableObjects nothing else
Well it should be fine then
ok thanks! 😄
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
exactly, because by using EditorUtility.SetDirty (without doing others additional steps) will cause every action to be destructive
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
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.
And what object are you working on?
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
Have you tried? 🤔
Update() will look at the target and update its data to match.
Apply() will set the modifications to target
I will try, I was just wondering how undo/redo is handled
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
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?
Thanks, that's it
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
Oh you don't imagine how works the Editor under the hood XD
The screen shot above is me selecting it three times
They can't really keep the editor cached for the life time of the application
Is it an issue?
So it's better to be consistent and recreate it
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.
This is why you have serialization
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?
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
aah, smart.
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
@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.
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?
Nope
The Inspector has a ActiveEditorTracker that create and manage Editors internally
It stays in the scope of the selection.
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.
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.
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.
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
That's selecting the gameobject with my component once, then deselecting it.
hmm, still don't understand why there are two though.
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
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
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
UIElements.ProgressBar doesn't seem to be able to be created via XML. It says that there's no factory for it. How come?
@cloud wedge while you are right, Unity never used Path in their API for a folder
If I remember correctly 🤔
that's good to know
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
Can you screenshot me the transition line of animator? 🤔
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?
there's some utility function somewhere that rotates
I'll try to find it
@neat shadow Try this https://docs.unity3d.com/ScriptReference/GUIUtility.RotateAroundPivot.html
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?
@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;
}
❤
I think I misunderstood the question, assuming you were talking about a UXML thing
(Funny enough, a dude on unitydev Slack asked the exact same thing yesterday, I just copy pasted)
Why would you want to do it this way instead?
@visual stag I noticed that X)
The reason is I'd like to get editor windows from uxml+uss only
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...
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.
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
Haha never noticed this one, shit (Good catch)
Editor-only is ok 😃 Thank you !
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
Yes
hello everyone, has someone alredy used pdb2mdb ?
Never had to, what is your issue?
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
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 ?
@rich gate The sprite is white because it is null (not found).
Confirm that the asset is setup as a Sprite in the Inspector.
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 ?
@rich gate Use the other constructor to disable the mip map
?
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
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
the sprite isn't on the ressource folder
because i don't want to load at the game starting
If you want me to help you, you need to at least try what I am asking...
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
Like this
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
Well for your information
and Ressources are loaded at the game starting
Resources.Load() loads from any Resources folder
i don't want that
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?
i have make a Ressources folder before
and it was not working?
and i have Debug.Log the lenght of the Ressources
You must have done something wrong.
How do you get the "length"?
idk
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())
but another question
that work perfectly like that
but that add MipMap to the icon
how can i disable the mip map ?
import settings didn't work?
import settigns don't load at start ?
import settings should be constant as far as I know
WWW is loading from a distant path.
It is not reading any import, since it is raw data.
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.
He did that already
ahh
But since its texture is not properly set, he sees blur stuff
sorry late to the party
😃
I was wrestling with a BSP/DFS/BFS implementation in C# and the lack of pointers make me sad
DFS BFS?
Honestly twas a interview question I choked on 😛
got home and had to sort it out
mainly because it was annoying
How good are they as lookup algorithm?
DFS complexity is O(V+E) and Breadth first is O(|V|+|E|)
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
RGBA32 is the better format ?
It's larger
@rich gate this is what I told you about look out the other constructor XD
"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
@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
DXT5 is not lighter ?
It is.
But you need to fill its prerequisites
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
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?
You are expecting an instance of a Type and you would like to wrap it around an enum? 🤔
What is the idea behind?
there is a World singleton
which expects generator logic
dependency injection, I believe it is called
Now I might make them scriptable objects instead
they don't really have to exist past initialization
Still, they have to persist at some point no?
how do you mean?
'they don't have to, past'
It means they have to, before X)
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
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
@rich osprey code code
what?
Drop some code if you would like more help
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?
@rich osprey
UnityEventDrawer eventDrawer = new UnityEventDrawer ();
eventDrawer.OnGUI (position, property, label);```
It also has a .GetPropertyHeight method
You'll find it in UnityEditorInternal
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?
how do you enable this from an editor script?
as i mean, build a server build from an editor script
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
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
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
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!
I've found this: https://docs.unity3d.com/ScriptReference/Presets.Preset.SetAsDefault.html will check if it works.
Presets of type 'UnityEngine.QualitySettings' can't be set as default.
rip me
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();```
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.
@gray portal [RequireComponent]
That easy, huh? Thanks! Follow-up questions:
- Can these scripts be added minimized? (In the above example, only B and C would be minimized)
- 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.
- Not really, for that there is no easy solution, you need to dive into the Inspector & Editor code.
- Yes technically you can.
You have the message OnValidate() that helps you receive an event when the Inspector is modifying a Component.
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnValidate.html
@gray portal
@onyx harness Thank you for the info!
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
doh, perfect, thanks!
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 😃
how do i tell if an object is a folder?
or an asset is a folder
nevermind, got it, AssetDatabase.IsValidFolder(string path);
@hidden night This channel is not really used for advertising.
No problem, check #502171717544968212
Okay Thx 😄
@whole steppe just ask the actual question
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
But, this is #↕️┃editor-extensions , a channel about extending the Editor. #📲┃ui-ux is for runtime UI - so I'd take the question there
Good idea, I missed it's existence
@zealous ice Thanks for suggesting the vertical layout group. Ill research this and how to use it .
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
@@heavy tiger Use time properties to define if you are on the very first frame.
So you are saying it instantly dies?
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
Mikilo suggested a solution to that
i dont understand a time property ?
isn't there a event "editorLoaded" or a OnStart() for the editor ?
No
ok
Give EditorApplication.timeSinceStartup a go
ok i'll see
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 😄
@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 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
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?
Not sure exactly, but the things to look up are Rich Text https://docs.unity3d.com/Manual/StyledText.html, perhaps you could copy the TextArea GUIStyle and set https://docs.unity3d.com/ScriptReference/GUIStyle-richText.html, but I'm really not sure if that'd make it work
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
@coarse hull Can you be more explicit? O_o
in what way?
"loop through the text and color specific parts specific colors"
"EditorGUILayout.TextArea"
how would I color different text in it different colors
example: looking for letter a, recolor to blue
rest is green
how do you use that in a text area?
The text you provide to TextArea(). It must be like this:
TextArea("<color=green>We <color=blue>a</color>re green</color>")
you can do that?!
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.
how do you do that?
As a last argument, you can provide a specific style to TextArea (or more generally, to any GUI methods)
oh that's what that means
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!
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
GUILayoutOption are different
It is just a convenient way to override UX details
GUIStyle gives the global rendering, and the options override some stuff
how do I put text into this? GUIStyle style = new GUIStyle(EditorStyles.textArea);
You don't
You.. dont?
you pass style to the TextArea function
GUIStyle style = new GUIStyle(EditorStyles.textArea);
style.richText = true;
EditorGUILayout.TextArea("<color=green>We <color=blue>a</color>re green</color>", style);
wait but I need a text area where I can put text into that is colored
ohhhhhh
🤦 🤦 🤦 🤦 🤦 🤦 🤦 🤦
thanks again xd
You need to lookup method overloads
I really do
@coarse hull Also, cache the style, don't create a new one every single frame
got it
@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
I know no other technique to color text.
darn
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
I would probably cache your colored text.
@visual stag but I just checked, CCS doesn't give a specific scope
uhwhat
Are you changing your string elsewhere?
I am making a colored script editor in unity
so if they modify stuff I need to remove and readd color anyways
Is the only place your string changes in the TextArea?
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
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
I really don't know what you mean
oh you are saying cache it for the next frame
@visual stag how would I handle using html?
crying
like if I have html in the file, how do I make it ignore the richtext
while my color additions still working
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
if you could find it that would be great!
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 😛
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
-_-
Yeah, I'm really not sure how it all works out
I am trying to display and edit
both xd
vertx I already found both sites that said those two things, neither would work
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 😛
-_-
lol that longer face got bot'd?
I just tried TextArea with rich text, it works, but it is obviously not convenient at all to use
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
?
what do you mean?
How do you edit a text area from code while the user is editing it?
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.
how do i use this parameter
@mystic swift get the texture, GetColors() from the texture, replace the colors you want, SetColors(), Apply.
@smoky radish you did it! 😇
@onyx harness Sorry. I have no idea what texture you're talking about.
@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
@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.
@mystic swift lol, that is lightyears from what I understood X)
Look for OnValidate()
@onyx harness Cheers!
@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 ?
@smoky radish Github id? I almost never use GitHub but here is mine: Mikilo
I don't know if it helps you X)
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?
OH
OK
Ok now I got another problem
I'm watching this tutorial and theres no MainMenu.LoadScene
Thanks for watching, Don't forget to Rate, Comment & Subscribe! ------------------------------------- My Website - http://xiconikkxgaming.weebly.com/ Cheap G...
2:13 to be exact
I followed the same steps
Halp
Because your GameObject has no MainMenu Component on it? O_o
I guess yes
What about your MainMenu code?
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
Huh?
It means, your script is not up to date
The scene name is NormalWorld
You need to fix it
WELL GOD FUCKING DAMN IT
You forgot quotes then
"NormalWorld"
Updating Unity is nothing related to your issue
oh
NormalWorld in your code is a variable
But you never declared it anywhere
It does not exist
That's why
What is the tutorial saying?
I can't guess X)
If you tell me your scene is named NormalWorld
Just quote it
Thanks for watching, Don't forget to Rate, Comment & Subscribe! ------------------------------------- My Website - http://xiconikkxgaming.weebly.com/ Cheap G...
SceneManager.LoadScene("NormalWorld");
Oh
IT WORKED
THANK YOU
Now I gotta copy and paste this process for 4 other world types
oof
Your tutorial is showing LoadScene(1)
This channel is about extending the editor. General code goes in #💻┃code-beginner
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.
can i ask for help here?
@burnt tulip just ask, if anyone will be able to help, they will answer
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 😃
u use double click in unity or even opening manually from file folder shows blank file too?
if i open the file outside of unity it shows the code 😃
did you switch your default code editor in unity settings to new VS?
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 😛
Yep, .2 and .3 uses new plugin which is not 100% yet
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 😉
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)
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 do you have an editor script?
@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!
The Rect is just a position relative to the top-left corner of the window
Make some tests, it's nothing fancy
when you say it that way, it really doesn't sounds fancy xD... ok! will give it a try
@onyx harness Technically? What I Need is after button find all gameobject what I want and put in editorwindow
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
Yeah that is make sense... But What I make this array? I today find this cool stuff (editorwindow) ...
It is cool indeed 😄
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?
If I understand you, yes.
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 😃
That's a good start!
Thanks 😃
@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
Well done!
Can I detect when a handle is clicked on?
How to get rid of this gap between the label and the actual object?
@whole steppe labelWidth
How to use it on something like this @onyx harness
EditorGUILayout.ObjectField(extra.Configuration, typeof(ExtraCampaignData));
@wild star i don't know if you can detect a clic in any handle... but you can add a button https://docs.unity3d.com/ScriptReference/Handles.Button.html (I hope the answer doesn't come too late)
@wild star I would say HandleUtility.s_NearestControl might be a clue.
Is there any guides/documentation for the UI Elements GraphView?
How would I redraw an editor based on the value of something, such as an enum? (using UIElements)
@whole steppe if (value) Repaint() ?
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
Yeah, i did that first part, but wdym by clear and rebuild?
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
Ah, I see
Hahaha I'm so out of the game about UIElement XD
@onyx harness it makes so much more sense having a persistent UI 😛
Thanks to both for helping, I got it now
Don't tell me... I don't know who got the idea of IMGUI and more over, who approved it O_o
I love IMGUI, it's really easy 😛
it's just difficult to do complex things
complex things are easy if you have state
Don't get me wrong, IMGUI is supa nice for prototyping.
But I am talking about IMGUI approved for runtime 🤔
omg I remember programming my first UI in OnGUI back in the day
such a different era
I can't wait until it actually looks and feels like something I'd like to be using 😛
What is it lacking right now?
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
Few weeks ago? Oh gosh...
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
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?
EditorGUI.PropertyField does exactly that (or EditorGUILayout.PropertyField if on a CustomEditor)
Right, but I need a serializedproperty for that right? What if I have a literal like, int? Like
int bob = 5;
on a propertydrawer you already have access to the serializerproperty
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?
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
I realize a dictionary is not seralizable, I realize alternative options, and that did not answer my question.
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
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
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.
Guys, i got these errors when i try to use Test runner. Do you know solution?
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.
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?
var prop = serializedObject.FindProperty("_myClass");
var myFloatProp = prop.serializedObject.FindProperty("_myFloat");
var myFloatValue = myFloatProp.floatValue;
@gloomy chasm
It is wrong, instead of prop.serializedObject.FindProperty("_myFloat"); you should do prop.FindPropertyRelative("_myFloat");
Ah thank you both! I was close.
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?
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.
Okay I'll try that. Thank you.
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.
Update: Duplicating the file did not work, the file is still read only. Could this be due to a virus?
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
@wanton girder @tacit jasper please use #💻┃code-beginner for those kind of issues, the #↕️┃editor-extensions is focused in editor scripting stuff (Custom Editors, Editor Windows, Property Drawers, UI Elements and such)
I will move or re-write my unfortunately massive post. My apologies
I misinterpreted the name of the channel
Also @tacit jasper there is a #archived-machine-learning channel in case you need further help about your MLAgent
I'm not so bad on the ML side, it's Unity and C# that are my obstacles
I'm learning though
slowly
Well, welcome to the community, I am sure that the people on the #💻┃code-beginner channel will be very helpful for you then!
thanks very much @regal jasper
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 thanAssetDatabase.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:
- Select an object with an
Animatorcomponent - Generate a new MonoBehaviour script
- Refresh the directory that the script was created in so that the user can see it (currently it's not appearing)
- Assign the new script to the selected object
- Assign the
Animatorcomponent 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.
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?
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
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
Ah yes it was DrawPreviewTexture! @visual stag Much love man
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
You must have done something wrong
How can I programmatically create a csharp file with a meta file in an editor script/
Just create a file with the extension .cs and then call AssetDatabase.Refresh()
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.
if it has compiler errors, yes, it will
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!
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
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?
@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
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?
oh right, forgot about the postprocessor 🤦
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 ?
@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.
@onyx harness So you think I should use AssetDatabase in my case ?
Yes
If AssetDatabase can do what Resources is providing you. Use AD
@smoky radish
Okay. Awesome. Thanks. It does what I want.
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?
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
@visual stag You forgot developer mode
...?
I use it all the time
Using the GUIView debugger
Using internal debug mode on the inspector
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 🤷
😄
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?
I believe so @gloomy chasm
https://github.com/Thundernerd/Unity3D-ExtendedEvent
It's done here although I didn't look into how ^
Oh, cool. Well thanks for the reply and the link!
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?
Hello all, is this the correct place to ask for some help on a collision script?
@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.
@barren moat you probably should refresh the asset database after generating the type
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);
}
}
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
Nice.
I am a bit confused about what happens when the code is reloaded
I thought it would kill the script tbh
it would - you have to continue per partes 0)
@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
@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
i don't understand this: "Types don't just appear in the code after importing the script, right?" why wouldn't they ?
I don't know, I don't understand C# enough
are you making animation wrapper btw ?
Yes
types do appear in the assembly once it's compiled (reloaded)
no, you have to reload - which unity does for you when asset is changed
Right, well I can call AssetDatabase.Refresh() and continue
So it doesn't kill the script immediately
it's not that dynamic - far from any live code
Yeah, I didn't expect it to continue at all
yea I'm not sure about all intricacies of AssetDatabase.Refresh tbh
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?
what's the end goal ? -- attach generated component on the objects selection right ?
Yep.
The part that (attetmpts) to do this is what I pasted here https://discordapp.com/channels/489222168727519232/533353544846147585/593221451553832990
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
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
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
oh yea that one
I don't want to mislead you entirely 😃 - there are couple of hidden assumption which need testing
Something that can persist past the code reload
yes
(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
yea modifying code on the fly is not very straightforward -
Then I'm going to try to make a package manager compatible repo
the project looks useful if it will work seamlessly :]
esp. since the whole animator setup is not very user friendly
it looks like a great visual tool for e.g. state machines, but the manual setup is always a pain
Gonna do shaders next
Material wrapper
I'll open source it, but for now it's just in a branch of our game
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
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
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 )
I asked a unity employee and he said he would ask around
And then told me that it would be difficult
hah
oh man, I didn't even think about this
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
When Unity creates a script it just uses File.WriteAllText and then AssetDatabase.ImportAsset, which can then be immediately AssetDatabase.LoadAssetAtPath'd and returned
@visual stag will that work with a new type ?
Of course, that's what happens when you create a new script, no?
new type causes reload - hence the callbacks discussion above
Ah, alright, I've not been following along 😛
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