While developing a new site, I noticed my interface was mysteriously broken this morning (6/30/2017). I had not pushed any code changes, but it's pulling in aframe.io/aframe/dist/aframe-master.js which _did change_ last night.
The code that no longer worked is supposed to manage UI elements by automatically readjusting the position of buttons (simple plane geometries) whenever a button is added/removed. It does this by looping all elements (each button is control):
pos = control.getAttribute('position');
if (pos) {
pos.x = offset_left;
control.setAttribute('position', pos);
}
I checked control.getAttribute('position') and they were all correct, but none of the positions were actually changed in the scene. I tried manually performing control.setAttribute('position', pos) via the developer console and noticed something odd: it took two calls to setAttribute to actually get the element to move. So my updated UI loop (which works again, hooray!):
pos = control.getAttribute('position');
if (pos) {
pos.x = offset_left;
// For some reason, this now needs to be called twice.
control.setAttribute('position', pos);
control.setAttribute('position', pos);
}
var pos = document.querySelectorAll('a-box')[0].getAttribute('position');
pos.x -= 1;
document.querySelectorAll('a-box')[0].setAttribute('position', pos);
// The box does **not** update position, until you run the following line (uncomment before running):
// document.querySelectorAll('a-box')[0].setAttribute('position', pos); // Now it works!
Most likely because of the changes of skipping type check if reusing the same object, thanks will check it out.
A few objects in my experience moved when upgrading to 0.6.0
For me it was happening when I changed the 'position' 'x' attribute-- it reset y to 0 instead of holding onto its previous value.
In other words, I define an entity at position (0, -.24, 0) and throughout the experience I'm changing that x position, but every time the x position changed it was resetting y to 0. I surmised that I needed to keep redefining y, and that seemed to fix the problem.
`
//move from -.25 to 0 and scale from 0 to 3 over panotime
countTime -= 500;
var xLoadPos = -.25 + (0.25 * (1 - (countTime/panoTime)));
var xLoadScale = 3 * (1- (countTime/panoTime));
loadBar.setAttribute('position', 'x', xLoadPos);
loadBar.setAttribute('position', 'y', "-.24"); //ADDING THIS CODE FIXED IT
loadBar.setAttribute('scale', 'x', xLoadScale);
`
I have multiple things broken with this update. I have two components changing entity rotation in tick().
Firstly, I experience the same problem as @ibrews.
Secondly, I noticed that reversing the order of these components inside HTML tag restored the previous behavior. Is there a test that checks the execution order of tick() etc.? If not, we should write one.
@ip can you add a test case? thanks!
@ngokevin Probably later, I have no time at the moment, unfortunately, but wanted to let others know.
I found the problem. For single property components like position or scale. The component oldData is not a copy of data but a reference. When doing things like:
javascript
var position = el.getAtttribute('position');
position.y += 1;
el.setAttribute('position', position);
Both data and oldData are modified. the update method of the component is never called because no changes in the component are observed since oldData === data. PR coming
Ah, that makes sense! But quick question: why is that solved by calling el.setAttribute a second time? Wouldn't the same oldData === data check have the same result?
More than likely
Get Outlook for Androidhttps://aka.ms/ghei36
From: Jay Dansand notifications@github.com
Sent: Wednesday, July 5, 2017 2:29:11 PM
To: aframevr/aframe
Cc: Subscribed
Subject: Re: [aframevr/aframe] Entity.setAttribute('position') Not Always Effective (#2829)
Ah, that makes sense! But quick question: why is that solved by calling el.setAttribute a second time? Wouldn't the same oldData === data check have the same result?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com/aframevr/aframe/issues/2829#issuecomment-313232199, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AcUiPn1Filh-bXqGXcP4pUrJbXCcUO0jks5sLAAngaJpZM4OKyaE.
If you call setAttribute multiple times with the same object (as you do in your example), the object is considered trusted and we disable certain checks on it (type checking and comparison with oldData values). Your second call to setAttribute is going to through a different path that ends up triggering the change you were expecting on first call (because we don't compare against oldData)
We should probably restore the comparison with oldData regardless if the same object is passed multiple times to setAttribute (thinking about it)