seronis Posted November 13, 2013 Share Posted November 13, 2013 Im playing around with diff color campfire using "AddPrefabPostInit("firepit", doTweak)" and in my handler I am replacing the default FX with my custom prefab using: inst.components.burnable.fxdata=nil inst.components.burnable.fxdata={} inst.components.burnable:AddBurnFX("darkfire_flame", vec )When I add fuel to an extinguished campfire my effect was showing up perfectly but I noticed when i saved, exited and reloaded the world the fire was using the default FX until it extinguished, at which point it would again be using mine. Shouldnt all AddPrefabPostInit() handlers be called during world load BEFORE savefile information is loaded on components? I would expect this to be the case because a mod can override many features of vanilla components and expect that behavior to be preserved when the world is reloaded. Link to comment Share on other sites More sharing options...
simplex Posted November 13, 2013 Share Posted November 13, 2013 Use a zero-delay callback, as @squeek suggested in his thread. The issue here is that OnLoad methods run after a prefab post init, possibly overriding changes they make. Link to comment Share on other sites More sharing options...
seronis Posted November 13, 2013 Author Share Posted November 13, 2013 My problem is onload seems to be processing BEFORE i've had a chance to replace the FX. Because its loading the original campfirefire fx prefab and not my darkfire_flame fx prefab. I would prefer onload to process after my postinit -edit- https://dl.dropboxusercontent.com/u/13440285/coding%20zips/campfire_test.tar.gz Have to take nephew to bowling league practice but will be back in a few hours to try to see what im overlooking. Dropbox link is incase anyone is curious Link to comment Share on other sites More sharing options...
Malacath Posted November 13, 2013 Share Posted November 13, 2013 My problem is onload seems to be processing BEFORE i've had a chance to replace the FX. Because its loading the original campfirefire fx prefab and not my darkfire_flame fx prefab. I would prefer onload to process after my postinit No you wouldn't, if the OnLoad would run after the PostInit then it would override your new fx, like it currently does. So simplex's suggestion should fix it since the last thing written in the burnfx will be the one used not the first. Link to comment Share on other sites More sharing options...
seronis Posted November 13, 2013 Author Share Posted November 13, 2013 I only have -one- thing written in the fx though. I set the default list to nil to delete it before adding my own. So if onLoad calls after my postInit it should only be able to use my fx prefab. The other wouldnt exist. So it seems onLoad is getting called before my postInit is called as a fire already exists Link to comment Share on other sites More sharing options...
Malacath Posted November 13, 2013 Share Posted November 13, 2013 I only have -one- thing written in the fx though. I set the default list to nil to delete it before adding my own. So if onLoad calls after my postInit it should only be able to use my fx prefab. The other wouldnt exist. So it seems onLoad is getting called before my postInit is called as a fire already existsDeleting the current list of fx doesn't prevent any other script to override your new fx.I might be mistaken so I'm gonna download your mod and see for myself. Link to comment Share on other sites More sharing options...
simplex Posted November 13, 2013 Share Posted November 13, 2013 @seronisI took a closer look at it, and the issue is not with OnLoad functions, but with the prefab constructor (the fn()) for the firepit calling inst.components.fueled:InitializeFuelLevel(), which spawns the default fx prefab before the post init runs. This modified version of doTweak does what you want:function doTweak(inst) -- Kill the current FX, if any. inst.components.burnable:KillFX() inst.components.burnable.fxdata={} inst.components.burnable:AddBurnFX("darkfire_flame", GLOBAL.Vector3(0,0.4,0) ) inst:DoTaskInTime(0, function(inst) if inst.components.burnable and inst.components.burnable:IsBurning() then -- Kill any additional FX spawned from then, if any. inst.components.burnable:KillFX() -- And now spawn our custom one. inst.components.burnable:SpawnFX(true) end end)endobs.: I also erased your overriding of the section callback, since you were overriding it with a function identical to the vanilla one, not to mention there's no need to touch that to achieve your intended effect. Link to comment Share on other sites More sharing options...
seronis Posted November 13, 2013 Author Share Posted November 13, 2013 I had other stuff in my section callback originally it just wasnt relevant to this. I try to do "minimum test case" for issues. And now I feel silly at overlooking the (now obvious) cause of the problem. The onLoad() method does trigger the section callback to adjust fx level so i was initially assuming it might still be relevant to have my own version there. Thanks for the help guys =-) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.