Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Instantiated prefabs don't have textures only in windows build

Discussion in 'Windows' started by raganvald, Aug 15, 2019.

  1. raganvald

    raganvald

    Joined:
    Feb 1, 2019
    Posts:
    5
    I have some models that are prefabs. If I drag and drop them in the scene they have their materials. If I Instantiate the prefab in code they end up with the default texture (all black). This only happens in windows, when I hit play from the editor the instantiate makes objects with textures. Does anyone have any idea why this happening.

    The objects were created in blender 2.7 and have just have a color assigned to them, they are placeholders. I tried to extract the materials but that didn't work, it created the materials and I had to just reassign the colors, in Unity and assign them to the object. All the textures are 2048 in size

    Version 2018.3.8F1

    Also tried Version 2019.1.9f1 with same result.

    #From Code
    unit = Instantiate(button.gameObject.GetComponent<Action>().building, position: BuildingSelection.selectedbuilding.transform.position, rotation: BuildingSelection.selectedbuilding.transform.rotation);

    Screenshot attached, the objects towards the back were dragged into the scene, the black ones were Instantiated. texture-gltich.jpg
     
    Last edited: Aug 15, 2019
  2. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    406
    From your description, this appears to be a bug.

    I think what's happening is the textures are being stripped from the Standalone build because they aren't being referenced by an actual GameObject in the project. When the Prefab is instantiated in the Editor the textures are referenced and included in the build.

    As a workaround, you can try instantiating the Prefabs as "dummy" GameObjects, forcing the textures to be included in the build, and then instantiate the real objects in code.

    But please file a bug for this issue.
     
  3. raganvald

    raganvald

    Joined:
    Feb 1, 2019
    Posts:
    5
    For your workaround I thought that's what I would be doing by dragging them into the scene, forcing them to be included. However it doesn't seem to resolve the issue, as seen in screenshot.

    Im not sure what you mean by instantiating them as dummy game objects? Do you mean placing the object instantiate in a start method but outside the visible scene?

    Ill make sure to log a bug.
     
  4. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    406
    Sorry, I misunderstood; something is definitely wrong then.

    Yeah, that's basically what I meant or creating a Prefab instance that's invisible or de-activated, just so there's an actual instance of the Prefab in the scene, but since you're already doing that this suggestions is moot.
     
  5. LinkoVitch

    LinkoVitch

    Joined:
    May 14, 2015
    Posts:
    16
    Has there been any update/progress on this? I think I may be seeing similar/related issue. When I am instantiating a prefab that is essentially a transparent plane with a grass texture on it, in editor these appear correctly, however in builds (multiple platforms) I can see nothing. Breakpointing the code does show the mesh and material seem to be present in the instantiated instance however.