#Error building game

1 messages · Page 1 of 1 (latest)

autumn obsidian
idle viper
#

BallMove.cs

using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;

public class BallMove : MonoBehaviour
{
    Rigidbody2D rb;
    public int initialSpeedX = 8;
    public TMP_Text pointText;
    public Vector2 InitialPosition = new Vector2(0f, 2f);
    public TMP_Text RestartText;
    int Point = 0;
    int MaxPoint = 0;
    bool GameEnded = false;

    void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    public void Reset()
    {
        rb.linearVelocity = new Vector2(Random.Range(-initialSpeedX, initialSpeedX), 0);
        rb.position = InitialPosition;

        if (Point > MaxPoint)
        {
            MaxPoint = Point;
        }

        Point = 0;
        pointText.text = $"point: {Point} (Max: {MaxPoint})";
        RestartText.color = new Color(1f, 1f, 1f, 0f);

    }
    void Start()
    {
        Reset();
    }

    void Update()
    {
        if (GameEnded && Keyboard.current.spaceKey.isPressed)
        {
            GameEnded = false;
            Reset();
        }
    }

    public void EndGame()
    {
        GameEnded = true;
        RestartText.color = new Color(1f, 1f, 1f, 1f);
    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.CompareTag("Player"))
        {
            Vector2 velocity = rb.linearVelocity;
            velocity.x += Random.Range(-7f, 7f);
            rb.linearVelocity = velocity;

            Point++;
            if (Point > MaxPoint)
            {
                MaxPoint = Point;
            }
            pointText.text = $"point: {Point} (Max: {MaxPoint})";
        }
    }

}

autumn obsidian
#

send it with the code links under the large code block section

idle viper
#

Oh yes

#

So I paste my code there and copy the link?

autumn obsidian
#

yes

autumn obsidian
#

nothing here should cause an error like that. Hmm maybe a longshot but try and get unity to recompile, just add a blank line and go back to unity.
Or possibly restart computer and try again

#

i was testing something with building a game anyways, put those scripts in just as a sanity check and it builds fine.

#

The only other thing I could think is maybe you have some packages that are causing issues

idle viper
#

Ok. I'll restart my laptop and let you know the result.

#

Umm... but I made this code last night and already restarted.

#

I'm not sure this will work but I'll try

autumn obsidian
#

its not related to your code anymore, this is clearly either some issue with unity or a package

idle viper
#

Yes... I think so...

autumn obsidian
#

I dont have all that much time but I think the best things to try here is
restarting,
see what packages you have installed, maybe there is some conflict,
close unity, delete the library folder, and reopen the project

#

i built my game with an intentional error, trying to use unityeditor code in a build, and this is how it shows in the logs

#

though this also does show in my console

idle viper
#

This makes me so overwhelmed 😭

idle viper
#

another problem occured...

#

and my all gameobjects are gone

#

What did I mistake? 😭

#

Should I consider to redownload Unity?

idle viper
#

Oh, I exited Unity Hub, deleted /library, and opened it again. Then Something started to be redownloaded.

#

All thing came back. But I can't build...

idle viper
#

I have no idea what's going on here...

autumn obsidian
# idle viper Should I consider to redownload Unity?

possibly. this isnt really something ive seen before truthfully.
Maybe make a new project, put a cube in the scene, and just try to build that. I think this is either an issue with some package, or maybe unity got messed up when installing/creating the project

#

Creating a project is relatively quick at least, id try making a new one before reinstalling the editor

idle viper
#

Ok. I'll give it a try

autumn obsidian
#

given the warnings, its really likely the project was just corrupted in some way

#

its hard to say really what the issue is since first it wasn't building for some unknown reason. Maybe that error was hidden deep in the editor log unless you went through it all. Regardless this still shouldnt happen

#

deleting the library folder is safe because as you saw, unity rebuilds it

idle viper
#

I think when unity tried to delete something, I pressed no button in the dialog at that time. Just once, and I deleted Library folder and pressed yes then. Maybe something should've been deleted automatically but I denied it, so it made error? I'm not sure...

#

result.

autumn obsidian
#

Yea most likely the project was just corrupted then. Are you using version control?

idle viper
#

Hmm, I mean I did something and unity tried to delete something(I think not library folder) and, but I said no. I'm not sure this is the reason.

I did delete library folder while unity is closed.

idle viper
autumn obsidian
#

thankfully it is a small project but yea id truthfully just move on from the corrupted one then. u should always use version control (git)

idle viper
#

Should I do something when moving script from current project to new one? I would move on as you said and learn how to use git. Thank you for your help, although I'm not good at English 🥲

autumn obsidian
idle viper
#

Would create empty script in new project and copy codes be the best solution?

autumn obsidian
#

i think this was more just being unlucky, or some package issue, rather than anything you did