From 7055891a84585af2ed37e1619f495ed2950b9b4c Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sat, 2 Sep 2017 12:55:43 +0200 Subject: [PATCH] delayed instance creation --- src/game-lib-d3-raycast-vehicle.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/game-lib-d3-raycast-vehicle.js b/src/game-lib-d3-raycast-vehicle.js index 7dde3f2..0564167 100644 --- a/src/game-lib-d3-raycast-vehicle.js +++ b/src/game-lib-d3-raycast-vehicle.js @@ -66,16 +66,19 @@ GameLib.D3.RaycastVehicle.prototype.constructor = GameLib.D3.RaycastVehicle; */ GameLib.D3.RaycastVehicle.prototype.createInstance = function() { - var instance = new CANNON.RaycastVehicle({ - chassisBody: this.chassis.instance - }); + /** + * At this point - even though this component exists - the chassis could maybe not been have assigned, failed to + * register as a dependency, and therefore is not present at the time of createInstance() - we will need to call + * delayedInstance somehow... + * @type {GameLib.D3.RaycastVehicle|GameLib.D3.API.RaycastVehicle|*} + */ + var instance = false; - //TODO: maybe move this into linking system - ALSO - store a reference to the wheel somehow to update the wheel instance? - this.wheels.map( - function(wheel){ - instance.addWheel(wheel.instance); - } - ); + if (this.chassis && this.chassis.instance) { + var instance = new CANNON.RaycastVehicle({ + chassisBody: this.chassis.instance + }); + } return instance; };