(log & args)Log message to the [Unity console](https://docs.unity3d.com/Manual/Console.html). Arguments are combined into a string.
args;; strings work
(log "Hello, Arcadia!");; strings work
(log "Hello, Arcadia!");; arguments are combined as in str
(let [n (rand)]
(log "Want a number? " n ". Done!"));; arguments are combined as in str
(let [n (rand)]
(log "Want a number? " n ". Done!"));; log can also be used as quick debug hook
(hook+ (object-named "Main Camera") :update log)(null-obj? x)Is `x` nil? This test is complicated by the fact that Unity uses a custom null object that evaluates to `true` in normal circumstances. `null-obj?` will return `true` if `x` is nil *or* Unity's null object.
;; Unity interop calls will return Unity's null object
;; The Main Camera has no Rigidbody by default
(let [rb (.GetComponent
(object-named "Main Camera")
UnityEngine.Rigidbody)]
rb ;; => #unity/Object 0
(boolean rb) ;; => true
(null-obj? rb)) ;; => true
;; arcadia functions use null-obj? internally to present
;; a more consistent view of the Unity scene graph
(cmpt (object-named "Main Camera") UnityEngine.Rigidbody) ;; => nil
(obj-nil x)Inlined version of null-obj? Could be merged in the future.
x(instantiate original)(instantiate original position)(instantiate original position rotation)Clones the original object and returns the clone. The clone can optionally be given a new position or rotation as well. Wraps UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/Instantiate.
originalObjectpositionVector3rotationQuaternion;; create a new camera identical to the default camera
(let [new-camera (instantiate (object-named "Main Camera"))]
new-camera ;; => #unity/Object -6904
(.name new-camera)) ;; "Main Camera(Clone)"
;; create a new camera at a new position
(instantiate (object-named "Main Camera")
(v3 100 20 10));; create a new camera at a new position
;; looking at the origin
(instantiate (object-named "Main Camera")
(v3 100 20 10)
(qlookat (v3 100 20 10)
(v3 0)))(create-primitive prim)Creates a game object with a primitive mesh renderer and appropriate collider. `prim` can be a [PrimitiveType](http://docs.unity3d.com/ScriptReference/PrimitiveType.html "PrimitiveType") or one of :sphere :capsule :cylinder :cube :plane :quad. Wraps [GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject")/CreatePrimitive.
prim;; create the default Unity cube
(create-primitive :cube)(destroy obj)(destroy obj t)Removes a gameobject, component or asset. When called with `t`, the removal happens after `t` seconds. Wraps UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/Destroy. The difference between destroy and destroy-immediate is still being worked out.
objObjecttDouble;; remove the default camera
(destroy (object-named "Main Camera"));; remove every object with player in its name
(doseq [o (objects-named #".*player.*")]
(destroy o));; remember that map is lazy, so the following will
;; not work as expected
(map destroy (objects-named #".*player.*"))
;; instead, force evaluation with dorun or do all
(dorun (map destroy (objects-named #".*player.*")))
;; mapv returns a vector, and also forces evaluation
(mapv destroy (objects-named #".*player.*"))(destroy-immediate obj)Wraps UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/DestroyImmediate. The difference between destroy and destroy-immediate is still being worked out.
objObject(object-typed t)Returns one object of Type `type`. The object selected seems to be the first object in the array returned by objects-typed. Wraps UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/FindObjectOfType.
tType;; any type that can be in the Unity scene graph works
(object-typed UnityEngine.GameObject)(objects-typed t)Returns an array of all active loaded objects of Type `type`. The order is consistent but undefined. UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/FindObjectsOfType.
tType;; components are returned directly
(objects-typed UnityEngine.Camera);; superclasses work too
(count (objects-typed UnityEngine.Camera)) ;; => 1
(count (objects-typed UnityEngine.Component)) ;; => 8
(count (objects-typed UnityEngine.Object)) ;; => 20
(object-named name)Returns one [GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject") named `name`. Wraps UnityEngine.[GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject")/Find.
nameString;; get the default camera object
(object-named "Main Camera")(objects-named name)Returns a sequence of all GameObjects named `name`.
name;; cube primitives are named Cube by default
(dotimes [_ 20]
(create-primitive :cube))
(count (objects-named "Cube")) ;; # => 20
;; regular expressions work as well
(dotimes [_ 20]
(let [cube (create-primitive :cube)]
(set! (.name cube) (str (gensym "cube")))))
(count (objects-named #"cube.*")) ;; # => 20
(object-tagged t)Returns one active [GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject") tagged `tag`. Tags are managed from the [Unity Tag Manager](https://docs.unity3d.com/Manual/class-TagManager.html). Wraps UnityEngine.[GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject")/FindWithTag.
(objects-tagged t)Returns an array of active GameObjects tagged tag. Returns empty array if no [GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject") was found. Tags are managed from the [Unity Tag Manager](https://docs.unity3d.com/Manual/class-TagManager.html). Wraps UnityEngine.[GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject")/FindGameObjectsWithTag.
Common protocol for everything in Unity that supports attached components.
(cmpts this t)Returns a vector of all components typed `t` attached to the object
thist(cmpt+ this t)Adds a component of type `t` to the object and returns the new instance
thist(cmpt- this t)Removes all components of type `t` from the object and returns the object
thist(cmpt this t)Returns the first component typed `t` attached to the object
thist(ensure-cmpt obj t)If `obj` has a component of type `t`, returns is. Otherwise, adds a component of type `t` and returns the new instance.
objtTypeCommon protocol for everything in Unity that is part of the scene graph hierarchy.
(child- this child)Move `child` from under `this` object ti the top of the hierarchy
thischild(parent this)Returns the object that contains `this` object, or `nil` if it is at the top of the hierarchy.
this(child+ this child)(child+ this child transform-to)Moves `child` to under `this` object in the hierarchy, optionally recalculating its local transform.
thischildtransform-to(children this)Returns all objects under `this` object in the hierarchy.
this(with-gobj [gob-name x] & body)gob-namexbody(with-cmpt gob cmpt-name-types & body)gobcmpt-name-typesbody(if-cmpt gob [cmpt-name cmpt-type] then)(if-cmpt gob [cmpt-name cmpt-type] then else)Execute body of code if `gob` has a component of type `cmpt-type`
gobcmpt-namecmpt-typethenelse(gobj-seq x)xMap of keywords to hook component types
(hook+ obj hook f)(hook+ obj hook k f)Attach hook a Clojure function to a Unity message on `obj`. The funciton `f` will be invoked every time the message identified by `hook` is sent by Unity. `f` must have the same arity as the expected Unity message.
objhookfk(hook- obj hook k)Remove all `hook` components attached to `obj`
objhookk(hook obj hook)Return the `hook` component attached to `obj`. If there is more one component, then behavior is the same as `cmpt`.
objhook(hooks obj hook)objhook(hook? t)(hook? t hook)thook(state go)(state go kw)Returns the state of object `go`.
gokw(set-state! go kw v)Updates the state of object `go` with funciton `f`.
gokwv(remove-state! go kw)Updates the state of object `go` with funciton `f`.
gokw(update-state! go kw f & args)Updates the state of object `go` with funciton `f`.
gokwfargs