- Home /
Ensuring Correct Call Order
Currently I am working on an RTS styled management game and am having some issues arising from unity's call order for it's built in methods.
Instead of putting actual source code as it would be too much and make the question unspecific I will outline the problem.
I am using a creation controller class that upon pressing a button, based in the GUI function of that class, will allow you to place a house. As soon as this button is pressed it will change a bool called placing from false to true. Then the house prefab will be instantiated, as it was passed into the script via the editor, and then this script will move onto the update function allowing mouse based placement.
Upon pressing the right mouse button, everything will be placed and freed up, the instance object will be added to a list of placed objects and then the house will be allowed to be clicked on by changing an internal bool for the house to true and setting the placing bool to false.
Then upon clicking the house, given that you aren't placing anything and the house can be clicked on, a menu will pop up from the house's GUI function.
The issue arises because OnGUI() is called after Update(), since I am changing the bool values in the Update function of the creation controller to ensure that everything is being read from the list I have created. Upon placing the object the menu will pop up immediately since the mouse is over it already.
While the bool values are supposed to change this, and I am checking them in the OnGUI function for the house, it does not seem to matter as the call order for OnGUI is stacked after Update so the bools have already changed.
My objective to to ensure that this does not happen, instead I want the menu to only be allowed to be opened after the initial mouse click.
Any suggestions on how I may achieve this?
Currently my work around is to tie the placement to the left mouse button, and the house clicking to right mouse button. Still interested to see if this can be more elegant for the user.