How to reference material with Unity Exporter scripts

Does anyone know if its possible to pass a material as a parameter to a C# script and access that with the Typescript mesh component ?

I have this C# script:
namespace MyProject
{
public class Video : EditorScriptComponent
{
[Header("-Script Properties-")]
[BabylonProperty]
public string URL;
public Material material;

        protected Video()
        {
            this.babylonClass = "PROJECT.Video";
        }
    }
} 

when I try to access the material in the Typescript file using
this.material = this.getProperty<BABYLON.Material>(“material”);

it just returns null.

Maybe @MackeyK24 can shed some light on this?

The the property is not a native BABYLON.Material but rather metadata describing the name of the material… The material itself gets exported into the scene and you can get the material from the scene by name

const materialData:any = this.getProperty(“materialEditorProperty”);
const materialName:string = materialData.name;

then just get material from scene by name

FYI… IN the new toolkit this metadata is strong typed

    export interface IUnityMaterial {
        type:string;
        name:string;
        gltf:number;
    }

As a matter of fact … here are the Unity Interface For Th New Toolkit

So if you use any of these property types… this will be its metadata

    /**
     * Unity Export Interfaces
     */
    export interface IUnityTransform {
        type:string;
        id:string;
        tag:string;
        name:string;
        layer:number;
    }
    export interface IUnityCurve {
        length:number;
        prewrapmode:string;
        postwrapmode:string;
        animation:any;
    }
    export interface IUnityMaterial {
        type:string;
        name:string;
        gltf:number;
    }
    export interface IUnityTexture {
        type:string;
        name:string;
        width:number;
        height:number;
        filename:string;
        wrapmode:string;
        filtermode:string;
        anisolevel:number;
    }
    export interface IUnityCubemap {
        type:string;
        name:string;
        width:number;
        height:number;
        filename:string;
        wrapmode:string;
        filtermode:string;
        anisolevel:number;
        texelsizex:number;
        texelsizey:number;
        dimension:number;
        format:number;
        mipmapbias:number;
        mipmapcount:number;
    }
    export interface IUnityAudioClip {
        type:string;
        name:string;
        filename:string;
        length:number;
        channels:number;
        frequency:number;
        samples:number;
    }
    export interface IUnityVideoClip {
        type:string;
        name:string;
        filename:string;
        length:number;
        width:number;
        height:number;
        framerate:number;
        framecount:number;
        audiotracks:number;
    }
    export interface IUnityTextAsset {
        type:string;
        filename:string;
    }
    export interface IUnityDefaultAsset {
        type:string;
        filename:string;
    }
    export interface IUnityVector2 {
        x:number;
        y:number;
    }
    export interface IUnityVector3 {
        x:number;
        y:number;
        z:number;
    }
    export interface IUnityVector4 {
        x:number;
        y:number;
        z:number;
        w:number;
    }
    export interface IUnityQuaternion {
        x:number;
        y:number;
        z:number;
        w:number;
    }
    export interface IUnityColor {
        r:number;
        g:number;
        b:number;
        a:number;
    }

Hope that helps some :slight_smile:

1 Like

Should I still be referring to Material in the C# script?

'cos when I try to access the property in the Typescript file this.getProperty(“material”) always returns NULL