#↕️┃editor-extensions
1 messages · Page 51 of 1
So I'm not able to make an asset bundle in that version?
I never did that before, sorry dude I can't help you. However I'm sure it's doable
I don't know whether it's an issue with monodevlop or not as this is my first time using Unity
As a first suggestion, I would say try Visual Studio or Visual Code. Anything but MonoDevelop
I will try visual studio. I have both 2017 and 2019 of visual studio installed
I can try in an about an hour once I get home
so I've managed to use visual studio however the script in the example is giving me this error
That's pretty clear
even though the function has 4 arguments inside it
Where do you see it?
And VS is telling you there is no method BuildAssetBundle taking 4 arguments
which is the BuildPipeline.BuildAssetBundle() function
As I told you, your documentation is outdated
Learn about this error, the message is very explicit
IDE are veeeeery unlikely to spit out false-positives
but I'm guessing that the updated code won't work on older versions of unity?
I am trying to see where (in the updated build assets documentation) I can specify which assets are built into the assets bundle
as it's just a material and a texture I need to bundle and not the rest of the assets
well I am kind of new to this
so I am not sure what methods etc to use
can you point me to the right method?
remove the 'S'
but it states at the top of that particular page that it's obselete?
Which page?
Oh BuildAsseBundle?
as you said to remove the S
They are saying that BuildPipeline is obsolet
You need to use AssetBundle instead
BuildAssetBundles is stating:
Build all AssetBundles specified in the editor.
I guess you need to tag your assets first
I have tagged the two assets I wish to bundle
What the result of the method?
eh?
when I try to look at the docs it always leads me back to the buildassetbundles page
Which might be the one you are looking for
I'm quite confused, as you say buildpipeline is depreciated however that is the function used in the update doc
Allow me to correct myself, the method you were looking for is deprecated
I have to go, good luck in your journey
What do I need to do to have alternative icon for selected node? Scriptable object icon changes to all white, and easily visible. However Mesh icon does not. And my custom icon on TerrainData also doesn't. I'm placing icon into Gizmos with the AssetScript icon.png name.
Hmm, according to EditorUtility.GetIconInActiveState it should be AssetType on icon.png, but it doesn't work because GetAssetPath for already loaded gizmo icon is empty… Looks like something is broken inside
@onyx harness Incorrectly submitted here
Hey. Does anyone know a way to check if a tile is flipped in a tilemap editor script?
How do you know without using a script?
Using a script that loops through every tile in a tilemap
I'm making a tool that instantiates prefabs based on tiles. The only problem is that I need the gameObject to be "flipped" if the tile is flipped but I can't find any property in the Tile class that would give this information since a flipped tile scale and rotation seems to be the same as a normal tile
So, how do you know it is flipped?
If you can't tell me humanly speaking, I don't think I can help you editorly speaking
Because it's flipped on the tilemap itself. Like I pressed shift + [ when painting the grid . I'm just wondering if there's a way to detect that in code or if I need to create a separate image where the tile is already flipped
Sorry, can't help ya then, not my area =X
I'm back to work on my editor script to help set 110^2 gameobject references for VRchat Trigger scripts
im not really sure how to reference a VRC_Trigger script
if it were a component like a rigid body or something i could just say item.GetComponent<Rigidbody>();
but item.GetComponent<VRC_Trigger>(); doesn't work because it doesn't know where to look for that namespace
the script is apart of the VRchat SDK
ohh i just have to import the namespace duhhhh
@blissful sinew doesn't it have something like transform property? If that's UnityEngine.Tilemaps.Tile, it has it.
Is there any way to execute OnAnimatorIK during edit mode ?
nvm i managed to manually update it
I want to draw the properties of a list onto a custom editor
I can currently draw the fields of each item in the list, now how can I then draw the properties of those?
Here's my current code:
SerializedProperty listIterator = assetSo.FindProperty("nodes").Copy();
Rect drawZone = GUILayoutUtility.GetRect(0f, 16f);
bool showChildren = EditorGUI.PropertyField(drawZone, listIterator);
listIterator.NextVisible(showChildren);
//List size
drawZone = GUILayoutUtility.GetRect(0f, 16f);
showChildren = EditorGUI.PropertyField(drawZone, listIterator);
bool toBeContinued = listIterator.NextVisible(showChildren);
//Elements
int listElement = 0;
while (toBeContinued)
{
drawZone = GUILayoutUtility.GetRect(0f, 16f);
SerializedProperty nodeIterator = listIterator;
bool Continue = nodeIterator.NextVisible(showChildren);
showChildren = EditorGUI.PropertyField(drawZone, listIterator);
toBeContinued = listIterator.NextVisible(showChildren);
listElement++;
}
PropertyField should draw the children already, I thought. But you can pass true as the third parameter to force that to be the case
? I don't understand
I don't want to draw the children/items of the list, I want to draw their properties
Can you explain what it is that you're trying to do as a whole?
because if you just want to display the contents of an array/list without the Unity UI faff that comes with it, just drawing the items one after another...
You can just for loop over your array using GetArrayElementAtIndex and then draw that property
I have a list of scriptableobjects
I want to draw their properties
You need to create (and cache) SerializedObjects for each of them, where you then draw the properties. Or you can use Editor.CreateCachedEditor and call it's GUI function
so i'm trying to create an animation from a list of sprites through code, but none of the keyframes have sprites associated with them, however the list is populated with sprites
@cosmic dagger I assume images is an array of Sprites?
Unity's internal code in SpriteUtility seems to do basically what you're doing
I don't know if you've looked at it for comparison
never knew that existed
Looking at the code
I think you can create a sprite with an animation automatically
if you drag an imported sprite into the scene and hold alt
well i'm creating a bunch of different animationclips from sprite sheets that aren't mine so that wouldn't work
it would but i'd be too time consuming
there's like 100's of different animations
Makes sense. It might be worth just reflecting into this code though and passing your stuff to it
perhaps it's how i'm creating the sprites? I'm making them from a sprite sheet using Sprite.Create
I assume you've serialized them before you run this function?
Like, AssetDatabase.CreateAsset
Yeah, otherwise the animation asset cannot refer to them
But i’m referring to the dictionary
Oh wait
I see what you mean
It would only work at runtime right?
How do you mean? All of this is editor-only stuff
Well i load the sprites dynamically, but create the animations only once and save the .anim asset
You cannot author animations at runtime as far as I know
I’ll try serializing the sprites, i think i know what’s going on
Guys is there any way to make an enum like dropdown menu for serialized custom classes that derive from the same base class?
The dropdown will select the type and there should be a button to set a [serializedRefernce] baseclass field to an object of derived type.
I don't want to write separate buttons for every derived type.
You can use EditorGUILayout.Popup to display a list of any strings.
And you can use https://docs.unity3d.com/ScriptReference/TypeCache.GetTypesDerivedFrom.html to populate that list and any selection you want from it.
Not sure how you'd serialize any of this though, or if you need to for what you want to do.
@visual stag [serializeReference] handles the serialize part. I want an easily customizable list<baseclass> that has properly serialized derived classes. I will try typecache.
@visual stag How can I call the constructor of a type from the typecache?
@waxen sandal I have little experience in using reflection, could you give a sample syntax?
Would activator.createInstance work?
I don't think you can pass arguments with create instance
But if you don't care then sure
There are lots of overloads
thanks, one of the overloads worked. MSDN site to the rescue.
On a side note, can you recommend any sources for learning the basics of reflection? Clearly I have a lot to learn.
Just googling when you have a question is how I learnt what I know
It's just a slide of my Reflection course I give.
Unfortunately, the course is in french... Except if you can understand it, I'll send it to you if you want
That's a lot of information for one slide
Because you don't have all the previous slides explaining how to use Reflection.
The one above is a summary
Makes sense
You have in front of you most 'things' you can interact/get/reach with Reflection.
Anyone knows how to fix this horrible Prefab window lighting?
maybe ask in #archived-lighting ?
I could but although the question is about lights, it is not lighting related 😦 it's about the prefab editor window. it should have a neutral light set as default. not so bright.
Is there any equivalent of OnEnable() for PropertyDrawers that works like onEnable of custom Editors?
I only need to use reflection once to fetch the data I need.
No, u need to make a flag for example first time in GetPropertyHeight() that will initilize your property drawer
One more thing, how can I use the serializedproperty of a propertydrawer to change the object it's pointing to? I want to make it point to a new instance of the fields class.
you can always call NextVisible()
but the drawer for the next property will invoke nonetheless
@onyx harness I meant making the field the property drawer is attached to. I want the field point to a new custom class object.
I can already do that by calling a function on the serialised object. But I don't think that handles undo.
A new custom class? It means you completely change the SerializedObject right?
@onyx harness doesn't the serialised object mean the gameobject with the monobehavior that has the field?
Technically no, and factually no.
It targets the Component, which in your case is your MonoBehaviour
@onyx harness Yeah, I messed up a bit there. But I should be able to access the field on the monobehavior?no?
I just want to set that field to a new reference.
But I can't figure out the syntax.
Most methods for modifying the serialised property mentions propertyfield which is not what I want.
unsure if property.objectreference does what I need
No no
Look for FindProperty
Or FindRelativeProperty
It requires a path
Similar to propertyPath provided by your SerializedProperty
What's the difference between the two?
And getting the property is not the problem. I need to set it to a new object. I don't see any other way to do that other than object reference value.
I think one is relative the other is absolute
One is in SerializedObject, the other is in SerializeProperty
But you can't set it
A SP is fixed
Can I just post my code then? I think both of us are unsure about what we want
@onyx harness https://pastebin.com/K5gUj7H3
The code won't compile since I removed some lines there.
But the idea is the same as my code
You want to create an object and set it as the new SerializedProperty
Yes
But you can't do that
As stated above
Remember one thing, Unity can't serialized polymorphism
But I can access the object and call a fucntion to do the same thing. Just without the undos
Serialization has some workarounds in 2019.3
so that's not the problem
Oh you are on the latest
If serialized object does not work, how do I tell it to mark the undos?
You can manually draw it, but won't be able to recreate a Serialized context around it
You can't Undo if you are not working on an Object
So long story short, Not possible?
What if I used a custom editor. I would be directly accessing the monobehaviour then
*By casting the target to the monobehaviour
Like SO
You can cast it to MB from both
You can create your new object from the selected Type
You can draw it manually
But not using anything related to serialisation
Some asset store packages do have inspector serialized classes. And they also support changing types with undo support.
Ex:Gameflow.
Do they also rely on external serialization methods?
I'm sure you are not giving me all the details
Or you don't know that you didn't give me all the details
Perhaps they serialized stuff themselves
Like a lot of plugins do
In other words I can't compete.
Oh well, I'm pretty sure I can love without an undo. It's not like anyone else is going to use my stuff.
Sorry for wasting your time.
Maybe, but I've already spent more than the amount of time I wanted on this.
Just a thought, does undo.recordobject also rely on serialisation?
how can i make a selection handle ?
i plan to draw multiple handles in different positions on the same script
I'm trying to go through a list of scriptableobjects and then display the properties of those scriptableobjects on the inspector. Currently I've just only been able to get each of the scriptableobjects in the list and create a propertyfield for them (for testing) but I can't seem to do anything else.
My idea was to add each one to a list and then iterate through that list and get their properties but for some reason only Element 2 gets added to the array and I can't figure out why.
if (sp.isArray)
{
int arrayLength = 0;
sp.Next(true);
sp.Next(true);
arrayLength = sp.intValue;
sp.Next(true);
int lastIndex = arrayLength - 1;
List<SerializedProperty> nodes = new List<SerializedProperty>();
for (int i = 0; i < arrayLength; i++)
{
EditorGUILayout.PropertyField(sp, new GUIContent("Label"));
nodes.Add(sp);
if (i < lastIndex) sp.Next(false);
}
Debug.Log(nodes[2].displayName); //only prints "Element 2", no matter which index I choose (0,1, or 2)
}
When printing the display name of an item in the nodes list, it ONLY prints Element 2.
the property fields are fine, btw
(changed the label from new GUIContent("Label") to new GUIContent(sp.displayName))
i feel like this is similar to a closure problem since it seems to only add to nodes the last 'node' in the list I'm getting them from.
Because
@digital spoke When you Next() a SP, you move it forward.
When adding your sp to the list, you just add the same and again and again
You need to create a copy of SP
Hi Everyone!
My brain is melting, and I need a hand. (Please let me know if you think I should post this in a different channel.)
I have a line of code that compiles fine in the standard unity editor build, but fails when I try to compile it into a custom DLL (for unity editor). Clearly, I’m missing some DLL reference in the project settings of my custom DLL.
The function call giving me trouble is : https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodinfo.createdelegate?view=netframework-4.8&viewFallbackFrom=netframework-2.0
At the top of the page documentation it shows multiple dll’s, which, apparently include this function. *** How do I know which of these (AND which version of these on my computer) I should be including in my custom DLL references?
I’ve tried a including a few of them, semi-randomly ... some lead to a bunch of other weird errors popping up, and some have no effect.
@keen pumice Look at your .csproj
you mean the unity editor project? I havn't looked in that file.. but I do see in visual studio it has a TON of references... it even looks like it has all the DLL's at the top of that page.
Yep
You can either check those csproj
or check the references in your projects via Visual Studio
They are suppose to be equivalent
I did try adding a couple of those in.. had the results I metnioned.. I didn't try adding in ALL of them tho...is that actually necessary?
(feel like I shouldn't need to reference 5 dlls to use a single function...)
no no
you just need what is required
Only one
There is a simple trick
Click on your method CreateDelegate
And press F12 on it
At the top of the preview, you will the origin assembly
AH! cool.. ok .."mscorlib" .. trying it
and I should use the one in the Unity folder? This is what the editor project says..."C:/Program Files/Unity/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll"
oh! I got an error why I tried to add it..
which is cool... except that I get that compile error 😦
a seperate project .. but in the same "solution"
been working fine.. just get stuck with some of these missing references somtimes.. I don't see the pattern
Open the output window
Build
Look at the compilation command line
You will see several "/reference:BLABLABLA.dll"
hmm.. must need to turn that on.. don't see that at all...
yep
Tools / Options / Projects and solutions / Generate and execute
Set verbose to "Normal"
ok.. now when I compile the editor buld I see a TON of these... 2> Copying file from "C:/Program Files/Unity/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll" to "Temp\bin\Release\mscorlib.dll".
it loooks like all those that are in the project references.. still no idea which one to include.
not there.. oh: "The Do not reference mscorlib.dll build property doesn't exist in Visual Studio 2017."
lol
Well
To be honest
It's a bit hard for me to help you
I can only ask you questions to try to see the big picture
but you barely give me some
hmm.. perhaps I'm refernceing the wrong version of other dll's which is creating the problem... I see that the system.dll I'm referencing is NOT from the unity folder.. C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll
and I see that folder does not have a system.reflection.dll .. hmm
I'm just looking to understand the pattern/stardard procedure one should use to reference dlls. There are so many of each version! Guess I'll start by duplicing exactly the references in the editor project.
Well, I used the exact same references as in the Unity Editor project, and included system.refelection.dll... but the error persists.
(Also, had to updtae from .Net2.0 to .Net4.0 in project settings to work with those dlls)
AH.. got A fix: I removed the system.reflection.dll reference entirely.. and change project version again.. this time to .Net 4.5- it complied.. so what am I misunderstanding at the bottom of the docs.. looks like it's there in 2.0....
"Applies to
.NET Core
3.0 2.2 2.1 2.0 1.1 1.0
.NET Framework
4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5
.NET Standard
2.1 2.0 1.6 1.5 1.4 1.3 1.2 1.1 1.0"
.Net Framework is listed seperately.... does that mean anything other than marketing branding stuff.. is it relevant to the dll stuff??
which one does unity use?
does that mean my dll must use 4.6.. or can it use a lower version (and even if it CAN.. should I avoid that?)
so if I set my compiler to "2.0 Framework".. does that ACTUALLY mean it would use the ".Net Standard 2.0" listed as compatible.. (2.0 is NOT listed in the ".Net Framework" section). also... is THIS setting how it chooses which mscorlib version to use?
If I'm not wrong, that is right yes
There is a lot of framework, all have their own version of mscorlib
and others
Depending on what you need
some are light, others full
Is it possible to save a sprite created through code as a Sprite asset?
@cosmic dagger yes.
I tried just doing AssetDatabase.CreateAsset(sprite, ...) but the asset created is unreadable
is that not the correct way to do it?
Ah, right.
Yeah, I remember this... hold on.
I actually don't save mine cos I hit it.
You need to save the image as an asset too.
I believe.
Ah, right. Sorry, this is slightly different to what I did. I generated a texture at runtime and created a sprite asset for it so that I could add it to a UI.
So when I tried CreateAsset the sprites had no image data.
that's kind of what i'm doing
i create a sprite from a sprite sheet and then trying to save that sprite as an asset
Yeah, sorry, I don't know how to persist it to the project, mine is just for runtime.
hmm, ok
How are you generating the new Sprite?
Sprite.Create
Hmm...
var p = AssetDatabase.GetAssetPath(text);
Debug.Log("sprite.rect = " + sprite.rect);
p = Path.GetDirectoryName(p);
p = Path.Combine(p, spriteName);
AssetDatabase.CreateAsset(sprite, p);
var s = AssetDatabase.LoadAssetAtPath<Sprite>(p);
Debug.Log("s.rect = " + sprite.rect);```
what should be the file ending to a sprite?
Both Debug.Log() print the same for me, but if I look at the inspector it appears to have a 0 in the rect
.png right?
I do .asset
Given that I don't make a copy of the actual texture
I'm.. not sure if this is correct
i'll try .asset, but i need to copy the texture so i don't think it'll work
Yeah, if I try with .png it gives me an "File could not be read" error on the CreateAsset line
But.. the actual sprite that I've made does not appear to render
oh
it works
.asset works
i just thought i'd lose image data if I did .asset so i didn't try it
I'm guessing it just links internally to the correct texture2D
it must, because when i tried creating the sprite.texture it said the texture already existed
Like when you make a multisprite I assume that under the hood it creates sprite objects for each sprite and this one is just saved in a different location rather than the .meta file of the texture
im gonna try asking this again even though I don't think I'm explaining it well
I have a list of serializedobjects called nodes. I want to go through this list and draw the properties of these nodes onto the inspector
i'm not sure how to do this and every time I ask it seems people think that i just want to draw the contents of the list onto the inspector which is NOT what I want to do
at the moment I've been able to add the contents of the list to a list in my custom inspector script but it seems that their properties are not correct even despite the fact I have triple-checked to make sure I am getting the correct things so ?????
If properties!=content, define properties
these
every node has position but if I try to get it via FindProperty it returns null
Do you know how to find a property by path?
even though, I am getting the correct objects according to my debugging (this is me displaying the contents of the list I put the nodes into after getting them from the other list)
Look at propertyPath in your SerializedProperty
this is what it gives me
What you should try, get the cached Editor of the ScriptableObject draw it, repeat for each element
You are giving me the result, but never how you did it
How do you want us (helpers) to help you correctly if you give half the picture
Try to think from our point of view
what do you think I did? I literally just printed the propertyPath of one of the objects in the list. That's what it returned.
@digital spoke do you want to draw inline the inspector of these objects? So instead of opening up the object in it's own inspector it's right there?
Yes, this is his will
How can i replicate those controls ?
im sorry if i seem aggressive ive been trying to solve this issue (it started with ExposedReference)
i found something that I think might help me so I'm quickly going to see if that works and if it doesn't ill come back with code
welp
after all that, this works lmao
@digital spoke take a look at this code https://hastebin.com/biliqeqeto.cs
TestObject is just a ScriptableObject with some variables to test it out
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "TestObject")]
public class TestObject : ScriptableObject {
[Serializable]
public struct Test {
public string name;
public GameObject go;
public int y;
}
public int x;
public List<Test> list;
}```
@lilac python thanks but I found a solution that works fine.
Fair enough
@onyx harness also thanks for helping
is there a way to override OnInspectorGUI of a cached editor?
if (!editor)
Editor.CreateCachedEditor(property.objectReferenceValue, null, ref editor);
editor.OnInspectorGUI();
I want to do some stuff with the OnInspectorGUI of editor
@digital spoke have you seen line 30 of his script
Editor.CreateCachedEditor(property.objectReferenceValue, null, ref editor);
Oops haven't read your messages yet, my bad 😅
OnInspectorGUI is here to draw, if you want to bypass, either you recode the Editor, or just draw it yourself
i need to draw the editor in a specific way so i can set ExposedReference types and I'm not sure how to do that for a cached editor
the cached editor is handelling the drawing of Testing's properties. Object is a ExposedReference<GameObject> and I need to do some weird stuff to get it to work properly because of course I do
What do you mean by
draw the editor in a specific way
idk all I know is that ExposedReference's won't work unless I use the code from the example here https://gist.github.com/frideal/a55961c696acea49d54600c9f66c13ff
and I'm not sure how to do that since it seems I have no control on how a cached editor draws
Can you try to use Editor.DrawDefaultInspector()
instead of OnInspectorGUI
I never touched ExposedReference, I can't help much about those new things
exposedreference has been a thing for a while iirc
it's just that no one has seemingly ever used it outside of custom playables/the timeline in general
I'm stuck to 2017.4
exposed reference has been a thing since before that it seems considering it exists on 2017.1 documentation
O_o really...
it seems to have been introduced in 5.6
before unity started using the current naming convention of the versions
that's why this problem is so annoying for me, exposedreference is such a obscure type no one knows it exists
Unity really needs to give us a better way to reference scene objects in a scriptableobject
I'm not even sure I understand your issue right now
They are shown in your Inspector, but what do you want to do with them?
i want to be able to drag scene objects onto the Object field but I can't since it doesn't work like that for scene objects
That's very strange, because in my test, I can ONLY drop assets on it, not scene Object
Why not just store your data in a component on an in-scene object? If something is explicitly or implicitly tied to a specific scene, it should probably just be in that scene
Maybe you're hamstringing yourself by being set on using ScriptableObjects
well considering this a node editor, i kinda need to use scriptableobjects to store the data of the nodes
Not really...you can store the data of the nodes in a MonoBehaviour just as easily
im pretty sure that would require a pretty significant re-write of xNode's source code to use monobehaviour instead of scriptableobject
Ah, you're using a specific plugin as your node editor
yeah
i was able to get to the point where I can set an exposedreference on the node
but for some reason, they don't stay unless I set resolve it with a monbehaviour, it seems?
atleast that's what I've been told by someone in the xNode discord
Dunno, all that is specific to the plugin you're using, so the chat specific to that plugin will have more people who're likely to be able to answer your questions about it
he said "i've never used exposedreference, dunno"
well pretty much that (this is the creator of xNode)
only one guy on there has been able to help but but I think I'm pretty much stuck at this point.
I need to be able to handle how the cached editor draws but I can't override any of it's functions
can you believe this was just to get over the inconvenience of using custom playables for a completely unintended purpose
wait a minute...
@digital spoke Use this to see the paths
public static void OutputHierarchy(this SerializedObject so)
{
SerializedProperty it = so.GetIterator();
//it.Next(true);
while (it.Next(true))
{
if (it.propertyType == SerializedPropertyType.String)
Debug.Log(it.propertyPath + " " + it.stringValue);
else if (it.propertyType == SerializedPropertyType.Integer)
Debug.Log(it.propertyPath + " " + it.intValue);
else
Debug.Log(it.propertyPath + " " + it.propertyType);
}
}
public static void OutputVisibleHierarchy(this SerializedObject so)
{
SerializedProperty it = so.GetIterator();
it.Next(true);
while (it.NextVisible(true))
Debug.Log(it.propertyPath);
}
I dont know if you do a lot of editor scripting, but I am preparing a series of tips for the editor world. If you are interested, I will tag you the day I start
no it's fine.
isn't there some UI elements wysiwyg editor?
I thought I heard something about that
but I've only seen the UI Elements debugger
Heard about it, don't know much
and speaking of the UI Elements debugger
it seems a bit buggy sometimes
but the workflow is promising
this is it I guess?
I guess
will give it a try
Keep me in touch 🙂
Man, this is Unity, there is always a catch X)
haha I mean I'm just going to use it for simple stuff so I will probably not 'reach' the 'catch'
but it's cool, just drag and drop elements, edit properties, see instant changes
and also I can preview how it looks in dark mode, which is super nice for a free user
Say whaaat?? Hahahaha they thought about it, amazing
I think the catch is that it's UIElements
Mikilo don't want to tag you but check
generic asset support menu made with relative ease using UI builder
Don't worry, i'm always there 😄
We are all expecting drastic increase of UI building efficiency
I'm expecting to hit lots of edge cases
That make me hate my life
And I'm expecting lots of unnecessary boilerplate
also if UI elements is a package
that means that it will be a dependency for my asset if I use UI elements for editor windows etc
Yeah that'll be fun
If you don't want to support all versions of UIElements and some other package requires a newer/older version; then you're fucked
It would be surprising to have UI Element as a non native package
so it would come pre-installed when user downloads Unity?
They (Unity) are revamping all their windows with it. If the package is not present, how is the editor running?
To be honest I don't know, but the opposite is quite strange when you think about it
you're right
Hello. I need to create a ReorderableList inside a loop on the OnInspectorGui. My problem is that creating a ReorderableList inside this method makes it impossible to remove or drag items arround.
What can I do to make the remove and drag items arround possible when creating a reorderable list ?
Can you show your code?
public override void OnInspectorGUI()
{
serializedObject.Update();
DrawDefaultInspector();
EditorGUILayout.Space();
for (int i = 0; i < interactionProp.arraySize; i++)
{
SerializedProperty interactionListRef = interactionProp.GetArrayElementAtIndex(i);
SerializedProperty objectTypeRef = interactionListRef.FindPropertyRelative("objectConcerned");
SerializedProperty eventsToLaunchTypeRef = interactionListRef.FindPropertyRelative("eventsToLaunch");
AddPopup(i, ref objectTypeRef, "Object concerned : ", typeof(ObjectSettings.ObjectType));
ReorderableList list = new ReorderableList(serializedObject, eventsToLaunchTypeRef, true, true, true, true);
list.drawHeaderCallback = (Rect rect) =>
{
EditorGUI.LabelField(rect, "Events to launch");
};
list.drawElementCallback =
(Rect rect, int index, bool isActive, bool isFocused) =>
{
var element = list.serializedProperty.GetArrayElementAtIndex(index);
rect.y += 2;
EditorGUI.PropertyField(
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
element, GUIContent.none);
};
list.DoLayoutList();
}
serializedObject.ApplyModifiedProperties();
}
Ok thank you I'm going to try and cache it.
But I need to create it on the OnInspectorGUI() method because it tries to fetch a list of items from a list that is serialized and updated on the OnInspectorGUI() method
That's not how it works
you can create it in OnEnable
seeing as it uses serializedProperties and callbacks
Best case you'd want to create it in OnEnable
You can and should initialise almost all SerializedProperty values in OnEnable when you can
And if the list changes you remove/create a reorderable list
If the list changes entirely like, it's a completely different list, you'll have to make a new one
Thank you again it works now 😆
@waxen sandal @onyx harness @lucid hedge Honestly, the UIBuilder and UI Elements in general are actually an excellent UI package overall
it combines the strengths of WPF and HTML/CSS and does so quite well
I agree
the main issue I've run into is Z-Ordering of popups
which i was able to solve, but it was a problem
but I've never done a lot of advanced editor scripting though
Hahaha I knew you would be around about this subject 😅
😄
UIElements is Love, UIElements is life
seriously though, been doing WPF for 10 years, some html/css here and there, winforms, and of course the scourge, the evil queen, known as IMGUI
But you said it, UI Element needs a package?
yes it does
well, no, the UI Elements Builder needs a package
UIElements itself is integrated into the core
and the debugger is also part of the core, so you don't need that either.
@lucid hedge well, we got our answer here
The rabbit hole goes deeper
it will be a package
Not being a package currently carries some limitations in their flexibility, slowing down the development pace for UIElements, and preventing them from providing support for a few scenarios
so they are migrating to using a package, which will of course probably be forcefully installed
yeah that forum page is why I asked
its just like a number of existing packages which always exist and can't be removed (atleast as far as I can tell)
Imagine you update the package and there is a bug.
Boom Editor is not usable anymore
hey look i finally got it working
i can now set the exposedreference of my nodes
but now i have the small issue of that it's kinda annoying to have to set exposedreference's in the inspector rather than the node editor
reason why is because Unity refuses to save ExposedReference types when restarting the editor unless IExposedPropertyTable is inherited in a monobehaviour.
Re UIElements Runtime, is what in UIElementsUniteCPH2019RuntimeDemo the same as 0.0.3-preview hidden package?
Would anyone know how to not need to make wrappers for a structure like EnumCollectionDrawer<TEnum, T> : PropertyDrawer ?
or to automatically make the wrappers
Just derive the class
I mean to use that drawer I need to keep add for each class that uses it [CustomPropertyDrawer(typeof(LayerAnimator))] public class LayerAnimatorDrawer : EnumCollectionDrawer<Layer, Animator> { }
it's getting old
You have a second argument in the CustomPropertyDrawer to include derived classes
Execpt you can't use generic types inside of attributes :S
the way I'm presently thinking is way hacky so
It's about altering the dictionary in charge of selecting the right drawer from a given type
it's be easier to check the assembly and write a wrapper file in code IMO
How? What would you gonna do in your wrapper file?
in the editor use the [DidReloadScripts] then reflection to find all the types of the base classes
then write a cs file via code with the wrapper stuff
meaning by hand you'd only have to do the one generic wrapper and then unity will write the drawer wrappers
And the day you remove one derived class, you break compilation
how?
You have type A and B.
You generate LayerADrawer and LayerBDrawer.
The day you delete A or B, your script will stop compiling
the most you'd get is an error that the dependent class is not defined, you delete the unneeded wrapper.
If this flow is fine for you, I won't push ;)
I'm going to test it and see at least
worst to worst I'm just back to writing them by hand
If it is fine for you, I'm good with it
I'm confused about how to access certain classes from my project. Specifically, UnityEditor.UIElements.EditorMenuExtensions seems completely missing/inaccessible from my project (I'm running 2019.3.0b7 and this class clearly exists in the reference source for 2019.3.0.a3).
I don't understand if it was removed from its assembly at some point, or what is going on here.
It seems likely because the EditorMenuExtensions class is private, which is weird. I don't see why it would be.
Anyone have experience using Data Binding systems?
Specifically I’m trying to bind UI elements - slider and toggle to game object parameters and exposed VFX/ Shadergraph stuff
@tulip plank a lot of things that could have been public, are private. Nothing surprising
@onyx harness While I would totally expect Unity to do something like that, it was used as a solution provided in a Unity forum--though granted, it was provided by a Unity employee, so maybe they took for granted the fact that they were working within that project. :/
In any case I copied the code from the reference source and put it in my own project.
If it works, it works.
Or you can create a wrapper with Reflection to mimic the private clasw
👍 I like your style.
The benefit doing this way is, as long as their methods' signature remain the same, it is forward compatible
I can provide a class wrapper generator if you want
Hah, you've written such a thing? I mean, that sounds amazing so I'd love that (assuming it already exists, I don't want you to do that work just for me.)
It is done already.
I will send it to you tomorrow
okay so I've been using the UI builder some more
I love the workflow and speed you get of just designing an interface
sometimes it freezes big time though
and also I have yet to figure out how to create custom elements and add real interactivity instead of just nice looking designs, I'm not sure if those things are really doable without coding
they are and are not
Any clarification?
Sorry, I got totally distracted
so you can do a lot with binding paths to get things done, but some more complex interface issues are not so simple
like having a list selection feed some other display basically requires code behind
but anything for modifying the contents of a UnityEngine.Object can basically be done through binding
I built a little framework for making some of that easier
the first link is setup for loading into the package manager
it may just serve as useful examples
basically, yuo will not build a comprehensive UI without atleast some coding, its required, how you setup that code will determine how much code you have to write
which is why I built those two repos, because I wanted to reduce the amount of code I needed to write to create more complex interactions
@tulip plank What Unity version are you using?
2019.3.0b7
Does anybody know if there is an equivalent command line to build for WebGL like this command:
-buildWindows64Player [buildpath]
The command line -buildTarget <name> only specifies the build output but no path
Hey all! Just wondering, can i create a MonoBehaviour with a field ScriptableObject, where GameDesigner could drag desired asset file, and after that choose what field from the SO he / she would like to use in later functions (for ex. display chosen one as a text)
Something similar to this one:
Where some dropdown menu would have all fields like, ID, name etc.
@arctic frigate Yes you can.
"I'm understanding the semantic of the question but ignoring the meaning" – "Can you give an example?" – "Yes, I can" 🙂
He is just wondering, so I answered as precised as I could 8)
I think the real question is "how"
I never answer that question.
"What Unity version are you using?" – "The one I have installed", like this? 😆
The reason is very simple.
If the question is not backed with background elements. I am not going to make the job for him/her.
I don't wanna help people if they don't do their homework.
Gladly, this Discord has no gamification.
While I try to educate those young programmers, nobody (or rarely) will try to bypass my help and drop the work.
Yeah, I agree, doing homework is important. But often people are stuck and not just lazy, and they need nudge in the right direction
Anyway, not complaining, just noticed it's funny 🙂
Well, they really need a very minimum of homework to allow me to guide them.
Especially when the request is more complex than just "shit, do you have a method/algorithm to do that?"
If the answer is just an API, I don't have any to problem to tell them.
Or, if I know the author behind the question is someone who did his homework before. I don't have any issue helping them.
I try my best to not answer, but to guide them.
So they can guide themself later and not come back to this Discord ever 😄
Your definition of success would be "noone ever ask questions again"? 🙂
Yes. Because little bird became a PHOOEEENIXXX!! 🤪
can confirm I once asked Mikilo a question and he didn't hold my hand and instead I found it myself and felt very proud
Okay, here is a question (and I will come again). I'm using SO to configure an AssetPostprocessor and I need a property that represents a folder. I've found that folder is represented as DefaultAsset and I can use AssetDatabase.IsValidFolder to check if it is a folder. So far everything works fine, except I want to disallow selecting non-folders. Right now I issue a warning during import if there is a non-folder asset in the property, but I want to prevent it in the first place. Is there some kind of validation logic that I can plug into and filter non-folders from being drag'n'dropped into the property or selected from the list? If there is, what's the API? I probably can plug into UI events and handle Drag* events, but that's too low level and also doesn't handle selector window.
Bonus question to Unity devs, if any, is why there is no FolderAsset? 🙂
Your property, use a custom property drawer to filter it manually.
(I'm off to bed, will reply tomorrow)
hello, i'm stuck on editor stuff :/
I would like to have dropdown with values in my inspector, that i can change when my project is not playing
i want these values to be used in a script in the scene, i used a editor script, and i popup the content of my lists using EditorGUILayout.Popup
I change my 2 dropdowns than hit play, but when the project is playing, dropdowns have been reset to default values (so dropdown value changement is not saved when i hit play
here my editor class
before i hit play :
just after i hitted play :
the target class :
That's because you are saving the option selected in the editor
And editor is reseted when you enter play mode
is there a way to maintain those changes when i hit play ?
Having the selection in the MonoBehaviour or using PlayerPrefs or something like that
No, it can be a normal field
If it's static since it cannot be serialized it'd be reseted aswell
hes already saving it
var prevChoice = (target as DebugManager).url;
var indexFromPrev = options.indexof(prevChoice);
choice = EditorGuiLayout.Popup("Servers", indexFromPrev, options)
same deal with the other popup
You can change the int for a string?
I mean thats wrong, you'll need to reverse lookup the index from the options
Oh okay
something like that now
that could certainly fail, if the values are changed in options
I'm gonna stop now because I keep making tiny mistakes
var indexFromPrev = System.Array.IndexOf(options,prevChoice);
i'm trying this
dont need this part anymore ?
OK i kept this part, and this is working, thx 🙂
I have a EditorGUILayout.LabelField($"Summary: {t.GetSummary()}", GUILayout.ExpandHeight(true)); and I want all the contents to be visible when it overflows like in html. How do I do that?
Don't use the default style of LabelField
how do I avoid that?
You can provide a GUIStyle just before your GUI layout option
GUIStyle.none?
No no, more like from a copy of label style:
var label = new GUIStyle(EditorStyles.label);
label.wordWrap = true;
ah
thx
now i have this: var wrappingStyle = new GUIStyle(EditorStyles.label); wrappingStyle.wordWrap = true; wrappingStyle.alignment = TextAnchor.UpperLeft; EditorGUILayout.LabelField($"Summary", t.GetSummary(), wrappingStyle);
Good but not good
why is the text centered?
oh well, i an live w/ this
Is the text shifted, or your below GUI shifted?
not intentionally
Write a test. LabelField("A", "B")
var wrappingStyle = new GUIStyle(EditorStyles.label);
wrappingStyle.wordWrap = true;
wrappingStyle.alignment = TextAnchor.UpperLeft;
EditorGUILayout.LabelField($"Summary", t.GetSummary(), wrappingStyle);
EditorGUILayout.LabelField($"A", "B");
You can play with labelWidth
Using EditorGUILayout.PropertyField on a Texture2D I get this
but is there a straightforward way to get it to show up like this?
like in a material editor
so that there is a visual 'preview' of the texture and a 'select' button
Augment the height?
Don't put too much effort into it, it's not super important
a Texture2D
Strange
if the Type is deriving from Texture or is a Texture or Sprite, and the height > 18F, it should display a big preview
Alright well it's not important, just think it looks nicer with a preview but no big deal at all
thank you for looking in to it 🙂
Where did you find the information?
From this:
EditorGUILayout.ObjectField("Test 1", null, typeof(Texture2D), false, GUILayoutOptionPool.Height(64F));
EditorGUILayout.ObjectField("Test 2", null, typeof(Texture2D), false, GUILayoutOptionPool.Height(24F));
EditorGUILayout.ObjectField("Test 3", null, typeof(Texture2D), false, GUILayoutOptionPool.Height(32F));
EditorGUILayout.ObjectField("Test 4", null, typeof(Texture2D), false, GUILayoutOptionPool.Height(48F));
I got this:
I am using EditorGUILayout.PropertyField
Sorry, I never use PropertyField 🙂
I don't think PropertyField has the ability to do it
what are the downsides of using PropertyField?
Well you got one already.
haha
PropertyField is great
just not when you want something specific
you could make a PropertyAttribute and Drawer pair that enables you to use PropertyFields
or tag anything to use that specific object field impl
yeah that's not worth it in this case, it's really a small small detail
Also looking at the actual CS source the logic for which it draws makes a lot more sense
I could also use this
Texture2D texture = AssetPreview.GetAssetPreview(sp.objectReferenceValue);
This is why PropertyField can not handle what you want.
The 3rd argument is the Type, which is null.
And as I stated above, it needs a Texture/Sprite or deriving one
that's interesting
I prefer to say it is stupid 🙂
Even if SerializedProperty does contain the true inner Type. It can fetch it somehow.
Performance speaking, it's not the best I give them that point
Is it possible to rename scenes (hopefully enmasse) with an editor tool?
Yes.
Do you know which function I would use? I can make the window etc, I just havent found anything for the actual change yet
A scene is just an like any asset
Which implies they are Object.
Implying they have a name.
AssetDatabase.RenameAsset
ah, thanks!
How to play an AudioClip from an editor script?
There's an internal class AudioUtil that has an internal method PlayClip
you could call that
hello, I got the Odin editor for unity during the black friday sale and I am loving it so far. I am having one problem with it though and that is that the min max slider is hard to set the exact value I want with it. is there any way to make it increase / decrease it in increments for example it moves up or down by 0.5?
This channel is mostly for editor scripting, you have a better change in #💻┃code-beginner or #💻┃unity-talk
thanks
I'm finding that overriding public override bool RequiresConstantRepaint() to return true even with an empty inspector trashes my editor performance (~6ms -> ~30ms) - is that expected? 2019.3.0f1 - UIElements any better for this kind of thing (i.e. an animated progress bar)?
I would not recommend overriding this one
Prefer using onMouseMove and repaint on a real event MouseMove.
@split bridge
unfortunately that doesn't work for a progress bar...
what exactly is your progress bar?
editor-preview of a tween
I guess you are drawing something and need the next frame to repaint to keep animating?
If it helps... looks something like this
Yeah this is what I thought
The moment you start doing your "animation"
You just call Repaint()
Until your "animation" has completed.
sure, that's what it does currently
also when you roll over the buttons (even though it takes a while before the first mouse move in the area is detected)
So what is the issue then? I don't get it
the massive drop in editor performance.. when all I want to do is re-render that small bar
do you know if UIElements is any better in this regard?
so hang on, are you saying that calling Repaint is cheaper than setting RequiresConstantRepaint()?
If repainting is eating your CPU you need to question your code
Yes
I never used UIElement, can't tell
But from my feeling whenever I am in Unity 2019.3, I feel the experience is utterly slow
the performance drop happens even with an empty OnInspectorGUI so don't think it's my code
RequiresConstantRepaint() is basically a... constant repaint...
but isn't calling Repaint in OnInspectorGUI the same thing?
I see the same performance characteristics
I don't think you are using the proper word
I don't think performance drop is the right word
I think you mean you are seeing your CPU busy while nothing is done, am I right?
If you don't profile it, your statement remains weak
Define "performance characteristics".
This is the difference between calling 'Repaint()' in an otherwise empty OnInspectorGUI() or not
perhaps this is a .3 thing
hmm interesting, I didn't expect deep profiling the editor work (did it always?)
Yep
What is DOTS doing here, do you have an idea?
going to try and replicate in a blank project
Good habit.
But from my feeling, UI Element is really not on point. It's like the inertia is really really huge, like you are moving a bulldozer
oh?
I didnt profile it, but I know one fact, they implement hovering of element
This means onMouseMove is ALWAYS active.
Which triggers Repaint() on each move.
Technically, it is not suppose to be an issue, but in UI Element it is
@split bridge Keep me in the loop please, I would like to know
(If you have any interesting data of course)
so... it seems like the mention of DOTS is due to the LiveLink edit mode... but it's not the cause of the slow down and I can reproduce similar in an empty project
What is deep profile telling you then?
Remove VS please, I need to see the metrics X)
Can you unfold at the first line having 0KB of GC Alloc?
What is important here is the whole call stack, not just the deepest one
Because after 0KB, they all have minor impact
sure - though if you have f1 installed, I could just sent the two minimal scripts if it's easier
That's true X)
The truth is I want to know what is happening, because I will be impacted, but I am too busy working on other stuff
We can stop investigating if you want
well to me, it looks editor-related and worse perf than we should expect... so unless you think differently I'm kinda assuming this is an issue that they'll fix in f2 or f3
I guess I could try the same in 2019.2 but it's getting late here
Hope you are right
Hi all
I am playing around with the new [SerializeReference] in conjunction with some editor scripts but for some reason I lose my interface references if I close and reopen Unity. It seems to work fine between edit/play mode but doesn't survive closing Unity. Anyone with an idea how that is so? My other changes/variables that aren't interfaces are saved properly, because I use EditorUtility.SetDirty(object);
I think it is still a subject to limitation of Unity serialization. You can't reference scene objects... in a normal way.
In the assets that is
In my case, I am not referencing a unity asset. My code is as follows:
public class TileArray : ScriptableObject
{
[SerializeReference]
public List<LevelGrid.TilePair> tileArray;
[SerializeReference]
public ITileOccupy objType;
}
As you can se, ITileOccupy is an interface:
public interface ITileOccupy
{
TileObjectType TileObjectType { get; }
}
During edit time, I create a GenericBaseObstacleTile which implements ITileOccupy and assigns it to objType:
public class GenericBaseObstacleTile : ITileOccupy
{
public TileObjectType TileObjectType => TileObjectType.Obstacle;
}
Vice versa, referencing a scene object in the asset directly is not supported.
Huh, interesting. If that is not the case, what use case does it have?
I haven't got a chance to use it yet. But if you are using just one scene you can use a work around featured here. I think. https://www.youtube.com/watch?v=raQ3iHhE_Kk
Using generics they (scene objects) can be referenced sustainably.
From the looks from this post, it seems like I should be able to Serialize an Interface on a UnityEngine.Object: https://forum.unity.com/threads/serializereference-attribute.678868/#post-4543723
The funny thing is, the serialization works fine between edit and play mode, so its not the serialization itself. It is just that the object is destroyed when I leave Unity and return.
Where could I find some good and latest tutorial / courses to learn how to build great menu / layout whatever about GUI in Unity?
Perhaps it is saving InstanceID which is not persistent. Maybe I'm saying shit.
When I investigate the ScriptableObject with a text editor, I can see that it has actually saved the type to disk:
@unborn bluff Objects present on the scene are not persistent. I assume your tileArray references something on the scene. Because scene can be unloaded at any moment. That's the limitation. Again, using generics you can persistently reference those.
@stark geyser it doesn't reference anything in the Scene
I don't quiet follow you. My setup is:
ScriptableObject (TileArray.cs) contains a single field ITileOccupy. The type I assign to ITileOccupy is GenericBaseObstacleTile : ITileOccupy (notice it does not derive from MonoBehaviour). So I don't fully understand why I would lose anything by closing and opening Unity. Especially when I can see directly in the .asset using notepad that it is actually saving my Interface instance.
@rustic abyss For the latest, probably one of the numerous YouTube channels may have some. There are learning resources in pins in #💻┃unity-talk which have older ones.
If you can lose it by unloading a scene, this is what happens,
@stark geyser oh thank you, i didn't know that there are pins! gonna check now!
@stark geyser alright, I have simplified my problem. The following still doesn't work:
using UnityEngine;
[CreateAssetMenu(fileName = "TileArray", menuName = "ScriptableObjects/TileArray", order = 1)]
public class TileArray : ScriptableObject
{
[SerializeReference]
public TestInterface interfaceField;
[ContextMenu("Create Instance")]
public void CreateInstance()
{
interfaceField = new TestInstance();
}
[ContextMenu("Print")]
public void Print()
{
Debug.Log(interfaceField);
}
}
[System.Serializable]
public class TestInstance : TestInterface { }
public interface TestInterface { }
This is all the code there is to reproduce the issue.
In what way it doesn't work and where is the object you are referencing. Also checkout its limitations in the manual.
I just believed I figured it out.
If I run CreateInstance() and then run Print() it will print:
"TestInstance".
Closing and opening Unity, on the same ScripableObject running Print() then returns:
"Null"
However, I now tried adding just adding a single integer into the class instance. Then, after closing and reopening Unity it now prints properly.
using UnityEngine;
[CreateAssetMenu(fileName = "TileArray", menuName = "ScriptableObjects/TileArray", order = 1)]
public class TileArray : ScriptableObject
{
[SerializeReference]
public TestInterface interfaceField;
[ContextMenu("Create Instance")]
public void CreateInstance()
{
interfaceField = new TestInstance();
}
[ContextMenu("Print")]
public void Print()
{
Debug.Log(interfaceField);
}
}
[System.Serializable]
public class TestInstance : TestInterface
{
public int someValue = 5;
public int GetValue
{
get
{
return someValue;
}
}
}
public interface TestInterface
{
int GetValue { get; }
}
I would categorize this result as a bug in my opinion.
Yea, but in this case you are creating TestInstance only in memory. Only assets are persistent.
same thing will happen if you do this with Scriptable Object
This not what I understand from what jsonm_unity3d said here:
https://forum.unity.com/threads/serializereference-attribute.678868/
SerializeReference allows to save classes, it being an Object is optionnal.
And as FreakingPingo said, it works with a field, but not without a field.
This really smells like a bug.
I didnt try his code above, but I will keep that in mind the day I will tackle this new feature.
It has been too long since I last created a bug report: http://fogbugz.unity3d.com/default.asp?1203848_qtet0hej5prr7tqm
I am fairly sure this is a bug. I can't imagine this is expected behaviour
What is the proper way to use Undo for multiple objects? I tried
foreach (var obj in Selection.gameObjects.Select(c => c.GetComponent<Text>()))
{
Undo.RegisterFullObjectHierarchyUndo(obj, "Text Conversion '" + obj.name + "'");
//... my actual logic I do in the for-loop exists below this line
}
But that just seems to crash Unity, and I tried other forms of Register as well, with the exact same crashing result - my guess is that im using it wrong, or that it shouldnt be called in a for-loop, but I cant think of another way to do it other than maybe a coroutine with a WaitForSeconds(1f), since I didnt see any callbacks or "isDone" type of functions I could use (but I feel like a coroutine will probably end up with the same crash result)
Why not just simple registration?
What do you mean? Like the deprecated function, Undo.RegisterUndo(obj, "..."); ?
How do I display the "default" inspector for a non-MonoBehaviour that has the [System.Serializable] attribute, inside an EditorWindow?
I know you can do the following for UnityEngine.Object classes.:
Editor editor = Editor.CreateEditor( gameObject );
editor.DrawDefaultInspector();
But I am not sure what to do if it is an ordinary class.
Huh... I just discovered Undo.DestroyObjectImmediate(obj); which basically solves what im trying to do, but still crashes Unity inside a for-loop, now its almost like 50-50 though, sometimes it will, sometimes itll work o.o
@unborn bluff you need to serialize an Object, get the SerializedProperty and display it with a PropertyField.
@shadow violet oh its deprecated, didn't know
Make simple test, test over a loop of 2
Yeah, but after enough research, I found a very disgusting way of doing it, but it seems to work... O.o
void MyFunc()
{
m_LastEditorUpdateTime = Time.realtimeSinceStartup;
EditorApplication.update += OnEditorUpdate;
//for-loop logic I need to perform on Selection.gameObjects...
queueDestroy.Add(objFromLoop);
}
static void OnEditorUpdate()
{
float diff = Time.realtimeSinceStartup - m_LastEditorUpdateTime;
//destroy old text objects in replacement of the newly converted one, with UNDO,
//doing it in this way, prevents Unity from crashing a stack overflow, due to
//calling Undo operation, destroy, and reference loss, several times in a static for-loop
for (int i = 0; i < queueDestroy.Count; i++)
{
if (diff >= 0.12f) //"wait" a small timeframe
{
try
{
GameObject obj = queueDestroy[i]; //has to be referenced otherwise either Undo will queue nothing after Remove, or vice versa
queueDestroy.Remove(obj);
Undo.DestroyObjectImmediate(obj);
m_LastEditorUpdateTime = Time.realtimeSinceStartup;
}
catch { }
}
}
if (queueDestroy.Count == 0) { EditorApplication.update -= OnEditorUpdate; } //unsubscribe to prevent spamming the Editor
}
Now that I think about it, I probably could use a Queue<GameObject> instead of a List<GameObject> but this seems to get the job done without crashing o.o
Why delaying the destruction?
Cause otherwise, Unity will crash (and my only guess is, it may have something to do with how Destroy works internally, cause even using the regular GameObject.DestroyImmediate, it still crashes - and the Editor log has nothing relevant on what happened)
Can I see the full code?
Have you tried just registering then destroying only. Without doing any other action.
Just to make sure this is this code that crashes
Sure @onyx harness (https://hatebin.com/cihqntoueg)
OnEditorUpdate on line 17 is basically my "coroutine", in the lightest terms possible - ConvertSelectedToTMProContext on line 43 is what the user will use from the Hierarchy context menu - then ConvertUnityTextToTMPro does the actual work, for all functions
And I have, I tried commenting out everything else, and maybe the function is called multiple times (so I tried to put in some hardcoded "stops"), or something else is going on, but it seems to be just the destroy lines, cause with them commented out previously, everything worked flawlessly it just obviously didnt destroy anything
OK ok, well if you are on the latest version, just make a bug report
Oh, ok im not on the absolute latest version, my project is in 2018.3, but I do plan to form this into an asset, cause im sure it could help some others as well - ill put in a bug report anyway, just incase
does someone have a script thats create sortinglayers?
@rustic ginkgo Can you elaborate
@shadow violet in fact i wrote a script for that years ago
To replace a any Component A by any other Component B.
Not even sure it wouldnt crash like you
Yeah, the only downside I just realized with my system, (minus the workaround for crashing), is that it will destroy the old object, so if you had components or scripts on it, none of those would get carried over - maybe there might be a way to solve that, but for now, I just decided to add a "checkbox" function to decide if the object should be destroyed or not, within the users control @onyx harness
Is this intended behavior in UIElements? When registering Mouse Enter/Out events on the element, mouse out event gets called each time pointer enters and leaves a child element. For example:
Events are registered on gray background element, squares are children
I'd except an enter as well in that case
It's probably a "feature"
Just like how it doesn't work in editors for animator state scripts
Doesn't look right. If it were Enter, Out, Enter, Out there would be some logic in it.
I'd file a bug
does anyone know how to reorder these root level items?
we can use the priority argument in MenuItem attribute, but that only affects the items inside the menu
I want to reorder the root level stuff
The Reflection error or GUI error?
both of them
Drop the stack tracew
Because it does not work like that
OnSceneGUI is a Unity message.
Just change the name.
fixed, thank you
although
what I wanted to achieve is this
but it says onSceneGUIDelegate was deprecated
and I should use duringSceneGUI
so I did
but it doesn't have the effect of drawing handles whether selected or not
Which is fine. But not with this exact method name.
Oh
Put a log, to see if it is triggered
Yes
Which is normal XD
OnEnable is called only if the Editor is created
Which will never, if you don't select it
yeah but so what is a workaround to have handles be always displayed?
I switched to gizmos haha
they fit better in what I'm trying to do actually
I only need the visuals in play mode
sorry
it makes me sad that you abandoned uielements
@lucid hedge There's a Handles.Begin() which works like EditorGUI.Begin() (or something alike)
I am having an error when I am trying to use the UnityEditor.Build library, error CS0234: The type or namespace name Build' does not exist in the namespace UnityEditor'. Are you missing an assembly reference?
What have you tried?
Not many things, the script is inside a folder called Editor and I have tried using #if UNITY_EDITOR
I am working on a linux machine that is running fedora
I am using Unity 5.4.0p1
Can you show a screenshot or code?
Anything that we can use to help you
Because we are not god among humans X)
Also, for your information:
This API is available since 5.6.0, not before.
https://sabresaurus.com/unity-api-versioner/?api=UnityEditor.Build.BuildFailedException
Search every Unity release since 3.4.0 for when API calls are present and where.
I guess that google was wrong by saying that admob could be used in any version above Unity 4.6.8
I guess you're right
Thanks by the way
Wait you searched for UnityEditor.Build.BuildFailedException which means that BuildFailedException might be a subfile of UnityEditor.Build right?
I used the first class VS suggested me
Used the one you would like
Because remember, I don't have a clue what you used
As I mentioned befor I am having the error on the line using UnityEditor.Build it is saying that Build does not exist in UnityEditor so the library can not be imported cause it can not find the file
But it does find the UnityEditor
`#if UNITY_ANDROID
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Build;
#if UNITY_2018_1_OR_NEWER
using UnityEditor.Build.Reporting;
#endif
#endif`
The error is on the 10th line
That is importing the UnityEditor.Build
If I had more infos about what is going on I would have told them
When I googled the error I found almost nothing
Use triple backticks ```cs
and end it with triple backticks
for code
You have UnityEditor, which is right.
But the error is about UnityEditor.Build. Which might not be available before 5.6
Thanks for the tip, moreover the link you sent to me is not exactly right since I tried searching for UnityEditor library and it says that the first released was at 2019.1.0f2 but the library exists back in Unity 5.4
Is it possible that the UnityEditor.Build library is a part of a unity asset package?
From unity?
Which classes of UnityEditor have you searched?
I guess that, I was wrong, I searched for UnityEngine but it matched with UnityEditor.Compilation.CompilationPipeline.PrecompiledAssemblySources.UnityEditor
I am downloading a new unity version I will inform you if it was a version problem
Does anyone know of a good solution to drawing many thousand handles / gizmos in the scene view?
as in round about a 100K lines or so?
@onyx harness thanks I ended up using a geometry shader
working on some vector field based nav
Much better solution, gj
I'm generating some jpgs in an editor window and want to change the texture's wrap/filter mode after creating them. However the changes don't seem to stick. Here's my code. Any ideas? This is in an async script, but making calls to Unity has worked so far, so I'm not sure why changing properties on the texture wouldn't work.
var texturePath = $"{textureFolder}/{tileKey}.jpg";
var texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));
if (texture == null || !skipIfAlreadyCreated)
{
texture = await DownloadTileTexture(tilePosition, token, urlTemplate);
var fullTextureFolder = $"{Directory.GetCurrentDirectory()}/{textureFolder}";
var jpgBytes = texture.EncodeToJPG();
using (var jpgFile = File.Open($"{fullTextureFolder}/{tileKey}.jpg", FileMode.OpenOrCreate, FileAccess.Write))
jpgFile.Write(jpgBytes, 0, jpgBytes.Length);
AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceSynchronousImport);
texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));
}
texture.wrapMode = textureWrapMode;
texture.filterMode = textureFilterMode;
To be more specific, the changes don't work when the jpg is created. If it already existed and was loaded correctly on the second line the changes do stick Nevermind they don't ever get applied. Weird
You should use serialized objects or record it with Undo
Hello ! I'm trying to render prefabs contents (Sprite Renderers) in the editor scene without instantiating them (preview a prefab in the scene as a Gizmo). While it's moslty ok, I'm having bad times with their position. Any help would be greatly appreciated. Here is the code :
https://pastebin.com/0PZ6sewE
@wispy delta delay it
And print a log, to make sure you are on the right asset
@waxen sandal why do you want him to use SerializedObject?
@calm thistle what is the issue exactly?
@onyx harness Where should I put the delay? To test, I set the texture to null before importing/loading the asset and it appears to be assigned correctly.
EditorApplication.delayCall
No luck with this. Does it look correct to you @onyx harness?
EditorApplication.delayCall += () =>
{
texture.wrapMode = textureWrapMode;
texture.filterMode = textureFilterMode;
};
Debug.Log(texture, texture);
And click on the log to make sure it is the new one you just wrotr
You should create the asset directly, and not importing it
@onyx harness The position of the gizmo is different from the position of the transform. This...
Vector3 size = Vector3.Scale(cachedRenderer.bounds.size, cachedRenderer.transform.lossyScale);
ops[i] = new GUIOps
{
screenRect = new Rect(cachedRenderer.bounds.center - (size/2), size),
texture = croppedTexture
};
... should give me the rect of the sprite renderer in its prefab world position while this...
for (int i = 0; i != ops.Length; i++)
{
GUIOps op = ops[i];
Rect rect = op.screenRect;
rect.center += (Vector2) transform.position;
Gizmos.DrawGUITexture(rect, op.texture);
}
... should reposition the rect center using the current transform position but the texture is drawn with its center on top left, top middle or top right depending on the transform position.
I was creating Texture2D .assets originally, but I ended up needing actual image files. Can I create jpg files via AssetDatabase?
You can see here how the position of the texture doesn't change while its rect.center does.
@onyx harness I got it to work like this:
var importer = (TextureImporter)AssetImporter.GetAtPath($"{textureFolder}/{tileKey}.jpg");
importer.filterMode = textureFilterMode;
importer.wrapMode = textureWrapMode;
importer.SaveAndReimport();
Hey guys, i just downloaded Unity and VS Code on a new computer, but i can't find a way to get AutoCompletion for unity, i tried adding "Unity Tools" and "Debugger for Unity" nothing changed, could you guys help me ?
@wispy delta But I thought you wanted to create a texture. This is totally different
@dense cobalt Your file is not part of the project.
Delete your .sln/.csproj
Position has been corrected ( - (size/2)) but the texture is still not in the right place
Where can i find this file ? @onyx harness
@onyx harness I am creating a texture, this is just how i'm changing the import settings
You are writting a texture
then importing it
while you can use AssetDatabase.CreateAsset
@dense cobalt at the root of your project
Got it, working now, thx
if i use CreateAsset it has to be a .asset which doesn't have as many import options and I don't think generates mip maps
Hum... I don't think this is true
If I create a Material, it's gonna be .mat
but it needs to be confirmed
"You must ensure that the path uses a supported extension ('.mat' for materials, '.cubemap' for cubemaps, '.GUISkin' for skins, '.anim' for animations and '.asset' for arbitrary other assets.)"
Ok so another question if I can't find any answer... How would you draw a texture in the editor scene if it wasn't using Gizmos.DrawGUITexture ?
GUI.DrawTexture perhaps
Like drawing any GUI in the scene
It works
I'm looking into your code right now
But perhaps you are not using the right position
I debugged it and it's ok 😦
I mean, try this:
EditorGUIUtility.ScreenToGUIPoint
If it was just not well positioned I still wouldn't understand why the distance between the transform and the texture keeps changing
Or something similar to correctly convert a position from the 2 perspectives
You don't see it because you are around 0,0
Try around 500,500, you will clearly see the problem I think
you might even zoom in/out
neither ScreenToGUIPoint nor GUIToScreenPoint
Already triend with World To Screen and Screen To World
It's not a ratio problem :
Hum... strange
Just checked my rect are ok :
Gizmos.DrawWireCube(rect.center, rect.size);
Gizmos.DrawGUITexture(rect, op.texture);