arcadia-unity / Arcadia

Clojure in Unity
http://arcadia-unity.github.io/
Apache License 2.0
1.68k stars 108 forks source link

Removing a component is not finished after a call to cmpt- #381

Open kamisori opened 4 years ago

kamisori commented 4 years ago

Windows 10, Unity 2019.3.5f1, Arcadia 268bed0fc9dc5143870259d88a142d60ae8b7f9d

Given the following code:

(ns user
  (:use arcadia.core)
  (:import [UnityEngine BoxCollider2D
                        Debug
                        GameObject
                        MeshCollider
                        Rigidbody2D
                        RigidbodyType2D]))

(defn init-player []
  (destroy (object-named "Player"))
  (cmpt- (create-primitive :quad "Player") MeshCollider)
  (let [player (object-named "Player")]
    (log (cmpt player MeshCollider))
    (cmpt+ player BoxCollider2D)
    (sets! (cmpt+ player Rigidbody2D)
            gravityScale (float 0.0)
            bodyType RigidbodyType2D/Dynamic)))

When calling init-player in the REPL, it responds with:

System.NullReferenceException: Object reference not set to an instance of an object
  clojure.lang.Reflector.SetInstanceFieldOrProperty (object, System.String, object)
* user/init-player
* user/eval
  clojure.lang.Compiler.eval (object)
* clojure/core/eval
* clojure.lang.Var
* Arcadia.NRepl+EvalFn coop/Assets/Arcadia/Editor/NRepl.cs (203:6)

The Unity Editor Console logs the still available MeshCollider:

Player (UnityEngine.MeshCollider)
UnityEngine.Debug:Log(Object)
arcadia$core$log__31902:invokeStatic(ISeq)
arcadia$core$log__31902:doInvoke(Object)
clojure.lang.RestFn:invoke(Object)
user$init_player__33499:invokeStatic()
user$init_player__33499:invoke()
user$eval__33508__33513:invokeStatic()
user$eval__33508__33513:invoke()
clojure.lang.Compiler:eval(Object)
clojure$core$eval__3112:invokeStatic(Object)
clojure$core$eval__3112:invoke(Object)
clojure.lang.Var:invoke(Object)
Arcadia.EvalFn:invoke() (at Assets/Arcadia/Editor/NRepl.cs:203)
arcadia$internal$callbacks$run_callbacks__28824:invokeStatic(Object, Object)
arcadia$internal$callbacks$run_callbacks__28824:invoke(Object, Object)
arcadia$internal$editor_callbacks$run_callbacks__28918:invokeStatic()
arcadia$internal$editor_callbacks$run_callbacks__28918:invoke()
clojure.lang.Var:invoke()
Arcadia.EditorCallbacks:RunCallbacks() (at Assets/Arcadia/Editor/EditorCallbacks.cs:24)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

then complains about me adding a BoxCollider2D to a GO with a MeshCollider:

Can't add component 'BoxCollider2D' to Player because it conflicts with the existing 'MeshCollider' derived component!
UnityEngine.GameObject:AddComponent(Type)
arcadia$core$cmpt_PLUS___32127:invokeStatic(Object, Object)
arcadia$core$cmpt_PLUS___32127:invoke(Object, Object)
user$init_player__33499:invokeStatic()
user$init_player__33499:invoke()
user$eval__33508__33513:invokeStatic()
user$eval__33508__33513:invoke()
clojure.lang.Compiler:eval(Object)
clojure$core$eval__3112:invokeStatic(Object)
clojure$core$eval__3112:invoke(Object)
clojure.lang.Var:invoke(Object)
Arcadia.EvalFn:invoke() (at Assets/Arcadia/Editor/NRepl.cs:203)
arcadia$internal$callbacks$run_callbacks__28824:invokeStatic(Object, Object)
arcadia$internal$callbacks$run_callbacks__28824:invoke(Object, Object)
arcadia$internal$editor_callbacks$run_callbacks__28918:invokeStatic()
arcadia$internal$editor_callbacks$run_callbacks__28918:invoke()
clojure.lang.Var:invoke()
Arcadia.EditorCallbacks:RunCallbacks() (at Assets/Arcadia/Editor/EditorCallbacks.cs:24)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

same with the RigidBody2D:

Can't add component 'Rigidbody2D' to Player because it conflicts with the existing 'MeshCollider' derived component!
UnityEngine.GameObject:AddComponent(Type)
arcadia$core$cmpt_PLUS___32127:invokeStatic(Object, Object)
arcadia$core$cmpt_PLUS___32127:invoke(Object, Object)
user$init_player__33499:invokeStatic()
user$init_player__33499:invoke()
user$eval__33508__33513:invokeStatic()
user$eval__33508__33513:invoke()
clojure.lang.Compiler:eval(Object)
clojure$core$eval__3112:invokeStatic(Object)
clojure$core$eval__3112:invoke(Object)
clojure.lang.Var:invoke(Object)
Arcadia.EvalFn:invoke() (at Assets/Arcadia/Editor/NRepl.cs:203)
arcadia$internal$callbacks$run_callbacks__28824:invokeStatic(Object, Object)
arcadia$internal$callbacks$run_callbacks__28824:invoke(Object, Object)
arcadia$internal$editor_callbacks$run_callbacks__28918:invokeStatic()
arcadia$internal$editor_callbacks$run_callbacks__28918:invoke()
clojure.lang.Var:invoke()
Arcadia.EditorCallbacks:RunCallbacks() (at Assets/Arcadia/Editor/EditorCallbacks.cs:24)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

and finally: because the RigidBody2D couldn't be added I'm trying to sets! a nil:

NullReferenceException: Object reference not set to an instance of an object
clojure.lang.Reflector.SetInstanceFieldOrProperty (System.Object target, System.String fieldName, System.Object val) (at <fb1204dbf0b848beaab1559f81f1b22c>:0)
user$init_player__33499.invokeStatic () (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
user$init_player__33499.invoke () (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
user$eval__33508__33513.invokeStatic () (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
user$eval__33508__33513.invoke () (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
clojure.lang.Compiler.eval (System.Object form) (at <fb1204dbf0b848beaab1559f81f1b22c>:0)
clojure$core$eval__3112.invokeStatic (System.Object ) (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
clojure$core$eval__3112.invoke (System.Object ) (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
clojure.lang.Var.invoke (System.Object arg1) (at <fb1204dbf0b848beaab1559f81f1b22c>:0)
Arcadia.NRepl+EvalFn.invoke () (at Assets/Arcadia/Editor/NRepl.cs:256)
arcadia$internal$callbacks$run_callbacks__28824.invokeStatic (System.Object , System.Object ) (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
arcadia$internal$callbacks$run_callbacks__28824.invoke (System.Object , System.Object ) (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
arcadia$internal$editor_callbacks$run_callbacks__28918.invokeStatic () (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
arcadia$internal$editor_callbacks$run_callbacks__28918.invoke () (at <8bf3ff39d57c4f4382aba633b972f7c0>:0)
clojure.lang.Var.invoke () (at <fb1204dbf0b848beaab1559f81f1b22c>:0)
Arcadia.EditorCallbacks.RunCallbacks () (at Assets/Arcadia/Editor/EditorCallbacks.cs:24)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Delegate.DynamicInvokeImpl (System.Object[] args) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Delegate.DynamicInvoke (System.Object[] args) (at <437ba245d8404784b9fbab9b439ac908>:0)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <887a438259064e89922419bc7b8810ab>:0)
timsgardner commented 4 years ago

Weird, I'll take a look