It comes from the line of code

-If I play the level once, everything works fine.

-If I restart the level multiple times but do NOT change the scene, everything works fine.

-If I change scene back and forth but do NOT restart the level, everything works fine.

-ONLY IF I change scenes AND THEN try to restart the level do I get "attempt to index local ‘bounds’ (a nil value)

 

It comes from the line of code that tries to call the function to get the bounds of the enemy box.

 

So without posting hundreds of lines of code… is there something I can try to figure out what is going on? 

 

The object itself that I am passing to the function is not nil, it seems that only the contentBounds table is nil. 

 

But what I do not understand is why does this only happen in the one situation mentioned above?  

 

Is there something regarding contentBounds and switching composer scenes that I need to be aware of?

 

When I switch scenes I am composer.removeScene  on the level scene to make sure things get recreated properly when I go back to the scene.  Like I said, this works fine as long as I don’t try to restart the level after changing scenes. 

I fear this is too obscure to help with.  Can you shrink the project into a smaller form to demonstrate to the rest of us?  Sometimes doing this exercise reveals the error.

Also maybe you explain the problem more concisely.  I would like to help but I not quite sure what problem you are having or what exactly is failing.

As @sporkfin already said, you haven’t shared enough. In order to debug something, it’d be useful to see some code. This sounds to me like the object falls out of scope as you move between scenes, but I can’t know for certain.

I agree it sounds like a scope problem. My guess is: 

You have an object which is a global variable (whether intentionally or not). 

When you leave the scene the display object is removed as it is in a scene group which is removed, but the variable is not set to nil.

This means that this condition would be true:  

if myObject ~= nil then

but the object won’t contain any of the display.* properties so checking for myObject.width would return nil.