Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
0
Members

Namespaced Behaviors

A topic by An-Gremlin created Feb 12, 2016 Views: 364 Replies: 3
Viewing posts 1 to 4

As part of the work towards turning my game code into a reusable plug-in, I went through and stuck all of the relevant code into a namespace, but now even though I still register them to Superpowers none of the behaviors from the namespaced code appear in editors, even if I move the registration out of the namespace. For example:

class SimplePhraseBehavior extends Sup.Behavior {
...
}
Sup.registerBehavior(SimplePhraseBehavior);

Works just fine but:

namespace TomE {
export class SimplePhraseBehavior extends Sup.Behavior {
...
}
Sup.registerBehavior(SimplePhraseBehavior); //with either this....
}
Sup.registerBehavior(TomE.SimplePhraseBehavior); // OR this

Compiles but causes the behavior to be unavailable/marked "missing" in the editor

(1 edit)

Oh I forgot the most important part: the behaviors still WORK, as long as I don't touch the ones it thinks are "missing" they'll continue to function if you build and run the game, they just don't appear in the behavior list. I'm looking through the scene editor and behavior component code seeing if I can figure this out but I don't see anything yet...

Moderator (1 edit)

The Sup.registerBehavior is a function mandatory at runtime to let the engine know which behaviors are available.

The process to show available behaviors in the scene editor is different. It's done here on the server when applying changes to a script.
https://github.com/superpowers/superpowers-game/bl...
And yeah, we don't handle behaviors nested in namespace.

It also explains why it works if you move it to the namespace after setting it.

Hmm, well that raises yet more concerns - it really seems like if that's how the editor registers behaviors then it would be impossible to package common behaviors into a plugin at ALL, let alone safely in a namespace.