Problems with Cactus and GameObject errors

I was moving along just fine with this project until we got to the animations. Then somehow I got totally messed up and had to leave the project for awhile and work on another project in another course. So now trying again.
I’m having trouble with my cactus and some errors that I can’t figure out. I just can’t figure out what is wrong. I think I figured out part of the issue I was having with my cactus but it’s still not right. I checked all my code against the most current code to verify – still getting errors. Not always the same error for some reason. Here is one of the issues that it keeps bringing up:

~

~

Here are the errors I am currently getting:

Here is what I have set up in Unity as far as my animations and cactus components. I was trying to use the axe for my weapon instead of the zuchinni. I think that is when I started having issues because I was trying to customize instead of following exactly what Rick chose.

This is what it looks like after pressing play. The cactus will shoot one time at one lizard (before my cactus turns green) and then it just stops and does nothing else. No more shooting and no more lizards coming out.

Hi Penny,

Check the Animator of your cactus. Is the Attacking state still active when the cactus is not shooting anymore? If so, click on the animation file in your assets folder and enable “Loop Time”.

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message. Which line in your code gets highlighted?

When I try to open up my project now, there is a problem because I upgraded to the newer version of Unity the last time I was in there.

Does that mean all of my projects will be inaccessible?

This is the message I get:

image

I have double-clicked on it and it takes me to the line of code that is in the first screen shot that I shared. I tried to figure out what the problem is but I haven’t been able to. I double-checked my code against Ben’s and everything is the same.

The message means that you are trying to open an project that was saved in an older version of Unity in a newer version. Usually, that should not cause any issues but it’s advisable to make a backup of your project by duplicating the project folder. Opening the project with a newer version of Unity might take a few seconds.

Bear in mind that some things work differently in Unity 2018.3, for example, the new prefab system. Update only if you want to use it.

Do not open a project that was opened with a newer version in an older version.

In your Shooter.cs, you have two relevant variables that are supposed to contain a reference to an object: projectile and gun. NullReferenceException means that a reference (“link”) to an instance is missing. If you exposed a field in the Inspector, make sure that it’s not empty. Check that for all defenders, also the prefab.

Make sure that the assigned gun prefab is the gun in your Hierarchy. The axe is supposed to be a prefab from your Assets folder.

Sometimes the components are buggy for no reason. It’s worth a try to remove Axe and Gun from the Shooter component and to reassign them. Also try to remove the entire Shooter component and reattach it.

I tried some of what you said and I think that may have fixed part of the problem but here is something else I found weird and I have no idea how this happened:

When I play the animations, I have one action one of the cactus and one on the other. They are joined together for some reason (like parent and child) but I can’t seem to figure out how to separate them unless I just totally delete the entire thing and start over with the cactus. I probably should have just done that instead of trying to fix this cactus.

What do you mean by actions? I can see only one event in your cactus animation.

As it seems you have a SpriteRenderer on the parent and on the Body. The animation animates the Body. What is the purpose of the parent SpriteRenderer?

By the way, the children seem to have a huge offset. First of all, set the two buttons next to the tool buttons to Pivot and Global. Then select the children of the Cactus game object and move them closer to the parent. The position values in the Inspector are relative to the parent meaning that (0, 0, 0) would be the World Space position of the parent. Values higher than 1 or lower than -1 are “wrong”.

As this has been 24 days since a reply it will now close in 7 days,
Please create a new topic or ask for this to be unlocked if it closes before a response is posted.

Thanks

This topic was automatically closed after 6 days. New replies are no longer allowed.

Privacy & Terms