Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question After Building, Enemies are Invisible

Discussion in 'Editor & General Support' started by ApexSeal, Sep 5, 2020.

  1. ApexSeal

    ApexSeal

    Joined:
    Sep 5, 2020
    Posts:
    6
    Hello! I hope this is the appropriate place to post this request for help.

    I'm new to Unity, and I've been working on a project for a few weeks now. Today, I tried to build and run my project, and none of my enemies (which are prefabs being spawned into the map) show up on the screen. Within the Unity editor, when I hit play, in the game scene it shows all the enemies when spawned, and I can click on them to interact with them.

    Is there something wrong in my build settings? I don't know where to look, and I've been trying to google this problem but I'm not finding much.

    Thank you in advance for any help!
     
  2. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,593
    Im presuming somehow the prefabs arent spawning, perhaps you can try print out some debug stuff, like put a try catch around where you spawn them and see if theres any errors.
     
  3. ApexSeal

    ApexSeal

    Joined:
    Sep 5, 2020
    Posts:
    6
    Thanks for your suggestion! I tried this. (Side question, can I output debug logs outside of the editor? When the exe of the game is running?) Within the editor I can see them spawning, and if I wasn't clear before, when I'm in the game scene the objects spawn, are visible and intractable.

    When the actual game is running (when I build and run) I can tell that the objects of the enemies are being spawned because when they touch the player, the health bar in the UI goes down. I just cannot see them on the screen. So I assume the object and their collision boxes are being spawned and are functional, but the actual asset isn't being generated.


    p.s. I'm still learning the terminology so if I call things wrong, please forgive me.
     
  4. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,593
    Weird, are they static or something? if so turn that off.. Could you try making a build without occlusion culling on (just clear the data), maybe theyre culled somehow.
    As for printing in a build, not really but you could make a little canvas class to draw to, or write to a debug log, in fact I think unity does keep the log in the build folder for you (not sure I havent been able to make a build in over 5 yrs).

    Maybe they're on a layer that is not visible? if they're on a different layer to visible things try changing the layer to things you can actually see.. maybe somehow mesh renderers are turned off you could output to log to check that too.
     
  5. ApexSeal

    ApexSeal

    Joined:
    Sep 5, 2020
    Posts:
    6
    I assume when you are talking about static, you mean if the Rigibody's Body Type is? If so - no, it's Dynamic.
    As far as occlusion culling, I don't know what that is or how to use it. So I will definitely look into that more, and report back.

    I thought it was a layer issue, but I've put them in every layer, even my custom one (for enemies) but no change. Everything is on the default layer as of right now. Even if it were a layer issue, when I run the game within the editor, shouldn't it be the same as if I built and ran it??
     
  6. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,593
    Actually I mean is static ticked in the top right , but if you arent using occlussion culling then its probably not that. Yes build should be identical, but often isnt. Is there a log you can check for errors?

    Long shot but do you have LODs on enemies? if so tunr that off for now. Can you give me a screenshot of the inspector with an enemy selected in the editor? Just so I can see whats attached.
     
  7. ApexSeal

    ApexSeal

    Joined:
    Sep 5, 2020
    Posts:
    6
    Ok, so I had some time today to finally rip apart my project and try some things. First I tried just adding game objects with a sprite renderer and I noticed that I had to fiddle with the Z value to make it visible. It looks like by default the object is behind my tile map/ grid. So I decided to do the same with my spawner object, move it into the same Z axis that the new game object was, because my thinking is that if they are on the same Z plane the enemy objects would spawn on that Z plane. But I guess this is not the case, because when a prefab of the enemy is spawned, it has a value of 0 for Z. (if I didn't mention before, and I'm truly sorry for that, this is a 2D game). So I think I will have to use a Vector3(?) instead of a Vector2, when I call Instantiate; because the default Z value is behind the tile map.

    The last thing I did was I removed the tiles from my game, and built and ran it, and now the enemies show up!

    I guess the real question is...what is the best practice for making my tile map? It was all at 0 for the Z position. But clearly if the other game objects are at 0 Z, along with the tile map, it will be displayed behind the tiles.
     
  8. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,593
    Im not so good with 2D, maybe just move tiles slightly further back on z? or maybe there is some way to order. Cant help much with 2d but sounds like you're on the right track now, keep googling it :)