预制体自己的位置全是零

main.js

extends: cc.Component,

properties: {
    ccfpb: {
        type: cc.Prefab,
        default: null
    },


},

onLoad: function () {


    for (let i = 0; i < 3; ++i) {
        let mster = cc.instantiate(this.ccfpb);
        
        this.node.addChild(mster);
            mster.setPosition(ccv2pos);
        cc.log(ccv2pos);
    }



},

prefab.js

onLoad: function () {
let posx = this.node;
cc.log(posx);
cc.log(posx.x);

},

想要预制体自己能输出自己的位置,cc.log(posx);能有节点信息,
cc.log(posx.x);的是0,或者其他的同一个值,怎么刷新都不变,怎么办

let ccv2pos =this.poszition();

poszition: function () {
let zzx = Math.random() * 480;
let zzy = Math.random() * 320;
return cc.v2(zzx, zzy)

},

漏掉的代码

onLoad: function () {


    for (let i = 0; i < 3; ++i) {
        let mster = cc.instantiate(this.ccfpb);
        let ccv2pos =this.poszition();
        this.node.addChild(mster);
            mster.setPosition(ccv2pos);
        cc.log(ccv2pos);
    }



},
poszition: function () {
    let zzx = Math.random() * 480;
    let zzy = Math.random() * 320;
    return cc.v2(zzx, zzy)

},

你的代码看的真有点费劲,position打错了强迫症表示很难受~~~~~~你是不是先addchild后然后设置位置的?这个节点的onLoad不就先于设置位置执行了么?打印出来肯定是固定值~~你把mster.setPosition()那句放到addChild前面一行

谢谢,真的是这样的