Is there a hook / overwriteable function, when a placeable foundry vvt object was succesfully added to the scene and is ready to be used?
calling
const myown_data = { give_me_icecream: true }
canvas.scene.updateEmbeddedDocuments('ContainerName',[{ _id: this.data._id, ...myown_data }])
in
_onCreate
complains that the data could not be written / saved when I create the object. But when I reload the scene the data is written to all objects of the type without a problem. I would like to just to set some default values for a BOOLEAN_FIELD or any other DocumentField in a foundry.abstract.DocumentData Class, which should be used only when the object is created for the first time.
The solution is to overwrite the _initialize () function of DocumentData (in the module folder it is name something like ModuleNameData.js).
export class MyOwnClassData extends foundry.abstract.DocumentData {
static defineSchema ()
{
_id: fields.DOCUMENT_ID,
scene: {
...fields.DOCUMENT_ID,
required: false,
nullable: true
},
my_own_member: fields.BOOLEAN_FIELD
}
_initialize () {
super._initialize()
this.my_own_member = true
}
}