Okay thanks. I think I’m actually running into a slightly different problem.
Later in my code I am looping through the mesh instances of my entity with render components and then Im trying to do the same with the entities that have model components. I am getting an error.
Am I right in saying that model(legacy) components do not have mesh instances in the same way that render components do?
Im trying to do this but get a forEach error:
modelComponents = this.app.root.findComponents("model");//need to also get model(legacy as well as render)
for (var i = 0; i < modelComponents.length; i++)
{
modelComponents [i].meshInstances.forEach(function (meshInstance)
{
.....blahh
Alternatively, is there a way to quickly change all my model(legacy) components to render components?
Odd because I do exactly the same with render components and there is no issue. For example…
This works:
var renderComponents = this.app.root.findComponents("render");//need to also get model(legacy as well as render)
for (var i = 0; i < renderComponents.length; i++)
{
renderComponents[i].meshInstances.forEach(function (meshInstance)
{...
…but this doesnt…
var modelComponents = this.app.root.findComponents("model");//need to also get model(legacy as well as render)
alert("there are "+modelComponents.length+ " model components")//8
for (var k = 0; k < modelComponents.length; k++)
{
modelComponents[k].meshInstances.forEach(function (meshInstance) //error cannot read properties of null (resading 'foreACH'
{....
I literally cut and paste that code and get an error: cant read properties of length…
var models = this.app.root.findComponents("model");
for (i = 0; i < models.length; i++) {
var model = models[i];
for (m = 0; m < model.meshInstances.length; m++) {// ERROR: Cannot read properties of null (reading 'length')
//do nothing
}
}
It simply means your model.json file is not loaded at the time you are executing this code (mesh instances have not been generated yet). Set your model asset to preload, or execute the code after the asset is loaded.
Wierdly Im alreay doing that. However, all I did to fix this was put the following line in.
var models = this.app.root.findComponents("model");
for (i = 0; i < models.length; i++) {
var model = models[i];
if(model.meshInstances)//PUT THIS IN AND IT ALL WORKS FINE!!
{
for (m = 0; m < model.meshInstances.length; m++) {// ERROR: Cannot read properties of null (reading 'length')
//do nothing