Jump to content
Phodex Games

Handling Function Call Order

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

Share this post


Link to post

And you can't call the Load function after the scene is initialized? Where is the Load function coming from?

one option you can do: when the load function is called, check if the entity has been inited or call the init function yourself.

Share this post


Link to post

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.

Share this post


Link to post

Well you could use a bool to see if the init has been run 

or

the Load function calls the Init/start function.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...