Visitar URL original
allow using exist entitys for networked by arpu · Pull Request #509 · networked-aframe/networked-aframe · GitHub
Skip to content

allow using exist entitys for networked - #509

Draft
arpu wants to merge 4 commits into
masterfrom
updateExist
Draft

arpu wants to merge 4 commits into
masterfrom
updateExist

Conversation

@arpu

@arpu arpu commented Dec 6, 2025

Copy link
Copy Markdown
Member

No description provided.

@vincentfretin vincentfretin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a change we talked in January right?
Can you please give me again the scenario you have that is not covered by the persistent system? If it's possible to add an example with your case that will help, and probably additional unit test cases to cover the changes.

Comment thread src/NetworkEntities.js
var networkId = entityData.networkId;
var el = NAF.schemas.getCachedTemplate(entityData.template);
try {
const exists = document.getElementById(networkId);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me the name exists means it's a boolean, I'd prefer existingEl.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the log NAF.log.write('Creating remote entity', entityData); we already have abvove only if existingEl is null, and add another log if it already exists.

Comment thread src/NetworkEntities.js

if (!el) {
throw new Error(`Failed to create element for template: ${template}`);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAF.schemas.getCachedTemplate(template) already log an error if there is no template, so just return here maybe?

Comment thread src/NetworkEntities.js
if (entityData.isFirstSync) {
this.initPosition(el, components);
this.initRotation(el, components);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you check isFirstSync here? If the entity moved, you still want to sync it right?

Comment thread src/NetworkEntities.js
} catch (error) {
console.error('Error creating remote entity:', error);
return null;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try catch is not needed if you don't throw your own error.

Comment thread src/NetworkEntities.js
}

initPosition(entity, componentData) {
if (!entity) return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added check shouldn't be needed if you return before calling initPosition.

Comment thread src/NetworkEntities.js
}

initRotation(entity, componentData) {
if (!entity) return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added check shouldn't be needed if you return before calling initRotation.

this.el.emit(this.OWNERSHIP_GAINED, this.onOwnershipGainedEvent);
} else if (!isMine && wasMine) { // Lost ownership
this.onOwnershipLostEvent.newOwner = data.owner;
this.el.emit(this.OWNERSHIP_LOST, this.onOwnershipLostEvent);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about all the changes here. We already have the some OWNERSHIP_LOST event emitted in networkUpdate. Is is emitted twice now?


if (isMine && !wasMine) { // Gained ownership
this.removeLerp();
this.syncAll(undefined, true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you always full sync now with the second param isFirstSync to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants