[Solved] "Cannot Add Listener Function To Null Actor" How to avoid this?

homeofdeath212

  • Posts: 122
I know why this occurs and I'm trying to find ways to circumvent it.

From the code attached, I have a "Shield" Actor that spawns much later in the game but the "Collision" blocks are initiated as soon as the scene loads in. Of course, Stencyl wouldn't recognize the "Shield" Actor attribute because the actor isn't in the game yet.

How can I "avoid" this if possible? It would be nice if I could get to keep this behavior to control the collision mechanics of the shield actor rather than making a new behavior in it.

« Last Edit: April 21, 2019, 04:28:27 pm by homeofdeath212 »
Currently Working On: Galaxiconia (A space shooter/defence game)
https://www.newgrounds.com/dump/item/2af922bd9a873856b9b2274737f80bc5

colburt187

  • *
  • Posts: 2389
Yeah I have also had this issue in the past. I don't think the error causes any problems though. But it would be interesting to hear if anyone has a good solution.

LIBERADO

  • *
  • Posts: 2658
You'd need to attach the collision event directly to the shield actor.
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

homeofdeath212

  • Posts: 122
Yeah I have also had this issue in the past. I don't think the error causes any problems though. But it would be interesting to hear if anyone has a good solution.

It doesn't cause the game to crash(I saw this error from the logs) but the collisions won't work

You'd need to attach the collision event directly to the shield actor.

Seems like there's no other way then.

Anyway, does creating multiple actor types using the same visuals still increase the size of the game file?
I tried doing this method to save space(and convenience) but I guess that's not possible
Currently Working On: Galaxiconia (A space shooter/defence game)
https://www.newgrounds.com/dump/item/2af922bd9a873856b9b2274737f80bc5

JeffreyDriver

  • Posts: 2100
Anyway, does creating multiple actor types using the same visuals still increase the size of the game file?
I tried doing this method to save space(and convenience) but I guess that's not possible

Do you mean creating actors in the dashboard? I believe so as each actor would have its assets stored separately.

Have you not thought about using images instead of actors for the shield?

Then just use a boolean attached to your actor that checks if the shield is active, and code to check how close a projectile is rather than use collisions.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

LIBERADO

  • *
  • Posts: 2658
@homeofdeath212, you could do it this way:
   
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

homeofdeath212

  • Posts: 122

Do you mean creating actors in the dashboard? I believe so as each actor would have its assets stored separately.

Have you not thought about using images instead of actors for the shield?

Then just use a boolean attached to your actor that checks if the shield is active, and code to check how close a projectile is rather than use collisions.


It seems like I guessed right then. Good thing I got the shield behavior working or else I might've need to bloat the game.

For images... I didn't as I needed the shield to collide with the player too(but not damage) and make the shield look like a physical object. If I made into an image, it might be hard to code in the collisions needed to achieve that. Not to mention the shield also has animations which I haven't learned how to do that with images.

@homeofdeath212, you could do it this way:
   


I forgot that existed. This did exactly what I wanted. Thanks, Liberado.
Currently Working On: Galaxiconia (A space shooter/defence game)
https://www.newgrounds.com/dump/item/2af922bd9a873856b9b2274737f80bc5