From 3a6ad8554e62fcccde9a3d1ed58b315980207a30 Mon Sep 17 00:00:00 2001
From: netpro2k <netpro2k@gmail.com>
Date: Wed, 18 Jul 2018 16:15:33 -0700
Subject: [PATCH] Fix for sticky object error on network instantiation

---
 src/components/sticky-object.js | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/components/sticky-object.js b/src/components/sticky-object.js
index 5f8106681..0cf3e3c53 100644
--- a/src/components/sticky-object.js
+++ b/src/components/sticky-object.js
@@ -12,20 +12,28 @@ AFRAME.registerComponent("sticky-object", {
     this._onGrab = this._onGrab.bind(this);
     this._onRelease = this._onRelease.bind(this);
     this._onBodyLoaded = this._onBodyLoaded.bind(this);
-    if (this.el.body) {
-      this._onBodyLoaded();
-    }
   },
 
   play() {
     this.el.addEventListener("grab-start", this._onGrab);
     this.el.addEventListener("grab-end", this._onRelease);
-    this.el.addEventListener("body-loaded", this._onBodyLoaded);
+
+    if (this.hasSetupBodyLoaded) return;
+    this.hasSetupBodyLoaded = true;
+
+    if (this.el.body) {
+      this._onBodyLoaded();
+    } else {
+      this.el.addEventListener("body-loaded", this._onBodyLoaded, { once: true });
+    }
   },
 
   pause() {
     this.el.removeEventListener("grab-start", this._onGrab);
     this.el.removeEventListener("grab-end", this._onRelease);
+  },
+
+  remove() {
     this.el.removeEventListener("body-loaded", this._onBodyLoaded);
   },
 
-- 
GitLab