Issue with the grid objects

I have an issue when I start my game, every unit, other than the first one, has an extra unit text added to their grid starting position. When I move said units everything acts as it should other than their grid’s starting position keeps that added text. Let me show you through screenshots I took :


Sounds like you’re adding the Unit to the grid twice, so when it moves it only removes one instance and leaves the other one behind.
Maybe you added multiple Unit components to those prefabs? Or multiple Action components?
Add some Debug.Log(this); on Start to see how often that code is running, and add some Debug.Log on the Add and Remove functions.
You should see 3 adds on the start, then 1 remove and 1 add whenever a unit moves 1 grid position.

Thanks for the fast reply. I did some more testing and it is only happening when the unit is not on the grid position (0,0). I also added a Debug.Log to the UnitMove function and if the unit does not start on grid position (0,0) it has moved thus being deleted and added to it’s grid position. I’m not sure if this is suppose to happen. So I’m having some issues trying to find the problem. I took another screenshot with the units not being on (0,0) and the console which writes out the that all the units have moved on the start of the game.

Disable all the other units so you have just one, easier to test that way.
When are you adding the Unit to the grid? You should be calculating the Grid Position based on the Transform position, add a Debug.Log to see if that calculation is working correctly. If you place Unit on world position 2, 0 you should see GridPosition 1, 0 and it should add the unit just once to that position.

Thanks a lot, I found my mistake I was accidentally declaring two grid positions so it was calculating it twice. My bad.

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

Privacy & Terms