nate066 Posted January 11, 2014 Share Posted January 11, 2014 I made a prefab spawn script it just loads a prefab file however i get an error when i try to load my crawler prefab. The error is "c:/users/nathan/documents/leadwerks/projects/..." : 288 : attempt to index field 'animationmanager' (a nil value) when i add the prefab manually in the editor it works fine. when ran in debug mode the program crashes with the same error. In a diffrent scene it takes 5 secs then the error occurs but the debug error is assert fail. It looks as if it cant find the AnimationManager. Any Ideas on how to fix this Quote Link to comment Share on other sites More sharing options...
SarperSoher Posted January 11, 2014 Share Posted January 11, 2014 Can you also paste the 288. line of the mentioned script? The error log does not show which script it is, AnimationManager.lua I guess? And also the code block where you load the prefab please. Quote Link to comment Share on other sites More sharing options...
nate066 Posted January 11, 2014 Author Share Posted January 11, 2014 function Script:Draw() if self.enabled==false then return end self.animationmanager:Update() --288 end Its in the monster ai scipt Quote Link to comment Share on other sites More sharing options...
SarperSoher Posted January 11, 2014 Share Posted January 11, 2014 Is the animationmanager field assigned in the editor for the selected prefab? I guess you are trying to access the attached animation manager with "self" but it cannot find it as it return nil Quote Link to comment Share on other sites More sharing options...
nate066 Posted January 11, 2014 Author Share Posted January 11, 2014 Is the animationmanager field assigned in the editor for the selected prefab? I guess you are trying to access the attached animation manager with "self" but it cannot find it as it return nil this is what looks like in the script window. Quote Link to comment Share on other sites More sharing options...
nate066 Posted January 11, 2014 Author Share Posted January 11, 2014 where do i attach the animationmanger in the editor. I just tried my prefab in a diffrent scene and it doesnt work, the crawler just stands there doesnt move or anything but when i kill it the death animation plays. Quote Link to comment Share on other sites More sharing options...
nate066 Posted January 11, 2014 Author Share Posted January 11, 2014 Heres the maps scripts and everything else. Hopfully it hopes to solve the problem. Quote Link to comment Share on other sites More sharing options...
SarperSoher Posted January 11, 2014 Share Posted January 11, 2014 Ok the problem it seems is loaded prefabs do not run their Start function. That is where your Animation Manager is created. And in Draw function, script tries to access it and update it. So as it's not created in the first place, it returns a nil reference exception. That also explains why the enemies you drop into the map work and the ones you load do not. The ones you drop invoke their Start functions and create their animation managers successfully. I just made it so that before updating the animation manager in the Draw function, the script makes sure that it's not nil. If it's nil, it just creates it once. I also implemented the time delay mechanism in the enemy generator so when you change the delay value in the editor, it will reflect in the behaviour of the generator. Make sure you use milliseconds for that value, 1000 for a second for example. Hope it helps! Entity Spawner.lua MonsterAI.lua 1 Quote Link to comment Share on other sites More sharing options...
nate066 Posted January 11, 2014 Author Share Posted January 11, 2014 Ok the problem it seems is loaded prefabs do not run their Start function. That is where your Animation Manager is created. And in Draw function, script tries to access it and update it. So as it's not created in the first place, it returns a nil reference exception. That also explains why the enemies you drop into the map work and the ones you load do not. The ones you drop invoke their Start functions and create their animation managers successfully. I just made it so that before updating the animation manager in the Draw function, the script makes sure that it's not nil. If it's nil, it just creates it once. I also implemented the time delay mechanism in the enemy generator so when you change the delay value in the editor, it will reflect in the behaviour of the generator. Make sure you use milliseconds for that value, 1000 for a second for example. Hope it helps! It definitely helps, thanks. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 11, 2014 Share Posted January 11, 2014 After you load your prefab in code just call it's Start() function. local prefab = Prefab:Load(path) prefab.script:Start() 1 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.