动态创建的脚本, 无法立即通过getComponent获得到

插件问题


目前遇到的问题是 使用插件第一次动态生成的脚本, 没法在插件中 立即通过getComponent获得到!

求助各位大佬QAQ

尝试了触发creator编译后 在使用getComponent, 但是没用

// axios.get(“http://localhost:7456/update-db”).then(function (res: any) {
// 在这里使用getComponent, 还是取不到
// });

创建脚本后场景会刷新此时修改没保存的东西都丢失,这是我的做法

		// 定时检测creator加载新建文件缓存没有
		let stop_func;
		let chk_count = 0;
		stop_func = setTimeout(() => 
		{
			//等场景加载完脚本
			let node = cc.engine.getInstanceById(node_uuid)
			if (node && !node._objFlags) 
			{
				let comp = node.getComponent(args.bindInfos[0].comp_name)
				if(!comp) return;

				let is_up_scene = comp.uuid != old_comp_uuid;
				// *:组件uuid改变了说明场景已经刷新了一遍, comp.uuid != old_comp_uuid 
				// 创建脚本瞬间添加的node组件会丢失,所以需要检测1次组件确定加载了
				chk_count++;// 兼容2.4与1.9版本
				if (is_up_scene || chk_count == 1)
				{
					if(is_up_scene){
						stop_func();
					}