Jump to content

Handling Function Call Order


Phodex Games
 Share

Recommended Posts

Hi,

I pretty often encounter the followning problem: I need something to be called before, or after the Start function of an script.

My actual problem is that I have an NPC and his "Load" function (I wrote by myself) is called before the script actually is initiated. The problem is, in the load function some values are set (like npc health) but then the script gets initiated and the script uses the default script value of 100% health and the loading does not work. A workaround I found is to use the first step of the update function but I find this not very smart. Here an example:

function Script:UpdateWorld()
	if self.doOnce ~= true then 
    	--do something here
    	self.doOnce = true
    end
end

Any ideas how to solve this more elegant? Would be really glad if we could gather some ideas :)

Markus

Link to comment
Share on other sites

Hi Jorn, how to check if the entity is initiated?

In my case the player gets spawned and then the player "spawns" another entity which then gets loaded by the players loadfunction. By the way the object the player spawns is an prefab. However I worked around the problem by changing the whole spawning process. However the problem still remains. I often have trouble with prefabs the Start function and script variables. Just wanted to gather some experiences etc.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...