arcadia-unity / Arcadia

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

lookup/state returning nil on new prefabs #355

Closed nasser closed 5 years ago

nasser commented 5 years ago
(defmutable TubePosition [^float x ^float y])

 (let [go (GameObject.)]
   (state+ go :test (->TubePosition 0 0)))
 ;; make resulting object a prefab called "testo"

 (lookup (Resources/Load "testo") :test) ;; <== nil
 (state (Resources/Load "testo")) ;; <== nil
nasser commented 5 years ago

but this works

 (lookup (instantiate (Resources/Load "testo")) :test) ;; <== not nil
 (state (instantiate (Resources/Load "testo"))) ;; <== not nil
timsgardner commented 5 years ago

with this setup:

(ns arcadia-issues.issue-355
  (:require [arcadia.core :as ac])
  (:import [UnityEngine GameObject Resources]))

(ac/defmutable TubePosition [^float x ^float y])

(comment
  (let [go (GameObject. "issue-355")]
    (ac/state+ go :test (->TubePosition 0 0))))

;; then you have to save it as a prefab called "issue-355". subsequently, from the repl:

(defn run-issue []
  {:test-lookup (ac/lookup (ac/instantiate (Resources/Load "issue-355")) :test)
   :test-state (ac/state (ac/instantiate (Resources/Load "issue-355")) :test)})

It works for me:

arcadia-issues.issue-355=> (run-issue)
nil
arcadia-issues.issue-355=> arcadia-issues.issue-355=> {:test-lookup #arcadia.data/data{:arcadia.data/type arcadia_issues.issue_355.TubePosition, :x 0.0, :y 0.0}, :test-state {:x 0.0, :y 0.0, :arcadia.core/mutable-type arcadia_issues.issue_355.TubePosition}}
timsgardner commented 5 years ago

nm, I'm an idiot, bad reproduction. Here's the corrected code, which does reproduce the issue:

(ns arcadia-issues.issue-355
  (:require [arcadia.core :as ac])
  (:import [UnityEngine GameObject Resources]))

(ac/defmutable-once TubePosition [^float x ^float y])

(comment
  (let [go (GameObject. "issue-355")]
    (ac/state+ go :test (->TubePosition 0 0))))

;; then you have to save it as a prefab called "issue-355". subsequently, from the repl:

(defn run-issue-without-instantiate []
  {:test-lookup (ac/lookup (Resources/Load "issue-355") :test)
   :test-state (ac/state (Resources/Load "issue-355") :test)})

(defn run-issue-with-instantiate []
  {:test-lookup (ac/lookup (ac/instantiate (Resources/Load "issue-355")) :test)
   :test-state (ac/state (ac/instantiate (Resources/Load "issue-355")) :test)})
nasser commented 5 years ago

Correct Unity usage is to instantiate prefabs before using them. Closing.