Phodex Games Posted July 3, 2017 Share Posted July 3, 2017 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 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted July 3, 2017 Share Posted July 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
Phodex Games Posted July 4, 2017 Author Share Posted July 4, 2017 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. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted July 4, 2017 Share Posted July 4, 2017 Well you could use a bool to see if the init has been run or the Load function calls the Init/start function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.