To me, single-tone component A and
There is a generic component B that uses an instance of A.
Attach A and B components to different game objects.
If you try to put B in A’s Property,
The inspector is null and not working properly.
What should I do?
example)
import B from '...';
class A extends cc.Component{
private static instance : A = null;
public static get Instance() : A {
return this.instance;
}
@property(B)
public b : B = null;
public helloWorld() {
console.log("Hello World");
}
}
import A from '...';
class B extends cc.Component {
onLoad() {
A.Instance.helloWorld();
}
}
If you’re using a custom class that isn’t a component as your property, you need to tell Cocos Creator how to serialize it. You should use @ccclass('MyClassName') to define the serialized name for the class.
Also, yeah there’s issue with cyclic imports which is probably what you’re referring to here. A imports B and B imports A, and that doesn’t work so well in Cocos Creator. @slackmoehrle Is this issue fixed in 2.4.1?
Yes, it seems to be fixed in 2.4.1. Just tried it. It was quite a pain honestly to import inline as a workaround. (using import inside the code and not at the top)