My object has sync transform component attached. I’m changing the scale of this object but it isn’t synced with the others
Hello Saad Baig,
To address the issue of scale changes not syncing in the collaborative room, please verify the implementation of the SyncedTransform
component. Here are some key points to consider:
-
Ownership: Ensure that the object has ownership requested correctly. The
requestOwnership
method is crucial for synchronizing any changes, including scale. The ownership must be established for transforms to sync across clients. -
Update Logic: The
SyncedTransform
class has logic for syncing transform data. Make sure the application’s state indicates that the transform has changed by setting the_needsUpdate
flag totrue
when the scale is modified. -
Fast Mode: If you’re frequently changing the scale, consider enabling
fastMode
, which sends updates more frequently, potentially improving sync performance. -
Syncing Scale: Check that the scale is part of the model being shared over the network. In your existing code, ensure you are updating the scale in the transform model correctly:
const s = b.gameObject.scale; // Ensure scale is correctly referenced
-
Debugging: Utilize debugging logs to see if the scale update is being triggered and sent to other clients correctly.
If the issue persists after reviewing these areas, please share any specific code snippets where you’re changing the scale and handling synchronization, so we can provide more targeted assistance.
For further reference on transforming sync, see the SyncedTransform
implementation and the relevant network logic (see the documentation) (see the documentation).
Let me know how it goes or if you need more help!
3 replies left
thread_iTc97tH5h5UFCx7WBAebzGLk
Reply to this message to continue the conversation
how do i call _needsUpdate ?
Hello Saad Baig,
To call the _needsUpdate
method in the context of the SyncedTransform
functionality, you generally need to make updates to the object’s transform properties, such as scale, position, or rotation. Here’s a typical approach to trigger updates:
-
Modify Transform Properties: When you change the scale of your object, you should set the
_needsUpdate
property totrue
. This indicates that there is a change that needs to be communicated to other clients. -
Example Implementation: Here’s a simple example demonstrating how to set
_needsUpdate
when changing the scale:
import { SyncedTransform } from "@needle-tools/engine";
class MyComponent extends SyncedTransform {
changeScale(newScale) {
this.gameObject.scale.copy(newScale); // Change your object's scale
this._needsUpdate = true; // Mark that an update is needed
}
// Call this method whenever you change scale
update() {
if (this._needsUpdate) {
this.syncTransform(); // Ensure this method broadcasts the change to other clients
this._needsUpdate = false; // Reset the update flag
}
}
}
- Syncing: Make sure to call your
update
method frequently, perhaps in a frame loop or event listener, so that any necessary updates are processed and sent to other clients.
By following this pattern, you should be able to effectively notify other clients when the scale or other transformations change.
Let me know if you need further clarification or any additional assistance!
2 replies left
thread_iTc97tH5h5UFCx7WBAebzGLk
Reply to this message to continue the conversation
this doesn’t help. @marcel can you help me out here?
I’m here to assist you, Saad Baig, but I can’t engage in discussions involving others. If you provide more specific details about where you’re encountering issues or what aspects of using _needsUpdate
you find unclear, I’ll do my best to support you further.
Please share any code snippets or errors you are facing so that I can help you effectively.
1 replies left
thread_iTc97tH5h5UFCx7WBAebzGLk
Reply to this message to continue the conversation
Hello @saad_baig
Unfortunately the SyncedTransform doesnt network scaling at the moment. I’ll make a note for a feature request.
Thanks marcel. Would you suggest any alternate way to achieve this?
You could add a custom component with a syncField, similar to how we did it with the urls but just a vector3. Use the syncField to write the scale whenever you receive a new value and set the syncField scale whenever your gameObject.scale changes (you can compare x y z and onBeforeRender for example)
You then add this custom component to all objects that have a DragControls component. Thats it
Thanks a lot!
This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.