Game is exporting weirdly

,

Hello, when I export my game for a build and run test, it only exports my main character sprite and the background color. It leaves everything else in the game, and the animation does not even play.

What is causing this and how should I fix it?

This is the game running on Unity editor.

This is the game when it’s built and run.

Any help would be appreciated! Thank you.

Time to start debugging! 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.

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 or iOS: https://discussions.unity.com/t/700551 or this answer for Android: https://discussions.unity.com/t/699654

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.

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://discussions.unity.com/t/839300/3

When in doubt, print it out!™

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

1 Like

When you build your game, are you getting any errors or warnings in the console? If so, fix all of that stuff first. It’s pretty unlikely that a build can fail that horribly without Unity noticing issues.

1 Like

Weirdly, there is nothing on the console. I have no idea what’s happening. I can’t even find anything about this online :frowning:

I think I’m confused because the code runs fine in the unity editor and there are no error messages in the console either. When I play it on the editor, it’s perfectly playable. But once I build it, it’s just my unmoving player sprite on the background without anything else.

Why would “online” know about bugs in your program?

As I said, you probably have a trivial bug you can find and fix by debugging.

See above.

Yeah… it’s not that simple. There’s critical information missing from your earlier post like… how to actually see debug information in a build haha. I’ve been using Unity for years and I still didn’t know how to do this. Googling the issue is also difficult as it gives loads of unrelated information. It took me like 30 minutes of searching before I found what I actually needed.

@oneunoia The answer is indeed debugging. If you want to see debug information in a build, tick the “Development Build” and “Script Debugging” options in Build Settings before building your game. After you open your newly built game, any errors will open a console, and you’ll be able to then open a log file with a ton of debug information. You can also just click on any errors in the console to view more info about them, like which script and line they’re occurring in.

The console only opens when you receive an error (which I’m sure you will), but you can add a Debug.LogError("This is an error.") line to your code (in Untiy) to guarantee the console opens in a build.

I tried this out with my game, and I received multiple errors that never showed up in the editor.

There’s probably easier ways to go about this, but I just learned about this stuff today.

Do you mean this part?

Or maybe just google for “unity see console log in build” if you don’t like my links?

No, I’m not using a mobile device, or VR. I’m using a PC, so after reading the lines “If you are using a mobile device” and “If you are working in VR” I stopped reading as I didn’t think they would be relevant. Maybe they are, wouldn’t have known.

As I said, googling was difficult. Every result on the first page after googling “unity see console log in build” gives a completely different answer. However, I did eventually find out how to do it.

I’m just trying to learn and be helpful.

SWEET! This is critical… gotta close the loop and get information back from whatever program you’re debugging, and the nearly-ubiquitous approach is the log / console log / device log / run log / editor log , etc. Ten million words for it, all the same idea.

And this is where YOUR Debug.Log() outputs can go as well. Depending on many variables, these may be suppressed in a final build, but Debug.LogError() should go through. In an extreme pinch you can also throw your own exceptions to blow up a build if you’re desperate to find “is this code even running?!”

Thank you both! I’ll try the things suggested and let you know how it goes. I’m a complete newbie to coding and developing games so it might take me a while…