Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Build not working

Discussion in 'Editor & General Support' started by Chalk_snacker, Dec 4, 2023.

  1. Chalk_snacker

    Chalk_snacker

    Joined:
    Jul 16, 2023
    Posts:
    3
    Hi! Me and couple friends are making a 3D tower defence game as a project for school and we're now almost at the finish line. Everything is working perfectly in Unity itself, but as soon as we build the game, so much stuff breaks. We have no idea why, and obviously tried googling. Lots of people suggested that we look at the logs (player / output_log) to see what the errors were, but no errors are logged https://pastebin.com/MM1tCicP.
    The issue when building the game is that the towers wont rotate except for 2 of them (everything works perfectly in the editor) and the line renderer is not working either. https://imgur.com/a/ebXKI9B
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,066
    First link is broken. You can attach images right here in the forum.

    Did you check the „development build“ checkbox in the build dialog? Not sure how it affects the player.log contents, but with this enabled you would get an ingame popup if there is an exception.

    Other than that it‘s hard to tell what might be going on. I suggest adding logs and also try attaching the debugger to a running build to be able to inspect variables „live“ and also be able to step through code to see if it‘s taking a wrong turn somewhere.

    Nice work by the way! :)
     
  3. Chalk_snacker

    Chalk_snacker

    Joined:
    Jul 16, 2023
    Posts:
    3
    We have tried checking and unchecking the development build checkbox. Haven't tried attaching a debugger to the running build, but in the log file, there are no errors occurring.
    https://pastebin.com/MM1tCicP


    Thanks btw :D
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,287
    The usual culprits for built-vs-editor issues is doing incorrect asset loading (such as using System.IO.File, which is almost always wrong in Unity unless you know what you're doing) or else order of execution issues between scripts. There are many other possibilities too.

    Excellent first place to check, now it's time to add more info to find out what is actually happening in the built game.

    Time to start debugging!

    By debugging you can find out exactly what your program is doing so you can fix it.

    Here is how you can begin your exciting new debugging adventures:

    You must find a way to get the information you need in order to reason about what the problem is.

    Once you understand what the problem is, you may begin to reason about a solution to the problem.

    What is often happening in these cases is one of the following:

    - the code you think is executing is not actually executing at all
    - the code is executing far EARLIER or LATER than you think
    - the code is executing far LESS OFTEN than you think
    - the code is executing far MORE OFTEN than you think
    - the code is executing on another GameObject than you think it is
    - you're getting an error or warning and you haven't noticed it in the console window

    To help gain more insight into your problem, I recommend liberally sprinkling
    Debug.Log()
    statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the names of the GameObjects or Components involved?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as
    Debug.Log("Problem!",this);


    If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

    You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

    You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer for iOS: https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/ or this answer for Android: https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/

    If you are working in VR, it might be useful to make your on onscreen log output, or integrate one from the asset store, so you can see what is happening as you operate your software.

    Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

    If your problem is with OnCollision-type functions, print the name of what is passed in!

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494

    If you are looking for how to attach an actual debugger to Unity: https://docs.unity3d.com/2021.1/Documentation/Manual/ManagedCodeDebugging.html

    "When in doubt, print it out!(tm)" - Kurt Dekker (and many others)

    Note: the
    print()
    function is an alias for Debug.Log() provided by the MonoBehaviour class.
     
  5. Chalk_snacker

    Chalk_snacker

    Joined:
    Jul 16, 2023
    Posts:
    3
    UPDATE!
    The part of the model that was supposed to rotate was given a tag. Each tower had 5 models under it, one for each upgrade level. We used "GameObject.FindGameObjectsWithTag()" to get an array with all of those objects that had the tag. Since the models were ordered empty that held them, it returned a correctly ordered array. The problem however was that it didn't return the correct order in the build version of the game, which screws up everything since we assume that they're in order. How we fixed it was by making 5 different tags, so we could be 100% sure that the list containing them would be ordered correctly. Now I have no idea WHY it doesn't order them correctly in the build version, but that's why.
     
  6. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,211
    Looks like this worked by some chance or original cached ordering, since the find by tag does not guarantee an order.

    You could order the list by any other trait, e.g. object name, than use 5 tags

    A useful link on the above
    https://discussions.unity.com/t/order-of-gameobject-findgameobjectswithtag-string-tag/3229/2