I just want to get the last element from the list of models
Can't you use last
function instead? The removeLast
modifies the original list.
modelInstance = modelInstance.apply {
if(isEmpty()){
this += modelLoader.createInstancedModel(model, 10)
}
}.last()