Jump to content

Loading prefab Error


nate066
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

  • Upvote 1
Link to comment
Share on other sites

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.

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...