Hello All.
I am currently programmatically creating a world made of a cube prefab (already present in the scene) and a floor (also present in the scene, made from a flattened cube).
The cube and the floor have different materials. Both are instantiated with instantiateSynced.
The instantiation of the world is created only once, depending on the user role (maker and observer), set from url parameters.
Sometimes for unclear reasons, the material of the objects are swapped.
Also, since deploying to glitch, sometimes the whole world is only partially renderered for the observer.
That seems like the server did not register or is not serving the full list of instantiated objects.
Also, is there a better practice for programmatically creating scenes ? would having those prefabs as gltf be more efficient ? (i tried but nothing was instgantiated so i gave up)
Oh and I don’t get any skybox in safari, or chrome on my mac… but on safari ios it pops up … why is that ? Thanks !
The url parameters contain only the role (or more settings for the world generation)
Are you joining a room before creating the world? Are you using the SyncedRoom component and if so with which settings? Just asking if you are using the same room for all your worlds or if you use a different room for each world? If it’s the same room it could lead to collisions / data being used from a previous world.
How big is your world? E.g. how many instantiations are you doing? Can you show a bit of sample code for how to generate the world with the instantiateSync call?
I dont think prefabs are the problem/solution. There are multiple alternative solutions to try to solve it but I’d like to figure out what might be wrong with your currentl approach right now first (could you send your project as a bug report? using the Needle Engine/Report a bug menu item)
Alternative a)
just sync the seed and settings via networking and then generate the world for each client again instead of syncing each instantiation
Alternative b)
manually sync the object data in one big array/object and sync one object (the “world-generation-state”) instead of multiple individual instantiations
About the skybox: do you get any errors in the browser console? Are you exporting the skybox from Unity too? I havent heard of any issue like that before. Do you have a link to your deployed site?
answering question 2) :
My synced Room component is set to GlitchTemplate, url parameter name to “room” and booleans join random, require room parameter and auto rejoin all set to true.
at the moment I let it generate a random room, then add my parameters such as : &id=player. this parameter set the creation of scene. First I check if there are any objects as children of a transform that is supposed to be the parent of all scene objects. then if none, I generate a 2D array that creates a maze with its path. I then instantiateSync cubes whereever the value of the 2D array is set to 1 (wall).
here is a pieces of code:
// Create cubes for the maze
for (let i = 0; i < this.mazeSize; i++) {
for (let j = 0; j < this.mazeSize; j++) {
if (this.maze[i][j] === 1) {
// Create a cube for a wall
const opts = new InstantiateOptions();
opts.context = this.context;
opts.parent=this.mazeContainer;
opts.position = new Vector3(j * this.cubeSize, this.cubeSize/2,i * this.cubeSize);
if(this.prefab!=null)
{
const prefabInstance = GameObject.instantiateSynced(this.prefab, opts) as GameObject;
if (!prefabInstance) return;
this._instances.push(prefabInstance);
}
}
}
}
" If it’s the same room it could lead to collisions / data being used from a previous world." => I use the same room per session. Sometimes the creation of the scene fails to find already present object and creates another maze over the first but most of the time it works.
I think i will do as you suggested ! creating the seed (array) on one instance and communicating it to all to have local instantiations of the maze ! Thanks !
How should I send the seed ?
using this.context.connect.sendBinary(arr:Uint8Array) ?
Would users joining late still get a callback once listening to this.context.connection.beginListenBinrary(identifier:string, callback:(data : ByteBuffer) => void) ?
You can just send it via a json object e.g. send() (not sendBinary, that’s only useful for sending data with a lot of updates to reduce the load on the networking server, e.g. it’s being used by the SyncedTransform using flatbuffers)
As of the skybox, i am not particularly exporting it. Out of the box it shows up on my iphone but doesn’t on my mac : safari or chrome. here is the glitch website: https://large-uneven-argon.glitch.me/
it should show the grey “blurred-skybox” from the SceneTemplate. Left as is, it won’t create anything unless you add &id=player .Any other instance joining the same room with a different id or none will become observers.
I get absolutely no error in the console. it does say needle version 3.6.4 though. and i have Version 114.0.5735.133 (Official Build) (arm64) of chrome (latest)
what do i need to import ? VScode tell me there are no property “connect” on context. (by the way this is the kind of information i take hours looking for)
Glitch doesnt bring any css, when you deploy to glitch your bundled web files (in the dist folder) are just zipped and uploaded and then unpacked on glitch.
ha ! ok makes more sense ! I guess the key is to identify between messages ? do i set what ever I want on both ends? How do i convert my array to JSON ? i guess i can’t use Jsonutility …