Jump to content

Recommended Posts

Posted

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

Posted

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.

 

post-7852-0-79987000-1389435004.png

Posted

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.

Posted

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
Posted

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.

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.

×
×
  • Create New...