OnDelete method for Task / Conditions / Actions

NodeCanvas Forums General Discussion OnDelete method for Task / Conditions / Actions

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #9123

    Hi, I have a feature suggestion 🙂
    It would be very useful if you could add an “virtual OnDelete()” method to Actions and Conditions.
    So that its possible to delete custom added copmponents (from nodes or connections) before DestroyImmediate() – please see attached image. It would be nice if you could add this in the next update, so that we know when a condition or an action gets deleted from a list.

    (BTW: I already tried to use OnDestroy() on a script that derives from ConditionTask to delete my custom added components. Unfortunately other problems arise with [ExecuteInEditMode] and twice executed DestroyImmediate() calls etc.)

    Thanks! 😉

    #9132
    Gavalakis
    Keymaster

    Hello 🙂

    I don’t really know why would you want to add custom components on those gameobjects in the first place, but it’s a very easy request to add and indeed, I know of the errors that come up with destroying “linked” components in OnDestroy and using [ExecuteInEditMode]. There are workarounds for it, but sure, I will add an OnEditorDestroy method (keeping the naming convention I have for other editor callbacks).
    It will be in the next version 🙂

    Cheers!

    Join us on Discord: https://discord.gg/97q2Rjh

    #9131

    Thank you for the quick reply and Update!
    The reason is simple: We have our own 50 (in-House) action scripts. So I wrote just one ActionTask that can attach the other 50 actions to the node. So if I delete this ActionTask I have to delete the other components as well.

    Important Notice:
    I just realized that your “Execute Function” Action is using some code that does not run on mobile devices.

    The internal function..
    public static T BuildDelegate<T>(MethodInfo method, params object[] missingParamValues) is using a “.Compile()” method, that crashes on mobile devices.

    If there is no other solution for the Execute Function Action than please, mention it somewhere in the docs that it is not suitable for mobile devices. I just spent some hours and replaced all the actions with UnitySendMessage.

    Thank you very much for your great work!! 😉

    #9130
    Gavalakis
    Keymaster

    Hello,

    Until the last version ExecuteFunction was called with MethodInfo.Invoke which is much slower than calling a delegate directly. The BuildDelegate was added in the last version. Sorry for spending that time. I will make sure that it works with mobile in the next version.
    Was that issue on WP8? Can you please let me know what error you got?

    Thanks! 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

    #9129

    Hi 🙂

    The issue was on iPhone5S with iOS 8.02

    error:

    Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method ‘(wrapper dynamic-method) System.Runtime.CompilerServices.ExecutionScope:lambda_method (System.Runtime.CompilerServices.ExecutionScope,object,object,object,object)’ while running with –aot-only.

    at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0
    at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0
    at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType, System.Object target) [0x00000] in <filename unknown>:0
    at System.Linq.Expressions.EmitContext.CreateDelegate (System.Runtime.CompilerServices.ExecutionScope scope) [0x00000] in <filename unknown>:0
    at System.Linq.Expressions.CompilationContext.CreateDelegate (Int32 unit, System.Runtime.CompilerServices.ExecutionScope scope) [0x00000] in <filename unknown>:0
    at System.Linq.Expressions.CompilationContext.CreateDelegate () [0x00000] in <filename unknown>:0
    at System.Linq.Expressions.LambdaExpression.Compile () [0x00000] in <filename unknown>:0
    at System.Linq.Expressions.Expression1[System.Action4[System.Object,System.Object,System.Object,System.Object]].Compile () [0x00000] in <filename unknown>:0
    at NodeCanvas.NCReflection.BuildDelegate[Action

    4] (System.Reflection.MethodInfo method, System.Object[] missingParamValues) [0x00000] in <filename unknown>:0
    at NodeCanvas.Actions.ExecuteFunction.OnInit () [0x00000] in <filename unknown>:0
    at NodeCanvas.Task.Initialize (UnityEngine.Component newAgent) [0x00000] in <filename unknown>:0
    at NodeCanvas.Task.Set (UnityEngine.Component newAgent, NodeCanvas.Blackboard newBB) [0x00000] in <filename unknown>:0
    at NodeCanvas.ActionTask.ExecuteAction (UnityEngine.Component agent, NodeCanvas.Blackboard blackboard, System.Action
    1 callback) [0x00000] in <filename unknown>:0

    (Filename: /Applications/buildAgent/work/d63dfc6385190b60/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp Line: 49)

    (lldb)

    As far as I know the “System.Reflection.Emit” api is available in mono but does not work on iOS.
    You can use reflection on iOS but there is no way to compile code at runtime. And I think that “System.Reflection.Emit.DynamicMethod.CreateDelegate” does this. But I am not a .net Reflection Pro!

    Cheers! 🙂

    #9128
    Gavalakis
    Keymaster

    Hello,

    Thanks for the information, very usefull.
    I will probably have to revert the last changes made to reflection in NC to still use MethodInfo.Invoke instead of delegates. That’s a pety really, since delegates are much faster performance wise.

    Thanks.

    Join us on Discord: https://discord.gg/97q2Rjh

    #9127

    Hi 🙂

    Regarding OnDelete method for Actions and Conditions:

    You have added the methods for the Action- and Condition-Task Scripts but forgot to add it to the ActionList and ConditionList in the ListEditor method. Please see attached image! It would be nice if you could invoke the method from there as well.

    Thank you in advance! 🙂

    #9126
    Gavalakis
    Keymaster

    Hello again,

    Things are getting less generic than I original though with that OnDestroy would be, since I will have to check if type is Task since that ListEditor is for all element types. Now that’s something I wouldn’t really like to do :), but I will check to find an alternative for that.

    Cheers!

    Join us on Discord: https://discord.gg/97q2Rjh

    #9125
    Gavalakis
    Keymaster

    Hello,

    OnEditorDestroy is now called for lists on the newly submited version.
    Cheers!

    Join us on Discord: https://discord.gg/97q2Rjh

    #9124

    Thanks! 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.