实例化游戏对象的阴影错误? [英] Shadows for Instantiated Game Object bug?

查看:98
本文介绍了实例化游戏对象的阴影错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在一个项目上,我的下一个目标是能够在运行时实例化预制件,我设法达到了这一步,但是我注意到实例化的预制件没有任何阴影.我尝试将完全相同的对象拖到场景中,并且它可以投射阴影.我做了一些谷歌搜索,发现很多评论都认为这是版本5中的Unity3d错​​误,只是好奇是否有人遇到相同的问题并设法找到一种a回的方法来解决这个问题.

I'm currently working on a project and my next goal is to be able to instantiate a prefab during runtime, i managed to reach that far but I noticed that my instantiated prefabs doesn't have any shadows. I tried dragging the exact same object to the scene and it can cast shadow. I've did some googling and found many comments of this being a Unity3d bug in version 5, just curious whether anyone encountered the same problem and managed to find a roundabout way to fix this.

我生成的预制件几乎都不同.

The prefabs I'm spawning are mostly all different.

将带有阴影的平面和立方体拖动到场景内部,同时实例化没有阴影的物体.

The plane and cube with the shadow is dragged inside the scene whilst without shadow are instantiated.

非常感谢您抽出宝贵的时间来阅读!

Thanks alot for taking the time to read!

编辑1 因此,我尝试了一些测试,试验和错误,我注意到有阴影和无阴影的游戏对象之间的唯一区别是,没有阴影的游戏对象来自加载的资产束.

EDIT 1 So I've tried a couple of testing and trials and errors, and I noticed that the only difference between the game objects that have and doesn't have the shadow is that the gameobjects without the shadow was from an assetbundle loaded.

我的问题似乎与此人的帖子类似

My problem seems to be similar to this guy's post

在生成assetBundle( .unity3d文件)

编辑2

如果有帮助,我正在使用Unity版本5.5.1f1

I'm using the Unity version 5.5.1f1 if that helps

推荐答案

似乎通过assetbundle实例化了它的着色器,我使用此代码重新设置了场景中的所有着色器,并且对我有用./p>

Seems like instantiating through assetbundles did something to it's shader, I used this code to re-set all of the shaders in the scene and it worked for me.

Shader standardShader;

void Start() {
    standardShader = Shader.Find("Standard");
}

void changeShader() // because shadow for assetbundle is cucked.
{
    var renderers = FindObjectsOfType<Renderer>() as Renderer[];
    for (int i = 0; i < renderers.Length; i++)
        renderers[i].material.shader = standardShader;
}

,并在所有实例化完成后调用它.

and called it after all of the instantiating is done.

这篇关于实例化游戏对象的阴影错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆