CC 3.0 - Property Issue

Hello all,

I have a strange error when trying to do a thing like this:

@property({ type: Graphics })
public targeting: Graphics = new Graphics();
// OR
@property({ type: Node})
public targeting: Node= new Node();

After dragging a node or a node containing graphics component I am getting the following issue on runtime:

You are explicitly specifying `undefined` type to cc property "target" of cc class "cc.TargetOverrideInfo".
Is this intended? If not, this may indicate a circular reference.
For example:

 
// foo.ts
import { _decorator } from 'cc';
import { Bar } from './bar';  // Given that './bar' also reference 'foo.ts'.
                              // When importing './bar', execution of './bar' is hung on to wait execution of 'foo.ts',
                              // the `Bar` imported here is `undefined` until './bar' finish its execution.
                              // It leads to that
@_decorator.ccclass           //  ↓
export class Foo {            //  ↓
    @_decorator.type(Bar)     //  → is equivalent to `@_decorator.type(undefined)`
    public bar: Bar;          // To eliminate this error, either:
                              // - Refactor your module structure(recommended), or
                              // - specify the type as cc class name: `@_decorator.type('Bar'/* or any name you specified for `Bar` */)`
}

On Cocos Creator 2.X.X it worked just fine. What am I doing wrong here?

So I changed the code like this but no luck:

@property({ type: Graphics })
public targeting: Graphics;
// OR
@property({ type: Node})
public targeting: Node;
// Even tried this one:
@property
public targeting: Graphics;
// OR
@property
public targeting: Node;

Same error different place… Please help me here…

Can you send the whole file ? The problem could be related to other parts of your code

@pandamicro Here is the project…

https://drive.google.com/drive/folders/1FAN1VMkYCsrMbLVkPcSgtCgeIaMwUW5e?usp=sharing

Folder is open for so basically you can see everything…

Now I review the message you sent, it was reporting a warning in our engine

You are explicitly specifying undefined type to cc property “target” of cc class “cc.TargetOverrideInfo”.

But when I run your game, it’s only reporting

You are explicitly specifying undefined type to cc property “debugging” of cc class “Player”.

It’s normal because you haven’t give type declaration to @property()

@property()
public debugging: boolean = false;

For primitive types, just use @property is enough

@property
public debugging: boolean = false;

After I fix it, there is no more issue

1 Like

Thanks… It works. I still see the warning while playing the game (real time) but it works fine.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.