[Scripting] Scene.create / Scene.delete

Hi everyone hope you’re doing alright,

I am creating an effect which relies on manipulating a bunch of objects, the effect uses the plane tracker and the update() is called everytime the phone moves (xyz or rotationX/Y/Z) - I may later change this to update on Time.ms.monitor().

I would like to dynamically create and destroy the objects based on the amount of lag the user experiences - instead of just removing them from the array.

My question concerns the functions “Scene.create” and “Scene.destroy” (there are similar ones for the Materials module). These functions have no documentation in the scripting object reference (https://sparkar.facebook.com/ar-studio/learn/reference/classes/scenemodule.sceneobjectbase). But they do have a JSDocs which reads as follows:
Scene.create:

function SceneModule.create(className: string, initialState?: {
[key: string]: any;
}): Promise<any>

create(className: string, initialState?: {[key: string]: any}): Promise

Create a scene object asynchronously. When creating the scene objects, keep the following in mind:

* All objects must have an existing class.
* New objects always get assigned a globally unique  `identifier` .`
* `initialState`  is optional, but encouraged to be used.
* `name`  in  `initialState`  is being used, unless it's not provided - then  `dynamicObject`  is used. )

Even when ignoring the optional initialState I have tried every key I could imagine and it didn’t work - throwing the usual and unhelpful “Unhandled promise rejection”. I haven’t been able to test with Scene.destroy as only objects created dynamically with .create can be destroyed.

Does anybody know how these functions work? Are they working or is it just a “place holder” that does nothing for the moment (They silently appeared not so long ago)?

Any help is appreciated :heart:

EDIT: As of 25 AUG 2020 the .ts doesn’t seem to have any underlying code that makes it all work

Undefined is not a function it’s a pity, hope this changes soon.

Wow, I haven’t seen this yet! I know they have some references to unreleased features in the docs and in the modules, so it might be the case here, too. I don’t see it in the official docs.

Generally I’ve found the errors in Spark to be unhelpful, but if you add .catch(err => D.log(err)) to the promise, you might be able to see what the error is.

My guess is that the className argument needs to be the name of a block asset.

1 Like

Nice find!
It got me curious, how would you be able to track the performance? This is really important

1 Like

I’ll give it a try and see what I can get, thanks

Take the difference between the .newValue and .oldValue, the average should be 33/35ms if the number is consistently higher then the user is experiencing lag ;).
I’ve been investigating a lot into performance in Spark for this effect. After I publish it I can send you a checklist I have developed to keep everything under control - I may forget so DM if haven’t reached out in a month lol

2 Likes

Undefined is not a function so yeah sadly a place holder for some future update…
Thx for the help though :grin:

2 Likes