A Bug that I don't think is solved yet

When I was doing the Unity 2D course, in the Block Breaker section, in one of my levels, I placed only one block and for some reason, the block wouldn’t break when the ball collided with it. It took me a while to figure out but I placed one more block in the level and it started working. I think this might be something to mention in the course because it took me a while to figure that out. So could you possibly fix that bug or at least tell the students not to do that? It might be just me that I missed something that you said but just in case. Anyway thanks for reading!
-EZRock

EDIT:
Yeah, I just figured out that when you hit all the blocks, and there is only one left, it doesn’t get destroyed as well.

Did the ball still collide with the block?

Yeah it did, it just bounced right off though.

Couple reasons why that could be then, I would check your code to see what happenes in OnTrigger2D(Collider2D otherCollider)

Yeah nothing happened, and I made sure On triggered was on if that was supposed to be on. And sometimes even when there is more than one block, it still doesn’t break, but sometimes it does.

That should be OnTriggerEnter2D(Collider2D collision), e.g. the method name, the parameter name doesn’t matter.

@EZRock - perhaps share your project files and we can take a quick look, may be easier to resolve in context.

The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.


See also;

Thank you! Here is the link to the project folder on google drive:
https://drive.google.com/file/d/1HoB6nl3nsrDY8fyhqP40mcsgaH6Vnt7u/view?usp=sharing

Ok, give me a couple of minutes…

Ah yup, thank you! I mentioned the parameter here because of using Destroy(otherCollider);

You realise you have many blocks in Level one a different Z axis right? As is the Blocks GameObject, e.g. the parent container.

Wait what? I didn’t realize, is that part of the problem?

I edited Level 1, removed all of the Blocks, and reset the Transform of the Blocks parent object.

I added one block from your Block prefab and ensured it had a Z axis of 0.

I ran the scene but an error was thrown, so I ran your game from the Start scene instead, after destroying 3 of your blocks, the ball hit the forth and then generated an error. This is because you are trying to access the sceneLoader which doesn’t exist in your scene.

The error stops the game and any further code from running, this is why that fourth block doesn’t disappear in scene 2.

Next I changed your Build Settings so that scene 1 is before scene 2, in order to test the just one block issue. I ran the game, clicked the Start button and the game again errors. This time because of a missing reference to scoreText. You are trying to access its text property get have no reference to a UI object to do so.

If you comment out lines 17 and 29 in GameStatus.cs where you do this, this will temporarily remove these errors.

Then, do as I did;

  • remove all blocks from scene 1
  • reset the transform for the Blocks GameObject
  • drag in one Block prefab under Blocks
  • reorder the scenes in Build Settings so that Scene 1 is before scene two

Run the game.

After clicking the Start button you’ll have one block to hit, hit it and it is destroyed and the second scene loads - no errors.

Hope this helps.

2 Likes

Oh wow, oops. But how do I fix the bug where the blocks in the other level break?

See above…

With regards to the Z axis… you need to ensure that the blocks are all on the same value as the ball, otherwise it will not be able to make contact with them, this isn’t/wasn’t your only issue, but it would have been the next.

Regarding the two lines of code I advised you to comment out, looking further it would seem you currently have two GameCanvas prefabs, one just has a “1” suffix on the end which you can’t easily see unless you reduce the sizing in the Project view. The one you have in Level 1 does not have a ScoreText GameObject in it, the one level 2 does, however the reference to this hasn’t been created which is why the errors are thrown.

In general I think you may have missed a few steps whilst working through the lectures here and I would advise spending a little bit of time on some housekeeping, tidy things up and get back to a point in the course to which your current project aligns, then continue forward.

Thank you so much! It is working perfectly now. I appreciate the support!

1 Like

You’re very welcome :slight_smile:


See also;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms