Two instances of an object Network room

I am spawning the same object multiple time in a network room. I see multiple instances of that object but other client just see one.

Hi Saad Baig,

To effectively manage multiple instances of an object in a networked environment, it’s crucial to ensure that all clients have the same view of the state and instances of the objects. Here are some steps you might consider:

  1. Instantiate Objects on All Clients:
    Ensure that when you instantiate an object on one client, the same instantiation occurs on all clients. This is typically handled by sending a message or event to all clients to create an instance of the object.

  2. Synchronization Logic:
    Use your networking framework’s synchronization features. If you are using Needle Engine, consider leveraging the NetworkManager to handle spawning and synchronizing objects across clients. You might need to implement a method like SpawnObject() that handles both local and remote creation of the objects.

  3. Correct Identification:
    Make sure each instance of the object has a unique identifier so that all clients can manage each object’s state individually.

Here’s a mock-up of how you might go about this in code:

import { NetworkManager } from "@needle-tools/engine";

// Pseudocode for spawning objects
function spawnNetworkObject(objectData) {
    const newObject = NetworkManager.spawn(objectData); // Spawns the object
    NetworkManager.syncObject(newObject); // Synchronize it across clients
}

// Call this on object creation
if (isServer) {
    // Server spawns the object and informs clients
    spawnNetworkObject(objectData);
}

Make sure you have your server configuration handling the object counts correctly, informing all clients when an object is spawned.

If you’re facing technical issues with specific methods or events, please provide more details on your setup, such as your current code structure for spawning or the networking framework being utilized.

For more info, consider checking the Needle Engine documentation.

Feel free to ask if you need additional assistance!

3 replies left
thread_Y8lXVdOlpJLRzLvIlmbo5Ea1
Reply to this message to continue the conversation

I tried with different guid but the problem is the same. It only occurs when I spawn the same object with same url .

Hi Saad Baig,

If you are experiencing issues with multiple instances of the same object being visible to one client but not others, and especially when they have the same URL or resource identifier, this commonly relates to how the network framework handles state synchronization or object pooling.

Here are some steps to troubleshoot and potentially resolve the issue:

  1. Unique Identifiers:
    Ensure each object instance has a unique identifier (GUID). When spawning objects from the same URL, creating a new instance with a unique identifier is critical for distinguishing between them.

  2. Networking Code Verification:
    Verify your networking code for instantiation. Ensure that every time you spawn an object, you are sending a network message to all clients to notify them of the new instance.

  3. Handling URLs:
    If utilizing URLs for resources, you might want to consider implementing a method that generates variations of the object (e.g., different scales or colors) if using the same URL causes conflicts. This might help differentiate the instances.

  4. Synchronization Events:
    Make sure your synchronization events are correctly set up. When one client spawns an object, it should broadcast this event or message to all other clients immediately.

  5. Network Room Configuration:
    Check your network room settings. Sometimes room configurations can limit instances depending on how they are set. You might need to adjust these settings to ensure multiple instances are allowed.

Example pseudocode for broadcasting the spawn event:

import { NetworkManager } from "@needle-tools/engine";

function spawnObjectWithUniqueData(url) {
    const objectData = { url, guid: generateUniqueGuid() };
    NetworkManager.send("spawnObject", objectData); // Notify all clients
}

NetworkManager.on("spawnObject", (objectData) => {
    // Logic to create the object based on received data
    createObjectFromData(objectData);
});

If the issue persists, please share any relevant code snippets or specific configurations for further troubleshooting.

You can also refer to the Needle Engine API for more in-depth information on the methods involved.

Let me know if you need further assistance!

3 replies left
thread_Y8lXVdOlpJLRzLvIlmbo5Ea1
Reply to this message to continue the conversation

@marcel Sorry but AI answer isn’t sufficient.

Hi Saad Baig,

If the previous answers did not fully address the issue you’re facing with networked object spawning, I’d be happy to help further. Please provide more details about your setup:

  1. Current Code Snippet: Share the relevant parts of your code where you handle the spawning of the objects.
  2. Network Room Configuration: Details about how your network room is set up, particularly regarding synchronization settings.
  3. Specific Object Properties: Information about the objects you’re trying to spawn, particularly their URLs or any special properties that might affect their handling.

With this information, I can provide more targeted advice or code snippets to help resolve your issue.

Looking forward to your response!

3 replies left
thread_Y8lXVdOlpJLRzLvIlmbo5Ea1
Reply to this message to continue the conversation

Hi, can you add a bit more context on how you spawn your objects?

I’ve pictures of objects that are stored at my firebase cloud. On clicking the picture, it fetches corresponding downloadable link. Which I then store it in a synced variable and use it to spawn the object.

I have two ways do to this. One is to add from your PC which doesn’t create any issue even if I add the same object twice (using the same method above).
But the issue only arises when I use prestored object’s downloadable link.

Technically there’s no difference whether your URL is from an external storage provider or your own server (as long as your server configuration allows downloading the files but then the model wouldn’t show up for anyone and you would see e.g. CORS errors in the browser console)

  • Do you see any error in the browser console for you or the connected client?
  • Do you have a link that you can share with me (e.g. via PM)

There’s no CORS error or any other error in the console. I tried to print the Guid to see if it’s different but even with this logic it’s setting it the same.
I’ll share a link with you.

did you get chance to see the example?

For completeness:
This has been debugged with two possible solutions via PM - it is a project specific problem where networking state is unintentionally overriden