#Materials saving as black (default colour)

1 messages · Page 1 of 1 (latest)

toxic vigil
#

I'm trying to save the generated material (s) as an asset, so the prefabs have the correct material data.. but they're saving as black (the default colour of the material) I'm not sure how to save it correctly

#

As an example, this is what it should save as:

#

But its just black

#

As you can see, the referenced material is "black" to begin with, but i change it via script. (Texture Data Scriptable Object) to get the correct data.

Does anyone know how i can save the material correctly?

toxic vigil
#

Anyone? 😭

knotty drift
#

Are you using the alpha anywhere? Because right now all your tings are set to zero alpha.

toxic vigil
#

The alpha doesnt affect anything

#

those colours are just a tint, im not using any tints :p

toxic vigil
#

Please

strong wharf
# toxic vigil But its just black

Okay, real quick sanity check: Are they actually black or are they just showing up that way in the inspector? If you drag them onto an object without opening them, are they still black?

toxic vigil
#

Yea @strong wharf the actual material is black. At runtime it changes

#

(Last photo I sent) shows the default material in assets

strong wharf
#

Is this the correct understanding of the flow/error?

toxic vigil
#

Correct

quiet hatch
#

What does one of the saved materials actually look like

toxic vigil
#

@quiet hatch literally completely black

quiet hatch
#

The actual inspector.

toxic vigil
#

Sorry, just woke up. I'll be at the pc in 5 mins

#

@quiet hatch

#

the is the inspector of the generated terrain chunk while in playmode

quiet hatch
#

Why is there no texture set in playmode?

#

I think the issue is that none of your variables are serialized

toxic vigil
#

I followed sebastian lagues landmass generation tutorial

quiet hatch
#

so they only exist on the instances at runtime, and as soon as you try to copy or reload they will disappear

toxic vigil
#

is there an easy way to see if that would fix it

quiet hatch
#

I think, making all of the variables that you want to save have matching parameters. You should be able to look at the material in debug mode and see what it's currently serializing

toxic vigil
#

I have no idea how to do this, Never used CG before

#

this is whats currently serializing on the mat @quiet hatch

quiet hatch
#

Take a look in the Saved Properties

#

Do you have variables in there - but just no interesting values?

toxic vigil
#

None of it, it looks like

quiet hatch
#

in the floats are all the ones you intend to use in there?

toxic vigil
#

only "testScale" is there

quiet hatch
#

It might be that only properties that are in the Properties block are serialized

#

Anything that you expect to save will need to have a property declared I imagine

toxic vigil
#

Do you know how to do that? if i copy them all into properties i get an error

quiet hatch
toxic vigil
#

they're all arrays though

#

Alright, i got this. But im unsure how to serialize a float3

#

when serializing the attributes, They're all white now. Perhaps i need to change the code

#
    public void ApplyToMaterial(Material material)
    {
        material.SetInt("layerCount", layers.Length);
        material.SetColorArray("baseColours", layers.Select(x => x.tint).ToArray());
        material.SetFloatArray("baseStartHeights", layers.Select(x => x.startHeight).ToArray());
        material.SetFloatArray("baseBlends", layers.Select(x => x.blendStrength).ToArray());
        material.SetFloatArray("baseColorStrengths", layers.Select(x => x.tintStrength).ToArray());
        material.SetFloatArray("baseTextureScales", layers.Select(x => x.textureScale).ToArray());
        Texture2DArray texturesArray = GenerateTextureArray(layers.Select(x => x.texture).ToArray());
        material.SetTexture("baseTextures", texturesArray);

        UpdateMeshHeights(material, savedMinHeight, savedMaxHeight);
    }```
quiet hatch
#

I don't think you can serialize arrays can you? That's not showing up as an array in the inspector

#

I don't think what you want is actually possible like this. Sadly it would be much easier if you made a ScriptableObject that had the data that you later applied to your material at runtime.

toxic vigil
#

Thats what i have, its in the pictures above

toxic vigil
quiet hatch
#

Then why are you trying to save material assets

toxic vigil
#

i need to save the chunks as prefabs

#

to use at a later date

quiet hatch
#

Save them with a component on them that references the ScriptableObject that canbe used to set values on the material at runtime

toxic vigil
#

😬

#

I'm way over my head in this

burnt rose
#

marcos

toxic vigil
#

@burnt rose What