#Multiplayer Avatar Color
1 messages · Page 1 of 1 (latest)
Hello @pearl grove the PlayerColor script's purpose is to uniquely color each connected user with a stable color (based on their networking connection id).
I'm not how familiar you are with coding but you can network the selected color in a custom script if you need different behaviour:
https://engine.needle.tools/docs/networking.html#manual-networking
But maybe it would be good to add that feature to the PlayerColor component 🙂
let me know how it goes
Thanks for your help. I'm an experienced c# dev, but a total noob with TS and JS. I've implemented the IModel interface on my class and I'm trying to send the gameobject this way: this.context.connection.send(this.connId, this.gameObject as IModel, SendQueue.Immediate);
Unfortunately I'm receiving this error message:
uncaught range error: maximum call stack size exceeded
/node_modules/.vite/deps/chunk-BYWKJQSH.js?cf5a31f5:5110:14
at JSON.stringify (<anonymous>)
at Mesh.toJSON(https:192.168.3.8:3000/...
Ah ok so the IModel is your data model to send. It just forces you to implement a guid. But you would normally just add it to a new type like:
export class MyDataToSend implement IModel {
guid : string;
myColor:number;
}
the guid in your case would be the user's connection id most likely. this.context.connection.connectionId
Thanks for your response. I've created my AvatarColorUpdate type. Before sending the message, I'm converting my THREE.Color into a number with bit shifting. Now the error message is not being displayed anymore, but the color isn't being updated over the network
const packedColor = ((col.r * 255) << 16) | ((col.g * 255) << 8) | (col.b * 255);
let myData = new AvatarColorUpdate(this.connId, packedColor);
Do you alos subscribe to the event? Insteads of "this.connId" you need to define a event key (e.g "change-player-color") and then listen to the event to apply it (if(myData.guid === this.playerGuid) ...)
this.startCoroutine(this.waitForConnection());
this.context.connection.beginListen("avatarColorUpdate", (data) => {
let rdata = data as AvatarColorUpdate;
console.log("===1==="+rdata.connId+"_"+rdata.color);
console.log("===2==="+rdata.guid+"_"+rdata.myColor);
console.log('received: ${JSON.stringify(data)}');
});
I wrote the code above on the onEnable method, and I'm sending my information when a button is clicked: ```Typescript
let myData = new AvatarColorUpdate(this.connId, packedColor);
console.log("send: "+myData.connId+" and "+myData.color);
this.context.connection.send("avatarColorUpdate", myData, SendQueue.Immediate);
but not sure why I'm not receiving the data on the listener
Are you connected to a room? (using the SyncedRoom component)
I think I do
Ah you might need to open a second browser window to receive it in the same room
I'm running it on my desktop browser and sending the avatar data from a Quest browser
I'm running it locally
the color of the avatar is being set up on the Quest browser and works fine there, but is not being replicated to the desktop browser. I can see myself moving the avatar (using quest controllers) on the desktop browser, but the color remains the same
And it's not received?
Just tried this here real quick, sending /receiving works for this case. QuestBrowser is using the desktop localhost url i assume, right?
async onEnable(){
await delay(1000);
this.context.connection.beginListen("test", (data) => {
console.log(data);
});
const myData = {
time: Date.now(),
};
console.log("SEND");
this.context.connection.send("test", myData);
}
Yes, the quest browser is using the desktop localhost url. I'll give a try to your code to see how it works here, will keep you posted, thanks!
do you know what type should I import to avoid these issues?
delay is in engine:
import { delay } from "@needle-tools/engine";
inspired by Task.delay() 🙂
now the webxr displays black screen on both desktop and quest browser
Uncaught SyntaxError: ambiguous indirect export: delay
import { Behaviour, GameObject, serializable, delay } from "@needle-tools/engine";
the full path would be @needle-tools/engine/src/engine/engine_utils
which version are you using? does adding .ts fix it?
ah no not delay
import { delay } from @needle-tools/engine/src/engine/engine_utils
if I import this one, the webxr runs, but it displays an error message that says that delay is not a function
import { delay } from "@needle-tools/engine/node_modules/core-js/library/fn/delay.js";
That's definitely wrong. Which needle-engine version are you on? Can you try restarting vscode?
the paths above are definitely right. Depending on your version with or without /src/ but src would be right if you're not 10 versions or so behind
how can I tell what needle engine version I have installed?
fastest would be
sometimes worth checking
No version there 🙂 the screenshot i sent is from the ExportInfo component that you have in your scene
"version": "2.45.0-pre",
you can also check Unity's package manager
oh ok you're like 20 versions behind
We're currently on 2.67.4
interesting, I started this project two months ago
I'm updating the package to the latest available
I'd advice to commit before updating 20 versions 🙂
oh boy, too late
I've updated the needle engine package to the latest available. But now I'm facing some issues finding some types and I can't find them anywhere within the needle project. Could they possibly been deleted during the update?
No, they moved one directory in a few versions ago (in @needle-tools/engine/src/engine-component/WebXRAvatar for example)
You can run the updater if you want (Context menu on the ExportInfo component)
Oh, ok, thanks. I ran the Web Project Updater. Now I'm receiving an error from the browser then I try to run the app locally
Se bloqueó la carga de un módulo de “https://192.168.3.8:3000/node_modules/@needle-tools/engine/engine/engine_utils” debido a un tipo MIME no permitido (“”).
What does the error say? Have you restarted the server?
I've restarted my computer, how can I restart the server?
Open your project in Unity with the Needle Engine scene and click play
A module from “https://192.168.3.8:3000/node_modules/@needle-tools/engine/engine/engine_utils” was blocked from loading due to an illegal MIME type (“”).
this is the error displayed on the browser's console
Sounds like a cached file in the project. Can you try if it's fixed when you go to the ExportInfo component and hold ALT while clicking the Install button (It will perform a "Clean Install" of the web project, deleting the node_modules folder and local server caches)
I've performed the Clean Install. The new installation has finished, then I clicked the Play button but the same error message is being displayed
should I restart my computer again?
No that wont do anything here
You can check the chrome networking tab and try to figure out which script is possibly causing this (open with F12 in chrome, select the "Network" tab at the top and then refreshing your page)
and who is the Initiator? (in the screenshot the tab on the right)
should be something like this. It's a bit hard to help when the sceenshots only contain minimal information 😄
I'm sorry, I'm totally unfamiliar with web development, so idk how to debug the console log
ok so your UISelector script is trying to import a script that does not exist there anymore. Open the script in your editor (see screenshot) and change the import path to @needle-tools/engine/src/engine/engine_utils)
Or just @needle-tools/engine should work too in this case
no problem
ok, now the app is running again on the browser, thank you very much, now I'll go back to the original issue to see how it goes
I'm using your code and I only see the ("==OnEnable==") and ("SEND") console logs on the quest browser
I'm running also the app on the desktop browser and the logs are from the quest browser
async onEnable()
{
console.log("==OnEnable==");
await delay(1000);
this.context.connection.beginListen("test", (data) => {
console.log(data);
});
const myData = {
time: Date.now(),
};
console.log("SEND");
this.context.connection.send("test", myData);
}
great, I'm now receiving the message on the desktop browser, thanks for your help!
Hi, I'd like to ask you some help sending my data over the network. I've just recently updated my Needle Engine Package to the 2.67.18 version. I'm trying to send the date for testing, but I'm only receiving: "[object Object]" on the console. Also tried sending my own data through the implementation of my own type, but I receive the same message on the listener
You're receiving [object, Object] because you try to add it to a string.
If you want to log it and read it in the browser console just do it like so console.log("some string", data)
console.log can take as many or few arguments as you like and it will put them in the browser console. It's pretty nice
Thanks for your quick response, so this line should display the data? console.log("listener received: "+data);
oh, the ","
let me try tht
wow, it worked. Not sure how that can make a difference hehe but thank you! It worked, I'll try again sending my data
Well if you write "a string" + myObject it will try to concat that random javascipt object. It's invoking the toString() method on that object and by default that returns just the type name (it is the same as in c#).