Issue with myBuilding List (shows up in Building Limits)

Hello,

Edit Edit
:man_facepalming: Found the issue.

This was my Code. Hooking up the spawn and despawn behavior when the building spawned. Never hooking up the Despawn behaviour.
Building.ServerOnBuildingSpawned += ServerHandleBuildingSpawned;
Building.ServerOnBuildingSpawned += ServerHandleBuildingDespawned;

Changed the 2nd line to the correct one
Building.ServerOnBuildingSpawned += ServerHandleBuildingSpawned;
Building.ServerOnBuildingDespawned += ServerHandleBuildingDespawned;

Two hours this was. Two. :man_facepalming:

It is solved now though!

EDIT I decided to check if the Server was spawning and then despawning the building in the same frame. For some reason it is. The building will be added to the list in the HandleOnBuildingSpawn and then HandleOnBuildingDespawn is immediately triggered. I am going to check and see if I can figure out why it is happening in the same frame. Maybe I don’t have any health on my UnitBase? It is worth noting the UnitBase gameObject is not being destroyed.

I am pretty stumped on this. When the server goes to make a building it doesn’t add it to the myBuildings list on the server. I think this is strictly on the server as when the client connects they have a buliding in their list but the server still sees no buildings in either connections list.

I have debug statements on the server command to add the building to the list and the debug commands fire all the way to the myBuildings.Add(building) function call. However, nothing goes onto the list.

If I host a game I can drag and drop the unitBase from the editor into the players myBuildings list (manually adding it). And all of the other logic appears to work. If I add a call of myBuildings.Add(…) at the end of the CmdTryPlaceBuilding(…) function then everything works as expected. I imagine because this is bypassing the ServerHandleBuildingSpawned call which should be adding to the list but for some reason does not.

Like i said, I am stumped as logic runs on the ServerHandleBuildingSpawned all the way up to (and after) adding to the list. just for some reason it is not added.

Also, I can circumvent this by adding it to the try place building to keep going with the lectures but I know this isn’t how it is supposed to function. Any advice would be appreciated

Hey there, glad you figured this out!
You are not the first person to copy and paste those event subscriptions and have this issue. I did it myself the first time I ran through the course. Many students have done it, so you are not alone!

Privacy & Terms