请教一个创建预制节点的问题

按照文档(https://docs.cocos.com/creator3d/manual/zh/scripting/create-destroy.html)的代码,代码如下:

import { _decorator, Component, Prefab, instantiate, director } from "cc";
const { ccclass, property } = _decorator;

@ccclass("test")
export class test extends Component {

    @property({type:Prefab})
    private target: Prefab = null;

    start(){
        let scene = director.getScene();
        let node = instantiate(this.target);

        node.parent = scene;
        node.setPosition(0,0,0);
    }
}

运行时出现了错误,提示为:

Uncaught TypeError: Cannot set property 'parent' of null

请问为什么?

你这个Prefab没有指定一个Prefab上去?

已经放了,以下是截图

你把工程发上来看一下~

我刚刚实验出来了,原来是因为我把这个类重新new了一下,导致失去target导致的。