Multiple Normal Maps are not loading

Discussion and help for Easy Save 3
khanx078
Posts: 10
Joined: Fri Jan 29, 2021 11:06 am

Multiple Normal Maps are not loading

Post by khanx078 »

I am trying to load a normal map , when saving the normal maps the values are being saved, but when i try to load the normal map for only the first item is being loaded which is in the original item and the normal map for its duplicates are not being loaded.

Code: Select all

SAVING
 foreach (var obj in gameObjects)
            {
                try
                {
                    if (obj.GetComponent<MeshRenderer>() != null)
                    {
                        if (obj.gameObject.CompareTag("walls"))
                        {
                            ES3.Save("wallColor", obj.GetComponent<MeshRenderer>().material.color);
                            ES3.Save("shader", obj.GetComponent<MeshRenderer>().material.shader);
                            ES3.Save("normalMap", obj.GetComponent<MeshRenderer>().material.GetTexture("_BumpMap"));
                        }
                    }
                }
LOADING
foreach (var obj in objects)
        {
            try
            {
                if (obj.GetComponent<MeshRenderer>() != null)
                {
                    if (obj.gameObject.CompareTag("walls"))
                    {
                        obj.GetComponent<MeshRenderer>().material.shader = ES3.Load<Shader>("shader");
                        obj.GetComponent<MeshRenderer>().material.EnableKeyword("_NORMALMAP");
                        obj.GetComponent<MeshRenderer>().material.color = ES3.Load<Color>("wallColor");
                        
                        obj.GetComponent<MeshRenderer>().material
                            .SetTexture("_BumpMap", ES3.Load<Texture>("normalMap"));
                    }
                  }
                 }
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Multiple Normal Maps are not loading

Post by Joel »

Hi there,

You're saving to normal key to the same key every time you save. This means that you're just overwriting the same normal map in the file rather than saving multiple normal maps to the file.

You would need to use a unique key for each GameObject (for example, by appending the position of the GameObject in the gameObjects array).

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
khanx078
Posts: 10
Joined: Fri Jan 29, 2021 11:06 am

Re: Multiple Normal Maps are not loading

Post by khanx078 »

I did what you said but the normal map is still not loading for the duplicated object its loading for the orignal one but not the duplicated one, While debugging the save function is picking up the normal maps , but while loading the normal map of the duplicated object returns null

Code: Select all

LOADING
for(var i = 0;i<objects.Length;i++)
        {
            var obj = objects[i];
            try
            {
                if (obj.GetComponent<MeshRenderer>() != null)
                {
                    if (obj.gameObject.CompareTag("walls"))
                    {
                        obj.GetComponent<MeshRenderer>().material.shader = ES3.Load<Shader>("wallShader"+i);
                        obj.GetComponent<MeshRenderer>().material.EnableKeyword("_NORMALMAP");
                        obj.GetComponent<MeshRenderer>().material.color = ES3.Load<Color>("wallColor"+i);
                        obj.GetComponent<MeshRenderer>().material
                            .SetTexture("_BumpMap", ES3.Load<Texture>("normalMap"+i));
                    }
            	}
            }
SAVING
foreach (var obj in gameObjects)
            {
                try
                {
                    if (obj.GetComponent<MeshRenderer>() != null)
                    {
                        if (obj.gameObject.CompareTag("walls"))
                        {
                            ES3.Save("wallColor"+ gameObjects.IndexOf(obj), obj.GetComponent<MeshRenderer>().material.color);
                            ES3.Save("wallShader"+ gameObjects.IndexOf(obj), obj.GetComponent<MeshRenderer>().material.shader);
                            ES3.Save("normalMap" + gameObjects.IndexOf(obj), obj.GetComponent<MeshRenderer>().material.GetTexture("_BumpMap"));
                        }
		}
	}
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Multiple Normal Maps are not loading

Post by Joel »

Hi there,

Are any errors or warnings outputted to console?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
khanx078
Posts: 10
Joined: Fri Jan 29, 2021 11:06 am

Re: Multiple Normal Maps are not loading

Post by khanx078 »

Easy Save cannot save the pixels or properties of this Texture because it is not read/write enabled, so Easy Save will store it by reference instead. To save the pixel data, check the 'Read/Write Enabled' checkbox in the Texture's import settings. Clicking this warning will take you to the Texture, assuming it is not generated at runtime.
<i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
UnityEngine.Debug:LogWarningFormat(Object, String, Object[])
ES3Internal.ES3Debug:LogWarning(String, Object, Int32) (at Assets/Plugins/Easy Save 3/Scripts/Debugging/ES3Debug.cs:30)
ES3Types.ES3Type_Texture2D:WriteUnityObject(Object, ES3Writer) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_Texture2D.cs:20)
ES3Types.ES3UnityObjectType:WriteObject(Object, ES3Writer, ReferenceMode) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3UnityObjectType.cs:45)
ES3Types.ES3UnityObjectType:WriteObject(Object, ES3Writer) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3UnityObjectType.cs:23)
ES3Types.ES3ObjectType:Write(Object, ES3Writer) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:35)
ES3Types.ES3Type_Texture:Write(Object, ES3Writer) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_Texture.cs:17)
ES3Writer:Write(Object, ES3Type, ReferenceMode) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:221)
ES3Writer:WriteProperty(String, Object, ES3Type, ReferenceMode) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:286)
ES3Writer:Write(Type, String, Object) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:142)
ES3Writer:Write(String, Object) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:129)
ES3:Save(String, Texture, ES3Settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:106)
ES3:Save(String, Texture) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:67)
ES3AutoSaveMgr:Save() (at Assets/Plugins/Easy Save 3/Scripts/Auto Save/ES3AutoSaveMgr.cs:102)
Crosstales.FB.Examples:SaveFile() (at Assets/Plugins/crosstales/FileBrowser/Demo/Scripts/Examples.cs:139)
UnityEngine.EventSystems.EventSystem:Update() (at D:/Unity/2019.4.18f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
khanx078
Posts: 10
Joined: Fri Jan 29, 2021 11:06 am

Re: Multiple Normal Maps are not loading

Post by khanx078 »

when i load i get these warnings with different reference ids
Reference for UnityEngine.Material with ID 2800731894987681754 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored.
<i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>
UnityEngine.Debug:LogWarningFormat(Object, String, Object[])
ES3Internal.ES3Debug:LogWarning(String, Object, Int32) (at Assets/Plugins/Easy Save 3/Scripts/Debugging/ES3Debug.cs:30)
ES3Internal.ES3ReferenceMgrBase:Get(Int64, Type, Boolean) (at Assets/Plugins/Easy Save 3/Scripts/ES3ReferenceMgrBase.cs:167)
ES3Types.ES3UnityObjectType:ReadObject(ES3Reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3UnityObjectType.cs:84)
ES3Types.ES3ObjectType:Read(ES3Reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:54)
ES3Reader:ReadObject(ES3Type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:249)
ES3Reader:Read(ES3Type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:278)
ES3Types.ES3CollectionType:ReadICollection(ES3Reader, ICollection`1, ES3Type) (at Assets/Plugins/Easy Save 3/Scripts/Types/Collection Types/ES3CollectionType.cs:52)
ES3Types.ES3ArrayType:Read(ES3Reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Collection Types/ES3ArrayType.cs:36)
ES3Reader:Read(ES3Type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:274)
ES3Reader:Read() (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:126)
ES3Types.ES3Type_MeshRenderer:ReadComponent(ES3Reader, Object) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/Component Types/ES3Type_MeshRenderer.cs:61)
ES3Types.ES3ComponentType:ReadUnityObject(ES3Reader, Object) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ComponentType.cs:36)
ES3Types.ES3UnityObjectType:ReadObject(ES3Reader, Object) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3UnityObjectType.cs:65)
ES3Types.ES3ObjectType:ReadInto(ES3Reader, Object) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:77)
ES3Types.ES3Type_GameObject:ReadComponents(ES3Reader, GameObject) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_GameObject.cs:211)
ES3Types.ES3Type_GameObject:ReadObject(ES3Reader, Object) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_GameObject.cs:162)
ES3Types.ES3ObjectType:ReadInto(ES3Reader, Object) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:77)
ES3Types.ES3Type_GameObject:ReadObject(ES3Reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_GameObject.cs:126)
ES3Types.ES3ObjectType:Read(ES3Reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:54)
ES3Reader:ReadObject(ES3Type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:249)
ES3Reader:Read(ES3Type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:278)
ES3Types.ES3CollectionType:ReadICollection(ES3Reader, ICollection`1, ES3Type) (at Assets/Plugins/Easy Save 3/Scripts/Types/Collection Types/ES3CollectionType.cs:52)
ES3Types.ES3ArrayType:Read(ES3Reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Collection Types/ES3ArrayType.cs:36)
ES3Reader:Read(ES3Type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:274)
ES3:Deserialize(ES3Type, Byte[], ES3Settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:775)
ES3:Deserialize(Byte[], ES3Settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:764)
ES3File:Load(String, GameObject[]) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:243)
ES3:Load(String, GameObject[], ES3Settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:413)
ES3AutoSaveMgr:Load() (at Assets/Plugins/Easy Save 3/Scripts/Auto Save/ES3AutoSaveMgr.cs:134)
Crosstales.FB.Examples:OpenSingleFile() (at Assets/Plugins/crosstales/FileBrowser/Demo/Scripts/Examples.cs:50)
UnityEngine.EventSystems.EventSystem:Update() (at D:/Unity/2019.4.18f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Multiple Normal Maps are not loading

Post by Joel »

Hi there,

As the error suggests, your Texture is not read/write enabled so it's not possible to get the pixels. You would need to read/write enable it.

As the warning suggests, an instance of your Material doesn't exist when you load. This is likely because you're accessing the 'material' field rather than the 'sharedMaterial' field. The 'material' field creates a new instance of the Material which will no longer exist when you exit the scene, meaning it's not possible to load it by reference after you leave the scene.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
khanx078
Posts: 10
Joined: Fri Jan 29, 2021 11:06 am

Re: Multiple Normal Maps are not loading

Post by khanx078 »

ok so i should use the shared material and make it read/write
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Multiple Normal Maps are not loading

Post by Joel »

That is correct, though be aware that sharedMaterial will also change the colour on other objects with that material. For more information on this particular subject I recommend asking on the Unity forums, as this behaviour regards Unity's functionality rather than ours.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
khanx078
Posts: 10
Joined: Fri Jan 29, 2021 11:06 am

Re: Multiple Normal Maps are not loading

Post by khanx078 »

Hi I enabled read/write for textures and used material instead of shared material. But the save is really slow now and when we have like 3 to 4 objects the easy save breaks and we get a not responding .
Will using a shared material with read/write enable increase the performance of the save and load.
Post Reply