Comments (9)
I think it might be related to prefabs. I found that, if the game object is not from a prefab, this button method in editor works fine, the value is not lost after playing.
[ButtonMethod] void FindCollider() { m_Collider = GetComponent<Collider>(); }
However, if the gameobject is from a prefab. In editor, the change made by this method is not registered. It will be lost after playing.
I guess RecordPrefabInstancePropertyModifications()
or SetDirty()
would help. I will try it later when I have time.
from mybox.
It happened to me recently. In a button method I do something like list.Add()
and list.Clear()
, but the list is messed up:
- The list in the prefab is changed, even though I did not change the prefab.
- Non-null items ref in the list are cleared when clicking Play. Null items are still in the list.
Hope it can be fixed soon
from mybox.
[ButtonMethod] do works in an independent item, but it fail when come to the list item in a list/dictionary
Unfortunately, ButtonMethod is restricted to the root of MonoBehaviour or ScriptableObject. It wouldn't work with serialized custom type, but it will be shown through DisplayInspector Attribute. So, if you will use SO or MB in a list, you can do it like that (elements of the list are child MBs):
I know it's not a universal solution, but it is the only way, currently, to display buttons in a list.
Nowadays I'm using Odin inspector to do this kind of things, it works fine along with MyBox.
Extending this attribute to work with any serialized type is possible, but not in my priority. Would appreciate any contributions to the codebase 😅🙌🏻
I think it might be related to prefabs. I found that, if the game object is not from a prefab, this button method in editor works fine, the value is not lost after playing.
[ButtonMethod] void FindCollider() { m_Collider = GetComponent<Collider>(); }
However, if the gameobject is from a prefab. In editor, the change made by this method is not registered. It will be lost after playing.
Yep, you should definitely mark dirty any object, if you change its serialized data in the code during edit-time. Unity doesn't know that you changed the m_Collider field or resized the serialized list, so it won't save changes on the disc and they will be wiped out on domain reload.
The reason why changes weren't lost the first time is probably because you changed something else via inspector (this way the object was marked dirty internally) and all serialized data was successfully saved 🤔.
Something like this as a rule of thumb:
#if UNITY_EDITOR
[ButtonMethod] void FindCollider() {
m_Collider = GetComponent<Collider>();
UnityEditor.EditorUtility.SetDirty(gameObject);
}
#endif
from mybox.
Related Issues (20)
- Bug: Waiting for user code in MyBox.dll to finish executing HOT 3
- Crash in MySerializedProperty
- Constant errors with conditional field
- Enter Play mode being slower after install the package HOT 5
- Release with .unitypackage HOT 1
- Naming Conflit HOT 1
- Editor takes a long time in "MyEditorEvents.OnWillSaveAssets" HOT 4
- Passing a List or Array to DefinedValues HOT 3
- ConditionalField does not work when RegexString is used on the same fields HOT 1
- Missing def for Attributes/DefinedValuesAttribute.cs HOT 1
- ConditionalFieldAttribute is rather slow HOT 3
- Suggestion: Help boxes
- Using [ConditonalField] causes Editor Button to be drawn twice HOT 2
- ReadOnly HOT 1
- "No GUI Implemented" when using a UIElement Property Drawer with Default Inspector. HOT 5
- MyEditorAudio.cs not found. HOT 1
- DefinedValues w. method is null HOT 4
- [ConditionalField] doesn't work with lists or arrays HOT 1
- Foldout doesn't work properly in child classes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mybox.