Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by wasif_sc · Apr 21, 2020 at 07:00 PM · shadersassetbundlescriptableobject

Shader References seem broken for AssetBundle in HDRP Project

I am working in Unity 2019.3.6f1 in a HDRP project.

I am preparing AssetBundles of Prefabs according to the instructions here: https://docs.unity3d.com/550/Documentation/Manual/BuildingAssetBundles.html I am building the AssetBundles with the Asset Bundle Browser 1.7.0 package.

I load the AssetBundle using the following script, attached to a GameObject in the scene.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LoadObject : MonoBehaviour
 {
     AssetBundle loadedAssetBundle;
     public string bundleName;
     public string objectName;
 
     // Start is called before the first frame update
     void Start()
     {
         LoadAssetBundle(bundleName);
         InstantiateObjectFromBundle(objectName);
     }
 
     void LoadAssetBundle(string bundleName)
     {
         string pathPrefix = "";
         bool isOSXEditor = Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer;
         if (isOSXEditor) {
             pathPrefix = Application.dataPath + "/StreamingAssets/";
         } else {
             pathPrefix =  "file:///" + Application.dataPath + "/StreamingAssets/";
         }
         string bundlePath = pathPrefix + bundleName;
         loadedAssetBundle = AssetBundle.LoadFromFile(bundlePath);
 
         Debug.Log(loadedAssetBundle == null ? "Failed to Load " + bundleName: "Successfully Loaded " + bundleName);
     }
 
     void InstantiateObjectFromBundle(string objectName)
     {
         GameObject obj = loadedAssetBundle.LoadAsset(objectName) as GameObject;
         Debug.Log(obj != null ? "object: " + objectName + " loaded from bundle" : "failed to load object: " + objectName + " from bundle");
         Instantiate(obj);
     }
 }
 

When I run the program, the loaded asset looks pink (indicating some error with the shaders).

When I look into the object while the running the program, I can see that the materials for object (and child objects) are referencing the correct Shader for the Shader field, but the preview is pink. If I just click the Shader and reselect the same exact shader (for example HDRP/Lit) the material looks correct.

So it appears to me that the references to the Shader for the materials are somehow broken (even thought the names still appear in the inspector).

Is there a way to ensure these references can link to the right shaders without manual reassigning them? I also do not want to use a script to do that unless it can reassign any arbitrary shader.

I am not using any special custom shadergraphs, only shaders that are default in HDRP, such as HDRP/Lit.

Here is a screenshot where the first material is how it appears on load, and the second I just reclicked the Shader to "HDRP/Lit" and it works. alt text

How can I load AssetBundles so the shaders (such as HDRP/Lit) are properly linked?

screen-shot-2020-04-21-at-115027-am.png (28.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by J-Luna · Jan 18 at 01:33 PM

Hi @wasif_sc, any luck on this? I have the very same error on Unity 2020 LTS =(

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why isn't my scriptable object storing correctly in the AssetBundle? 0 Answers

When building AssetBundles some scriptable objects get corrupted 2 Answers

AssetDatabase.CreateAsset randomly fails claiming object has been destroyed 0 Answers

Loading Assetbundle scriptableobject settings. I can load the Scriptableobjects and place them in a list just fine but variables that are apart of it don't load. 1 Answer

How to import the object from server to unity 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges