this means it is currently being created and the name not confirmed yet if this asset dos still not exist do nothing this means it is currently being created an the name has not been confirmed yet otherwise attach a callback to the editor update to re-check repeatedly until it exists If this asset already exists initialize immediately If child is already set -> nothing to do => If this is meant to be used for runtime applications outside of the Unity Editor itself, make sure to wrap anything related to UnityEditor in pre-processor tags #if UNITY_EDITORĪny code related to UnityEditor namespace In that case I would simply check if a child already exists within this asset in order to not recreate it.Īlso note: UnityEditor is completely stripped of in a build! Note though: I would suggest to not only rely on Reset but additionally use OnValidate and Awake in order to also force the child to be set when someone changes it via the Inspector. In order to check this you can use AssetDatabase.Contains What you can do is delay the child creation until the asset was actually created. If you hit Escape then it is never created ) The issue is that until you entered the name the new created scriptableObject is not persistent yet. ![]() Public class Container : ScriptableObjectĬhild = ScriptableObject.CreateInstance() ĪssetDatabase.AddObjectToAsset(child, this) // This line throws exception!Ĭhild class public class Child : ScriptableObject I think this might be the reason I don't understand this problem.įollowing is the code of a simplified version of what I am trying to implement. I do not know what persistent means in this context. The inspector shows a child reference as soon as the asset is created, but says Type mismatch when the name of the container is entered. Observations: The container is created successfully. AddAssetToSameFile failed because the other asset is not persistent.UnityException: Adding asset to object failed.I use the AssetDatabase.AddObjectToAsset but gives me the following error messages: The container should also keep a reference of the child.Īctual: When I try to attach the child to the container asset, it fails. asset file in the correct folder with the correct name (name of variable + change event) at runtime, but can't find a way make a reference in the script to the newly created ScriptableObject (since you can't use the usual method when you use Instantiate for gameObjects).Goal: Create nested scriptable objects from the project view.Įxpected: When an instance of the container scriptable object is created from the project view, an instance of the child scriptable object is created and attached to the container asset. So my question is now how could I generate something IN THE EDITOR, and then autoassign it to the variable's ChangeEvent field? Is that easy to do (in which case it's worth implementing) or is it really complex (in which case I'll live with manually creating the event!). ![]() It's not super-important, but would be nice and I feel this should be solvable.ĮDIT: Upon thinking about this a bit more, it's not much use at runtime because I'd need to assign the event to a listener in the editor anyway. It's just to cut out one stage of implementation. It seems to be a better way of doing things (even if it's more difficult to plan out).Īs part of this, I thought that instead of the workflow being "create variable, create event to listen to this, then assign to a listener", it would be good if the 'VariableChangeEvent' was autogenerated with a useful name if there isn't one already ~at runtime~ in the editor and assign itself to an event field that fires when the variable is changed. I'm hoping this would avoid the need for constant checking in update to watch a variable. I want to have an event system where whenever this is changed, other components can listen to see when it's changed and then check within themselves if they need to act. I have a type FloatVariable, which is a ScriptableObject. I'm trying to build a ScriptableObject system (based off of Hipple's talk etc.) of variables and events.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |