Having trouble with trophy spawning and resources not being deducted

Please help, no one has responded to me on Discord and I just want to be pointed in the right direction.

I’ve had issues since video 144 and now i’m stuck and can’t find the answers that will work for me.
Problem 1: I managed to get trophy to spawn but it’s erratic and and not snapping to grid as well as it won’t spawn in the top 2 lanes.
Problem 2: My stars isn’t being spent as they are supposed to and I have no errors anywhere to tell me where the problem might be.

My scripts are identical to Rick’s and I checked for any typos that I might have made but I can’t find anything. Please can someone help me through this process?

Hi Carmen,

  1. Check the animation of the trophy. Maybe its position property is animated. If that’s the case, remove that property from the property list in the animation.

  2. Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? If so, add a few Debug.Logs to your code to figure out what exactly is going on during runtime. Try to verfiy or falsify all your assumptions.


See also:

Hi Nina

I ran some debug logs but I’m still not picking up issues but after playing around with the trophy’s animation properties, this error came up:
I wanted to copy the screen shot but now my trophy isn’t spawning at all again.

Defender newDefender = Instantiate(defender, roundedPos, Quaternion.identity) as Defender;

It said something like the animation object i want to instantiate is null which took me to that coding section but now I did something and the trophy isn’t spawning

this is just to have a look at how it is now:

Your animation window looks fine.

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty. Ideally, your buttons should reference a prefab in your Assets folder, not a game object in your Hierarchy.

I fixed the spawn issue…again…the buttons keep kicking out the prefab trophy for some reason but it’s staying put for now. Here’s a video clip of what it’s doing. The debugger is correctly displaying where my mouse is clicking but as you can see the trophy is like waaaaay over the other side. Ah, i don’t know how to upload the video so i’ll try and do a screenshot.

my mouse was clicked on the lane above and to the right of the lizard and that’s where my trophy decided to spawn

You could upload the video to Youtube and share a link here.

Do the following. Playe a trophy in your scene and set its transform to a potential spawn position, e.g. (1, 1, 0). If the trophy is placed correctly, go to its animation and adjust the values of the child positions in the keyframes. If it takes you longer to edit the values than to redo the animation, redo the animation.

okay here’s the link for the video: https://youtu.be/zbgAmtorMkg

i’m going to try that right now.

i feel like i’m getting close to the problem, it’s something to do with my gameobject i think:

That circle is where my mouse is when i drag the trophy over to the scene so i’m starting to think it’s the gameobject. i’ve already deleted this once completely and redid the animation and it still wouldn’t work so if i do it again i might fix that small issue though. i’m not sure

Place the trophy at (1, 1, 0). At the moment, it’s at (6.15, 4.4, 0).

image

Then check the position of “Bottom”. The position values in its Inspector are relative to the parent. For this reason, it is crucial that the parent position is at a potential target position like (1, 1, 0). Only when the parent position is correct, you will be able to adjust the position of the child game objects correctly without doing the maths.

Hi Nina

I made the position as you advised and i redid the animation and the whole work from scratch and now everything works. It’s snapping to grid exactly where the mouse is clicking.
Now I need to work on my next problem which is that the stars are not deducting. Thank you so much for your patience!

You’re welcome. I’m glad you solved the problem. :slight_smile:

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

Privacy & Terms