aframevr / aframe

:a: Web framework for building virtual reality experiences.
https://aframe.io/
MIT License
16.65k stars 3.96k forks source link

Nested entities initialize out of order in scene without a-assets #2802

Closed wmurphyrd closed 7 years ago

wmurphyrd commented 7 years ago

Description:

I believe components can assume during their initialization that components on child nodes have already been initialized due to the inside-out initialization order. This assumption does not hold up in a scene with no <a-assets> declared.

This scene errors when a component on <a-locomotor> expects an object to be returned from getAttribute on a child node component but gets a string instead:

<head>
  <title>Most Basic Super-Hands Example</title>
  <script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
  <script src="//cdn.rawgit.com/donmccurdy/aframe-extras/v3.3.0/dist/aframe-extras.min.js"></script>
  <script src="https://rawgit.com/wmurphyrd/aframe-super-hands-component/master/dist/super-hands.js"></script>
</head>

<body>
  <a-scene>
    <a-locomotor>
      <!-- Make sure your super-hands entities also have controller and collider components -->
      <a-entity hand-controls="left" super-hands sphere-collider="objects: a-box"></a-entity>
      <a-entity hand-controls="right" super-hands sphere-collider="objects: a-box"></a-entity>
    </a-locomotor>
    <!-- hover & drag-drop won't have any obvious effect without some additional event handlers or components. See the examples page for more -->
    <a-box hoverable grabbable stretchable drag-droppable
    color="blue" position="0 0 -1"></a-box>
  </a-scene>
</body>

This scene, identical except for the addition of an empty <a-assets> loads successfully:

<head>
  <title>Most Basic Super-Hands Example</title>
  <script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
  <script src="//cdn.rawgit.com/donmccurdy/aframe-extras/v3.3.0/dist/aframe-extras.min.js"></script>
  <script src="https://rawgit.com/wmurphyrd/aframe-super-hands-component/master/dist/super-hands.js"></script>
</head>

<body>
  <a-scene>
    <a-assets></a-assets>
    <a-locomotor>
      <!-- Make sure your super-hands entities also have controller and collider components -->
      <a-entity hand-controls="left" super-hands sphere-collider="objects: a-box"></a-entity>
      <a-entity hand-controls="right" super-hands sphere-collider="objects: a-box"></a-entity>
    </a-locomotor>
    <!-- hover & drag-drop won't have any obvious effect without some additional event handlers or components. See the examples page for more -->
    <a-box hoverable grabbable stretchable drag-droppable
    color="blue" position="0 0 -1"></a-box>
  </a-scene>
</body>

This can definitely be solved in the component by not making the assumption, but I thought it was worth documenting for you.

ngokevin commented 7 years ago

I'm curious what would happen if you decomposed the primitive to entity + components.

ngokevin commented 7 years ago

A-Frame has a fairly strict child-to-parent/inside-out load order. All children have to be loaded (meaning node is attached, components are initialized), then the entity initializes all components, then emits that it is loaded. So it's hard to think that it'd be due to the A-Frame core, maybe it's because of primitives, or maybe another issue, but I'd love to know more.

wmurphyrd commented 7 years ago

Here it is with decomposed primitive:

https://glitch.com/edit/#!/denim-straw

The issue is still the same

dmarcos commented 7 years ago

Where is locomotor-auto-config defined?

wmurphyrd commented 7 years ago

https://github.com/wmurphyrd/aframe-super-hands-component/blob/master/reaction_components/locomotor-auto-config.js