So frustrating

Screenshot_20221206_024805

Please someone find the error.

I have been at what should be one of the more simple tasks. Just get the console to say, these things. I was wanting to solve it on my own, but I have done it over and over. I am trying to only veer off course when asked too.

Anyway, for some reason, all this does is register the collision with the default.

I checked the names of the Objects, everything matches. I tried moving on, hoping it would work itself out (Meaing I missed something little and it would get fixed) but I can’t because this isn’t working.

Up to this point, I haven’t had a single issue, and understand pretty well what is being asked of me.

But man…

Also, the reason I can’t move on is the next project is asking to reload the scene upon a crash. But since it is only reading everything as default, the scene just constantly reloads.

Thanks in advance!

Are you sure you spelled the tags right,
and have assigned them to the gameobjects that need to have them?

Also in the future if you want put code in your post: press Enter to start a new line and CTRL+SHIFT+C,
and paste the code between the graves, then others can copy/edit if they want to help you.

it would look like this;

using UnityEngine;

public class collisionDetection : MonoBehaviour
{
    private void OnCollisionEnter(Collision other)
    {
        switch (other.gameObject.tag)
        {
            case "Friendly":
                Debug.Log("Safe");
                break;
            case "Finish":
                Debug.Log("Finish");
                break;
            default:
                Debug.Log("Default");
                break;
        }
    }
}

Hey thanks for the heads up on posting script, I was looking but was frustrated.

So it has to be something in the scene, because to test I I copied your code, made a “collisionDetection” script and pasted yours. Exact same result. Just the default detection.

So at least now I can troubleshoot the Objects… Even though I swear they are all right.

I will mess around and see what I can do.

Again, thanks!

Yes your code is alright, thats why i asked if you set the gameobject tags on them,
and if theyre spelled right.
Since it prints your default, the collision is being detected, just the tag is not found/set.
so it defaults.
Hope you can find it!

(1)
You wrote “names of the objects”. Did you mean "tags of the objects? The property gameObject.tag won’t return the “name”. The name is what is listed for that object in the Hierarchy window or at the top of the Inspector window for that object. That would be my first suggestion for what to check.

(2)
If that doesn’t help, check the tag text for any leading or following spaces and for upper/lower case. If you have "Friendly " or “friendly” it won’t match the case condition.

(3)
If that doesn’t solve it, then try adding a Debug.Log statement at the top inside of the OnCollisionEnter method that will print out the name and/or tag of every object that it collides into. I thought I was having a problem, so I added something like this:

Debug.Log("collided object name: " + other.gameObject.name + "; collided object tag: " + other.gameObject.tag);

This should at least tell you what objects your rocket is colliding with, and in what order it’s happening, BEFORE the code thread even reaches the switch statement.

(4)
If that doesn’t help, then my last suggestion is to cache the tag in a variable, and pass that variable to the switch statement. I.e.:

string collidedObjectTag = other.gameObject.tag;
switch (collidedObjectTag)
{
	case ...

This shouldn’t make a difference, BUT sometimes it does and it leads me to discover something I hadn’t known before. :roll_eyes:

Good luck!

1 Like

I did indeed mean the tags and not the names! The tags are spelled correctly. I will check and double check spelling and upper/lower case, as well as everything else you suggested in the morning!

I will update if it works!

Thanks a lot, I know this is all newbie stuff, and it’s appreiciated!

So, I did this! And what I learned, was that for some reason, everything was tagging as “Other”. I tagged and retagged stuff, then decided I would remove each tagged item and replace it, and retag the new object.

And this worked, the only issue is, I am not 100% where I went wrong. Soooo I am going to chalk it up to some rookie mistake I won’t make in the future!

Thanks for the help!

1 Like

Good job on fixing the issue. Don’t worry too much about it. We all made this mistake and/or had this problem at some point. That’s why we know how to solve it. And now, you know it too and developed your skills a bit further. :slight_smile:

1 Like

Hooray! I’m glad that Debug line helped you chase down the issue. I’m curious too how those items were all tagged as “Other”. I’ve certainly managed to do things that made no sense to me afterwards, so you’re in good company. :sweat_smile:

FYI, I use Debugs a lot, to help track down a variety of errors. They’re great at showing me what data actually is at a given moment (vs. what I expected it to be), and to track down where an error is occurring (usually by numbering their printouts). They’re the next best thing after builtin variable tracking and breakpoints (which I still need to learn how to do in C#). :nerd_face:

I didn’t actually tag them as other, just left them default. And as far as I could tell, everything was tagged correctly. But since I removed and added new tagged objects, I haven’t had an issue. Soooooo… no idea! LOL

Thanks again for the help!

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

Privacy & Terms