Strange behavior of the game

Hello everyone,
I’ve paused the course during few wekks and everything work fine but when I have restarted the course, i’ve notice some strange behavior when i pressed play button.
The first one is that my first unit isn’t selected at the start of the game.
If I selected it, my actions button appear and work fine.
The same if i selected the second unit, coming back again to the first.
The heaven on earth :slight_smile:
But when I stop the play mod and restart it to test again, my first unit isn’t always selected but my actions button don’t appear too…
I can only move and switch between the two units…
I’ve noticed the selected cirlce has desapeared too…
there is only the distance quad leave…
I’ve some error message according null reference exception.
I know it happens when you forget to put a gameObject or other thing in a field but after checking I don’t notice any missing…
So I’ve decide to tweak a little bit the code code to work by elimination and only changed the name of the UpdateSelectedVisual method.
When I rename it “UpdatedSelectedVisual” (i’ve only had a “d” after update), changing at the 3 others lines where it called the method, Ig I save, Unit restart the compilation and when I launch the game,
my first unit isn’t selected, but when I click on it, my action button appear again and “everything” work normally, even if I switch unit.
And if I stop the game and relaunch it, the same problem appear again.
No unit selected by default and no action button…
It looks like if something override something other…
I must say that I’m a little bit lost…
If but my actual project in my google drive, in zip, here:
https://drive.google.com/drive/folders/1LsQ3aV-etlm-VRnY_t8uuozo3hbVBAtQ?usp=sharing

I’ve spend many hour too check code coming back in the course but nothing looks bad.
I haven’t error message in visual studio…
Only missing reference in unity…
Excuse me for the boring but here, I need help if I want to continue…
Thanks a lot, have a good day.
François

Hi François,
I downloaded your project, and ran it, which gave me a chance to look at the error messages. (For future issues, generally if you copy the text of the Error message and paste in the relevant code, we’ll often be able to diagnose the issue).

The first error message I encountered was

NullReferenceException: Object reference not set to an instance of an object
UnitActionSystemUI.CreateUnitActionButtons () (at Assets/Scripts/UnitActionSystemUI.cs:29)
UnitActionSystemUI.Start () (at Assets/Scripts/UnitActionSystemUI.cs:18)

This leads to line 18 of UnitActionSystemUI line 18

 actionButtonUIList.Clear();//On vide la liste des boutons de l'UI pour l'adapter apr�s � celles de l'unit� s�lectionn�e.

This lead me to look at the declaration for actionButtonUIList, which read

    private List<ActionButtonUI> actionButtonUIList; 

The issue with this null reference is that the actionButtonUIList is never actually created, only declared as a variable.
Change this line to

    private List<ActionButtonUI> actionButtonUIList = new List<ActionButtonUI>();

The other error involves not getting the selectedAction… I spent quite a bit of time trying to trace this out with Debugs, and despite the fact that there is a unit selected, and that unit has already cached the Move Action… the selectedAction in Unit simply remains null until the unit is selected by the mouse, and I could not figure out why…
Then I clicked on the Unit entry in the UnitActionSystem, and it linked to the prefab in the assets folder, not the Unit in the scene. Linking to the Unit in the scene instead of the Action System resolved the error.

1 Like

Hello Tom.
Thanks a lot for your quick and efficient reply.
It was that.
It fixes the button bug.
No the correct button list appears when I select the unit.
For the other one, the default unit selected…
Good luck ? :slight_smile:
Have a good sunday.
Schuuss
François

Did you assign the SelectedUnit field reference on the UnitActionSystem? Select the object with the script and look in the inspector, the unit you reference there should be the default one

Ooooohhh… It was that.
I had an unit in the UnitActionSystem’s field but it was the prefabs one…
not the unit in the scene.
By replacing by the unit in the scene everything work fine.
Thank you and sorry for the borrying.
Don’t know what happened. Probably a ghost in the shell :wink:
Have a nice sunday.
Take care.
François

Privacy & Terms