diff --git a/dist/preview release/what's new.md b/dist/preview release/what's new.md index 0acb08c2827..68e1e7edcf5 100644 --- a/dist/preview release/what's new.md +++ b/dist/preview release/what's new.md @@ -377,4 +377,5 @@ - Fix width/height GUI container computation to take into account paddings when `adaptWithToChildren = true` ([Popov72](https://github.com/Popov72)) - `smoothstep` in NME is now taking any type of parameters for its `value` input. If you use generated code from the NME ("Generate code" button), you may have to move the smoothstep output connection AFTER the input connections ([Popov72](https://github.com/Popov72)) - `SoundTrack.RemoveSound` and `SoundTrack.AddSound` were renamed to `SoundTrack.removeSound` and `SoundTrack.addSound` ([Deltakosh](https://github.com/deltakosh)) -- `PolygonPoints.add` no longer filters out points that are close to the first point ([bghgary](https://github.com/bghgary)) \ No newline at end of file +- `PolygonPoints.add` no longer filters out points that are close to the first point ([bghgary](https://github.com/bghgary)) +- `Material` created with matching names now have auto-incrementing IDs. \ No newline at end of file diff --git a/src/Materials/material.ts b/src/Materials/material.ts index ab77b11e775..e900e860021 100644 --- a/src/Materials/material.ts +++ b/src/Materials/material.ts @@ -660,9 +660,14 @@ export class Material implements IAnimatable { */ constructor(name: string, scene: Scene, doNotAdd?: boolean) { this.name = name; + let idSubscript = 1; + this._scene = scene || EngineStore.LastCreatedScene; + this.id = name || Tools.RandomId(); + while (this._scene.getMaterialByID(this.id)) { + this.id = name + " " + idSubscript++; + } - this._scene = scene || EngineStore.LastCreatedScene; this.uniqueId = this._scene.getUniqueId(); if (this._scene.useRightHandedSystem) {