Giter VIP home page Giter VIP logo

puerts_unreal_demo's Introduction

unreal demo for puerts

怎么跑这demo?

  • git clone https://github.com/chexiongsheng/puerts_unreal_demo.git

  • ue4.25及以上版本,需要根据文档下载安装v8

  • 生成vs工程(window下,在mac下生成xcode工程),然后进入工程编译

  • 如果要打包运行,要到“项目设置/打包/Additional Not-Asset Directories to Package”,把Content下的“JavaScript”目录添加进去。

  • 如果打开基础ue类功能,可能会报找不到react-reconciler的错误,需要到Content/JavaScript下执行npm install .安装依赖的库。

Demo说明

  • 本demo目录是一个Typescript工程,可以用vscode(建议安装vscode,nodejs,typescript)打开这个目录。

  • TsGameInstance.cpp是程序逻辑的入口,里头关键语句是JsEnv->Start("QuickStart"),其执行了启动脚本QuickStart.js。

  • QuickStart.js是由TsProj下QuickStart.ts的编译结果,所以直接看QuickStart.ts即可,里头演示主要功能的用法。

  • 编译,在vscode上“Terminal -> Run Build Task”选tsc watch,修改代码后会自动编译。

  • PerfTest.ts编辑器下在老版本v8以及quickjs后端不可用

  • 若采用较新版本的vscode进行调试,发现无法命中断点,则尝试将本demo目录根目录下".vscode"目录中的"launch.json"中的"remoteRoot"配置项的"${workspaceRoot}"修改为"${workspaceFolder}",或者直接去除"remoteRoot"配置项。

  • UE版本如果>=5.3,ReactUMG插件不可用,需要修改puerts_unreal_demo.uproject禁用该plugin,否则会报编译错误。puerts_unreal_demo.uproject内的Plugins配置修改如下:

"Plugins": [
		{
			"Name": "Puerts",
			"Enabled": true
		},
		{
			"Name": "ReactUMG",
			"Enabled": false
		}
	]

puerts_unreal_demo's People

Contributors

chexiongsheng avatar fishorbear avatar primaryfantasty avatar zombieyang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

puerts_unreal_demo's Issues

[4.26] 蓝图生成的TsTestActor无法双击打开

问题出现在Constructor()中的console.warn("TsTestActor.Constructor this.Add", this.Add(33, 44));

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0x0000000000000000

UE4Editor_JsEnv!puerts::FFunctionTranslator::Call() [puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\Private\FunctionTranslator.cpp:108]
UE4Editor_JsEnv!puerts::FFunctionTranslator::Call() [puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\Private\FunctionTranslator.cpp:89]
UE4Editor_JsEnv!v8::internal::FunctionCallbackArguments::Call()
UE4Editor_JsEnv!v8::internal::CustomArguments<v8::FunctionCallbackInfo<v8::Value> >::GetReturnValue<v8::internal::Object>()

4.25.4, 4.26.2均无法双击直接打开

报错信息

Running D:/UnrealEngine/UE_4.25/Engine/Binaries/DotNET/UnrealBuildTool.exe  -projectfiles -project="D:/xxxxx/Documents/Unreal Projects/puerts_unreal_demo/puerts_unreal_demo.uproject" -game -rocket -progress -log="D:\xxxx\Documents\Unreal Projects\puerts_unreal_demo/Saved/Logs/UnrealVersionSelector-2021.04.22-09.15.11.log"
Discovering modules, targets and source code for project...
While compiling D:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Intermediate\Build\BuildRules\puerts_unreal_demoModuleRules.dll:
d:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\JsEnv.Build.cs(116,17) : warning CS0618: ??UnrealBuildTool.ModuleRules.PublicLibraryPaths???ѹ?ʱ:??For external libraries use the full path in PublicAdditionalLibraries, if its a system library then use PublicSystemLibraries/PublicSystemLibraryPaths??
d:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\JsEnv.Build.cs(118,17) : warning CS0618: ??UnrealBuildTool.ModuleRules.PublicLibraryPaths???ѹ?ʱ:??For external libraries use the full path in PublicAdditionalLibraries, if its a system library then use PublicSystemLibraries/PublicSystemLibraryPaths??
d:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\JsEnv.Build.cs(306,9) : warning CS0618: ??UnrealBuildTool.ModuleRules.Definitions???ѹ?ʱ:??The 'Definitions' property has been deprecated. Please use 'PublicDefinitions' instead.??
d:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\JsEnv.Build.cs(307,9) : warning CS0618: ??UnrealBuildTool.ModuleRules.Definitions???ѹ?ʱ:??The 'Definitions' property has been deprecated. Please use 'PublicDefinitions' instead.??
ERROR: Windows SDK must be installed in order to build this target.

unrealVersionSelector.log

WindowsPlatformFactory.RegisterBuildPlatforms: UnrealBuildTool.WindowsPlatformSDK using manually installed SDK
ProjectFileGenerator.GenerateProjectFiles: Discovering modules, targets and source code for project...
WindowsPlatform.FindVSInstallDirs: Found Visual Studio installation: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community (Product=Microsoft.VisualStudio.Product.Community, Version=16.8.30804.86, Sort=0)
WindowsPlatform.FindToolChainDirs: Found Visual Studio toolchain: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333 (Version=14.28.29335)
DynamicCompilation.RequiresCompilation: Compiling D:\UnrealEngine\UE_4.25\Engine\Intermediate\Build\BuildRules\UE4Rules.dll: Removed source file (D:\Build\++UE4\Sync\Engine\Source\Runtime\Advertising\Advertising\Advertising.Build.cs)
DynamicCompilation.RequiresCompilation: Compiling D:\UnrealEngine\UE_4.25\Engine\Intermediate\Build\BuildRules\UE4ProgramRules.dll: Removed source file (D:\Build\++UE4\Sync\Engine\Source\Programs\BenchmarkTool\BenchmarkTool.Build.cs)
DynamicCompilation.RequiresCompilation: Compiling D:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Intermediate\Build\BuildRules\puerts_unreal_demoModuleRules.dll: Assembly does not exist
DynamicCompilation.CompileAssembly: While compiling D:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Intermediate\Build\BuildRules\puerts_unreal_demoModuleRules.dll:
DynamicCompilation.CompileAssembly: d:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\JsEnv.Build.cs(116,17) : warning CS0618: “UnrealBuildTool.ModuleRules.PublicLibraryPaths”已过时:“For external libraries use the full path in PublicAdditionalLibraries, if its a system library then use PublicSystemLibraries/PublicSystemLibraryPaths”
DynamicCompilation.CompileAssembly: d:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\JsEnv.Build.cs(118,17) : warning CS0618: “UnrealBuildTool.ModuleRules.PublicLibraryPaths”已过时:“For external libraries use the full path in PublicAdditionalLibraries, if its a system library then use PublicSystemLibraries/PublicSystemLibraryPaths”
DynamicCompilation.CompileAssembly: d:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\JsEnv.Build.cs(306,9) : warning CS0618: “UnrealBuildTool.ModuleRules.Definitions”已过时:“The 'Definitions' property has been deprecated. Please use 'PublicDefinitions' instead.”
DynamicCompilation.CompileAssembly: d:\xxxxx\Documents\Unreal Projects\puerts_unreal_demo\Plugins\Puerts\Source\JsEnv\JsEnv.Build.cs(307,9) : warning CS0618: “UnrealBuildTool.ModuleRules.Definitions”已过时:“The 'Definitions' property has been deprecated. Please use 'PublicDefinitions' instead.”
WindowsPlatform.EnumerateSdkRootDirs: Found Windows 10 SDK root at C:\Program Files (x86)\Windows Kits\10 (1)
UnrealBuildTool.Main: ERROR: Windows SDK must be installed in order to build this target.
UnrealBuildTool.Main: BuildException: Windows SDK must be installed in order to build this target.
UnrealBuildTool.Main:    在 UnrealBuildTool.VCEnvironment.Create(WindowsCompiler Compiler, UnrealTargetPlatform Platform, WindowsArchitecture Architecture, String CompilerVersion, String WindowsSdkVersion, String SuppliedSdkDirectoryForVersion) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Platform\Windows\VCEnvironment.cs:行号 491
UnrealBuildTool.Main:    在 UnrealBuildTool.WindowsPlatform.CreateVCEnvironment(TargetRules Target) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Platform\Windows\UEBuildWindows.cs:行号 710
UnrealBuildTool.Main:    在 UnrealBuildTool.WindowsPlatform.ValidateTarget(TargetRules Target) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Platform\Windows\UEBuildWindows.cs:行号 792
UnrealBuildTool.Main:    在 UnrealBuildTool.RulesAssembly.CreateTargetRulesInstance(String TypeName, TargetInfo TargetInfo) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs:行号 568
UnrealBuildTool.Main:    在 UnrealBuildTool.RulesAssembly.CreateTargetRules(String TargetName, UnrealTargetPlatform Platform, UnrealTargetConfiguration Configuration, String Architecture, FileReference ProjectFile, CommandLineArguments Arguments) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs:行号 628
UnrealBuildTool.Main:    在 UnrealBuildTool.ProjectFileGenerator.AddProjectsForAllTargets(PlatformProjectGeneratorCollection PlatformProjectGenerators, List`1 AllGames, List`1 AllTargetFiles, String[] Arguments, ProjectFile& EngineProject, ProjectFile& EnterpriseProject, List`1& GameProjects, Dictionary`2& ProgramProjects) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:行号 2293
UnrealBuildTool.Main:    在 UnrealBuildTool.ProjectFileGenerator.GenerateProjectFiles(PlatformProjectGeneratorCollection PlatformProjectGenerators, String[] Arguments) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\ProjectFiles\ProjectFileGenerator.cs:行号 753
UnrealBuildTool.Main:    在 UnrealBuildTool.GenerateProjectFilesMode.Execute(CommandLineArguments Arguments) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Modes\GenerateProjectFilesMode.cs:行号 198
UnrealBuildTool.Main:    在 UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) 位置 D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:行号 550
Timeline.Print: Timeline:
Timeline.Print: 
Timeline.Print: [ 0.000]
Timeline.Print: [ 0.000](+0.026) <unknown>
Timeline.Print: [ 0.026](+0.081) XmlConfig.ReadConfigFiles()
Timeline.Print: [ 0.108](+0.000) SingleInstanceMutex.Acquire()
Timeline.Print: [ 0.108](+0.121) UEBuildPlatform.RegisterPlatforms()
Timeline.Print:   0.109          [ 0.000](+0.104) Initializing InstalledPlatformInfo
Timeline.Print:   0.213          [ 0.105](+0.000) Querying types
Timeline.Print:   0.214          [ 0.106](+0.001) XXXPlatformFactory
Timeline.Print:   0.216          [ 0.107](+0.000) MacPlatformFactory
Timeline.Print:   0.216          [ 0.107](+0.000) TVOSPlatformFactory
Timeline.Print:   0.216          [ 0.108](+0.000) AndroidPlatformFactory
Timeline.Print:   0.216          [ 0.108](+0.000) HoloLensPlatformFactory
Timeline.Print:   0.216          [ 0.108](+0.000) IOSPlatformFactory
Timeline.Print:   0.216          [ 0.108](+0.000) LinuxPlatformFactory
Timeline.Print:   0.216          [ 0.108](+0.000) LuminPlatformFactory
Timeline.Print:   0.216          [ 0.108](+0.013) WindowsPlatformFactory
Timeline.Print: [ 0.230](+6.469) <unknown>
Timeline.Print: [ 6.699](+0.003) Finding engine modules
Timeline.Print: [ 6.703](+0.003) Finding plugin modules
Timeline.Print: [ 6.706](+0.049) <unknown>
Timeline.Print: [ 6.755](+9.890) Compiling rules assembly (UE4Rules.dll)
Timeline.Print: [16.645](+0.020) <unknown>
Timeline.Print: [16.666](+0.000) Finding program modules
Timeline.Print: [16.667](+0.000) Finding program targets
Timeline.Print: [16.667](+0.028) <unknown>
Timeline.Print: [16.695](+0.189) Compiling rules assembly (UE4ProgramRules.dll)
Timeline.Print: [16.896](+0.166) Compiling rules assembly (puerts_unreal_demoModuleRules.dll)
Timeline.Print: [17.062](+0.097) <unknown>
Timeline.Print: [17.160](+0.000) FileMetadataPrefetch.Stop()
Timeline.Print: [17.162]

UI无法启动 版本(4.21 Win10)

最开始的错误

TGameJS: Error: (0x0000019DD8484698) E:\Example\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:59: Error: can not find [react-reconciler]
            let moduleInfo = loadModule(moduleName, requiringDir);

然后我

npm i react
npm i react-reconciler

然后的错误是:

TGameJS: Error: (0x0000019DFA913560) E:\Example\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:61: Error: can not find [components.js]
            let moduleInfo = loadModule(moduleName, requiringDir);
                             ^
Error: can not find [components.js]
    at require (E:\Example\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:61:30)
    at E:\Example\puerts_unreal_demo\Content\JavaScript\react-umg\index.js:5:18
    at E:\Example\puerts_unreal_demo\Content\JavaScript\react-umg\index.js:12:3
    at E:\Example\puerts_unreal_demo\Content\JavaScript\react-umg\index.js:12:134
    at executeModule (E:\Example\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:45:16)
    at require (E:\Example\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:79:21)
    at E:\Example\puerts_unreal_demo\Content\JavaScript\QuickStart.js:5:21
    at E:\Example\puerts_unreal_demo\Content\JavaScript\QuickStart.js:181:3
    at E:\Example\puerts_unreal_demo\Content\JavaScript\QuickStart.js:181:102

此时我npm i components.js
或者是创建components.js也是不行的,似乎得正确的提供这个文件

在开启PuertsSetting.Enable开关后,DebugEditor启动报错,且退出时存在崩溃。

环境

分支:master
IDE:Visual Studio 2019
启动配置:Debug Editor / Win64 / puerts_unreal_demo

DefaultPuerts.ini:

[/Script/Puerts.PuertsSetting]
Enable=True

问题描述

打开 Puerts Module Enable 开关,以 Debug Editor 启动后,日志中出现以下错误:

[2021.05.31-02.25.15:109][  0]Puerts: Error: (0x000002814CF2DC10) load module [TsTestGameInstance] exception C:\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:89: Error: can not find [react-reconciler]

Error: can not find [react-reconciler]
    at require (C:\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:89:30)
    at C:\puerts_unreal_demo\Content\JavaScript\react-umg\react-umg.js:3:20
    at executeModule (C:\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:66:9)
    at require (C:\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:118:17)
    at C:\puerts_unreal_demo\Content\JavaScript\react-umg\index.js:3:18
    at executeModule (C:\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:66:9)
    at require (C:\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:118:17)
    at C:\puerts_unreal_demo\Content\JavaScript\TsTestGameInstance.js:4:21
    at executeModule (C:\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:66:9)
    at require (C:\puerts_unreal_demo\Content\JavaScript\puerts\modular.js:118:17)

且退出调试时,在FJsEnvImpl::~FJsEnvImpl()函数释放 DelegateMap 处存在崩溃:

0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

在Generator目录运行 python main.py无法运行通过(附 报错信息)

PS E:\Work\puerts_unreal_demo\Plugins\Puerts\Generator> python main.py
('vcxproj_path ', '../../../Intermediate/ProjectFiles/puerts_unreal_demo.vcxproj')
('tree == ', <xml.etree.ElementTree.ElementTree object at 0x03DA6930>)
('root.tag ===', '{http://schemas.microsoft.com/developer/msbuild/2003}Project')
('namespaces ===', {'ns': 'http://schemas.microsoft.com/developer/msbuild/2003'})
Traceback (most recent call last):
File "main.py", line 278, in
main()
File "main.py", line 250, in main
ue_proj = UEProj(opts.project_path)
File "E:\Work\puerts_unreal_demo\Plugins\Puerts\Generator\ue_project.py", line 20, in init
include_search_paths = root.find('ns:PropertyGroup/ns:NMakeIncludeSearchPath', namespaces).text.replace('$(NMakeIncludeSearchPath)', NMakeIncludeSearchPath)
AttributeError: 'NoneType' object has no attribute 'text'

撤销C++类的Mixin后没有正常恢复原来的行为

定义一个MyActor类,在Tick中调用声明为BlueprintNativeEvent的TestUFun

// UFUNCTION(BlueprintNativeEvent)
// void TestUFun(double DeltaTime);

void AMyActor::TestUFun_Implementation(double DeltaTime)
{
	FRotator Rotator = GetActorRotation();
	SetActorRotation(FRotator(0, Rotator.Yaw + DeltaTime * 30, 0));
}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
	TestUFun(DeltaTime);
	Super::Tick(DeltaTime);
}

再创建一个蓝图类指定父类为刚刚的MyActor,添加一个StaticMesh组件网格体用自带的Cube。保存,然后拖拽蓝图到默认关卡里命名TestMyActor。
此时运行,可以看到TestMyActor在旋转。

编写一个TS脚本TS_Player,并将编译后的蓝图TS_Player拖拽到默认关卡里

import * as UE from 'ue'
import {$ref, $unref, $set, argv, on, toManualReleaseDelegate, releaseManualReleaseDelegate, blueprint} from 'puerts';

class TS_Player extends UE.Character {

    //StaticMesh: UE.StaticMeshComponent;
    
    Constructor() {
        // this.MixinCPPClass();
    }
    MixinCPPClass(): void {
        const MixinUE = blueprint.tojs<typeof UE.MyActor>(UE.MyActor.StaticClass());
        const MixinTestWithMixin = blueprint.mixin(MixinUE, ExtendMyActor);
    }
    
    UnMixinCPPClass(): void
    {
        const MixinUE = blueprint.tojs<typeof UE.MyActor>(UE.MyActor.StaticClass());
        const MixinTestWithMixin = blueprint.unmixin(MixinUE);
    }

interface ExtendMyActor extends UE.MyActor {}
class ExtendMyActor {
    ReceiveBeginPlay(): void {
        console.log("ExtendMyActor ReceiveBeginPlay");
    }

    TestUFun(delta : number):void {
        console.log("ExtendMyActor TS TestUFun");
        // this.CallFromTS();
    }
}

export default TS_Player;

可以看到这次执行之后之前的TestMyActor不再旋转了,而是不断的输出“ExtendMyActor TS TestUFun”Log。
然后停止运行后,注释掉TS_Player的Constructor调用MixinCPPClass,再次运行。依旧不转,而且也没有Log输出,断点后发现调用回了C++侧的TestUFun,但是参数和Tick的参数对不上,几乎为0。

试过在停止运行前主动调用UnMixinCPPClass还是有问题。

作者能分享几个wasm的C++代码吗

自己在测试C++ 转的wasm 和 JS 实现的接口的效率,但一直生成不了合格的wasm,普通C++的则OK。 特请教下作者,项目中和UE相关的几个wasm是怎么生成的呢,非常感谢车神的解惑!

vscode编译错误

  1. 在visual studio中编译debug editor,打开editor编译ue.d.ts
  2. 在vs code中打开项目然后build run task,出现如下编译错误
    image

【文档】一些建议或者意见

说说我的看法:

首先,对于PuerTS的**我非常认同,代码质量还没有来得及没有仔细看,仅仅从使用者的角度提一些意见。

  1. PuerTS的文档对于初次使用者非常的不友好,现有的文档里面并没有从使用者的角度基于几种典型的用例一步一步的引导;现有文档安装部分还行,但是使用手册只讲了一些功能性和实现方面的问题,完全没有从用户的角度,怎样从零开始使用PuerTS,就算有一些,也是零散的分布在文档和demo的说明中 - 从使用的易用性来讲,PuerTS相比UnLua还是有比较大的差距

  2. 比如使用C++代码创建JS虚拟机,是否是使用PuerTS唯一的方式?但是从 https://github.com/chexiongsheng/BlockBreakerStarter/ 这个示例看来其实可以不用手动创建虚拟机;然而,这个示例的说明也非常的晦涩,比如这个示例包括官方文档本身也没有说明,TypeScript目录下的TS_xxx.ts文件们和Content/Blueprints/TypeScript下的TS_xxx.uasset资源的对应方式 - 基于我自己的测试,这些资源应该是基于TS_xxx.ts文件自动生成的(我在本地删除了对应的BP - TS_xxx.uasset,重新打开编辑器,这些资源会自动生成);然而,这些生成的蓝图的EventGraph又是可以编辑的 - 而没有任何文档说明如果对生成的蓝图进行编辑会造成什么样的影响 - 以UnLua的思维模式,一个蓝图会显示的绑定到一个Lua脚本,Lua脚本里面可以override蓝图里面的方法(当然不能在蓝图生成新的变量等等,这个是PuerTS的黑魔法),而PuerTS里面生成的蓝图资源和原始的ts脚本并没有一个非常明确的对应关系 - 目前的感觉是生成的蓝图和原始的ts脚本是有对应关系的 - 是通过Content/Blueprints/TypeScript/TS_xxx.uasset这个路径来对应根目录下的TypeScript/TS_xxx.ts文件的吗(或者是Content/Javascript/TS_xxx.js对应的)?文档里面无从得知。我试验过将TS_Player.uasset蓝图里面的EventBeginPlay节点删掉,发现脚本里面相应的ReceiveBeginPlay的逻辑不会再被调用 - 但是,但是,既然这个蓝图是基于TS/JS脚本生成的,那么这个蓝图的逻辑就不应该被修改,否则任何人都可以开始修改这个蓝图,最终导致脚本和蓝图不同步 - 这个现在看来是一个比较大的问题。

该方案适合C++调用ts脚本,类似于UnLua里面的脚本覆盖蓝图方法来实现将逻辑无缝的切换到脚本使用 - 当然目前看来从ts脚本里面调用UE的方法这个方式是支持得比较完善的

  1. 上面的是使用用例之一(无论其本身的问题 - 如果有问题,那么文档也应该清晰的标明);然后就是我看到的实例里面的第二个用例:手动创建虚拟机,然后直接加载一个ts文件,执行里面的逻辑,主要在: https://github.com/chexiongsheng/puerts_unreal_demo 详细的就不多说了,在示例的说明里面,总是看得到“怎么跑这个demo”,然后blahblah的描述一番,好像我只要能跑这个demo就行了,但是根本没有描述,比如他的使用场景是什么,比如自己创建JsEnv并且加载一个脚本的使用场景是什么 - 就是文档有意无意的忽略了一些重要的细节,说了很多功能,但是有省略掉了很多 - 就好像一切都应该是不言自明的 - 不要忘记,作为PuerTS开发者,你的开发环境,上下文很多东西对于用户来讲都是不知道的 - 你一个demo扔出来,说明文档里面只有怎么跑是完全不够的 - 使用者根本没有你的上下文,很多东西是怎么来的根本不清楚 - 可以学习一下国外的软件是怎么写step by step guide的。

  2. 现在已经是UE5的时代了,而所有的示例还是基于UE4,虽然可以自己本地做一些修改,但是官方应该做一个UE5的分支,降低使用者的门槛

上面举的例子不是要作者来这里解答我的疑问,而重点是你的文档写得真的很不好 - 而实际使用体验也并没有非常丝滑 - 并不是你的文档或者说明里面描述得这么轻松(对,你的文档里面透露出一种举重若轻的轻松的感觉,觉得一切都很简单,你拿着跑就行了,其实实际情况不是这样的)

写了这么多,也是因为对puerts还是抱着期望的,希望作者能够采纳我的意见(我承认有点吐槽,因为使用下来的感受确实不太好),希望你们越做越好

Demo原生,无法用AnotherActor继承Blueprint

很奇怪,QuickTest里面可以成功用JS继承blueprint,但是如果用JS Blueprint来继承则返回错误

Puerts: Warning: (0x000002F2B58F7FD0) JS Execution Exception: E:\Unreal\xiuxian\client\puerts_unreal_demo\Content\JavaScript\puerts\uelazyload.js:23: Error: TestBlueprint_C is blueprint type, load it using puerts.blueprint.
Error: TestBlueprint_C is blueprint type, load it using puerts.blueprint.
    at Object.get (E:\Unreal\xiuxian\client\puerts_unreal_demo\Content\JavaScript\puerts\uelazyload.js:23:38)
    at getUClassOfType (E:\Unreal\xiuxian\client\puerts_unreal_demo\Content\JavaScript\PuertsEditor\CodeAnalyze.js:1042:30)
    at E:\Unreal\xiuxian\client\puerts_unreal_demo\Content\JavaScript\PuertsEditor\CodeAnalyze.js:1014:54
    at visitNodes (E:\Unreal\xiuxian\client\puerts_unreal_demo\Content\JavaScript\PuertsEditor\node_modules\typescript\lib\typescript.js:16514:30)
    at Object.forEachChild (E:\Unreal\xiuxian\client\puerts_unreal_demo\Content\JavaScript\PuertsEditor\node_modules\typescript\lib\typescript.js:16742:24)
    at onSourceFileAddOrChange (E:\Unreal\xiuxian\client\puerts_unreal_demo\Content\JavaScript\PuertsEditor\CodeAnalyze.js:1004:28)
    at E:\Unreal\xiuxian\client\puerts_unreal_demo\Content\JavaScript\PuertsEditor\CodeAnalyze.js:941:29

AnotherActor被改为如下:

import * as UE from "ue";
import { blueprint } from "puerts";

const TestBlueprint = blueprint<typeof UE.TestBlueprint_C>(
  "/Game/StarterContent/TestBlueprint.TestBlueprint_C"
);

class AnotherActor extends TestBlueprint {
  //注意,继承UE类的js类,构造函数必须大写开头
  Constructor() {
    console.warn("AnotherActor.Constructor");
  }

  //override 1
  ReceiveBeginPlay(): void {
    console.warn("AnotherActor.ReceiveBeginPlay");
  }
}

export default AnotherActor;

Canvas构造函数的问题,类似的对象很多

class Canvas extends Object {
constructor(Outer?: Object, Name?: string, ObjectFlags?: number);
ts中的Canvas 构造函数需要提供3个参数,可是没有文档说明这3个参数是怎么传递的还是说随意传值,是否需要阅读c++源码才行

VSCode调试配置可以具体些吗,官方文档的介绍太少了

1.要安装哪些插件
2.要配置哪些json文件
3.要配置ts-node或者V8吗
4.//GameScript = MakeSharedpuerts::FJsEnv(std::make_uniquepuerts::DefaultJSModuleLoader(TEXT("JavaScript")), std::make_sharedpuerts::FDefaultLogger(), 8080);
这行代码需要取消注释吗,端口8080需要在vscode中哪里进行配置吗

代理的内存泄露bug

import * as UE from 'ue'
import {$ref, $unref, $set, argv, on, toManualReleaseDelegate, releaseManualReleaseDelegate} from 'puerts';

/////////////////////////////////////////////////////////////////////////
let world = (argv.getByName("GameInstance") as UE.GameInstance).GetWorld();
let actor = world.SpawnActor(UE.MainActor.StaticClass(), undefined, UE.ESpawnActorCollisionHandlingMethod.Undefined, undefined, undefined) as UE.MainActor;
function ggg(){
let arr = new Array(1000000);
function MutiCast2(i) {
if(arr){}
}
actor.NotifyWithInt.Add(MutiCast2)
actor.NotifyWithInt.Remove(MutiCast2);
}

for(let i=0;i<10;i++){
ggg()
}
actor = null

tsx文件的更改无法被PurtesEditor更新

尝试使用内置的react-umg开发UI,发现每次更改.tsx文件后,editor并不能自动更新,即使手动跑了tsc命令也无济于事,目前只发现两种办法可以刷新更新后的tsx文件

  1. 文件重新命名,重新使用tsc生成(手动移除content/javascript下的js文件也不行,只能重命名)
  2. 重启UEEditor

以下是我的操作步骤:

  1. clone到本地
  2. 在如下地方跑了npm install:
    根目录
    Content/Javascript
    Content/Javascript/PuertsEditor
  3. 打开uproject之后开启了PuertsEditor Module Enabled,没有开其他debug的东西
    本地环境:
  4. windows 10
  5. node 12.18.2
  6. npm 6.14.5
  7. Unreal 26.1

此外,有没有办法可以手动根据ts生成蓝图,我觉得这个目录结构太混乱了,到处都是javascript和typescript相关的文件夹,有没有办法可以把所有JS相关的文件统一到一起?(我pull官方plugin也给我放一堆文件夹)

UE4.24.3打开Demo失败

打开过程中提示
Tips
tips2
本机node 版本: Node.js v14.5.0
VS版本 : VS2019
系统 : Windows 10 64-bit (10.0, Build 19041) (19041.vb_release.191206-1406)

整型引用

c++
bool Send(const FArrayBuffer& Buffer, int32& BytesSent)

在ts中定义了BytesSend,调用如下:
let BytesSent = 0; bool bSend = Send(buffer, $ref(BytesSent));
这里,BytesSent在ts中没办法返回,依然为0,但在c++层,已经修改了。

想问一下,支持number的引用吗?

有个版本问题

最新版本的puerts和这个demo使用的有一些函数已经不能用了,希望可以更新一下,万分感谢!

正确的启动项目

1.打开JsProj目录,输入npm i typescript

2.将package.json改成下面的代码.

{
  "name": "tgamejs-demo",
  "version": "0.0.1",
  "description": "tgamejs demo.",
  "scripts": {
    "build": "tsc"
  },
  "author": "johnche",
  "license": "MIT",
  "dependencies": {
    "@types/mocha": "^7.0.1",
    "@types/react": "^15.6.6",
    "@types/react-reconciler": "^0.18.0",
    "typescript": "^4.0.2"
  },
  "devDependencies": {}
}

3.控制台输入npm run build

4.在去启动项目

bug

进入Editor界面之后,每次点击Compile,QuickStart.ts中的Add,Bar等方法就不能使用,在ue.d.ts中就没有这些方法,但是每次重新打开Editor就有了

win7 vs2017 编译demo报错

UE引擎版本 4.26.2
win7系统 vs2017
更新到最新版本 编译报错

1>S:/Code/macmini/Game/UE4/puerts/puerts_unreal_demo_check/Plugins/Puerts/Source/JsEnv/Private/PesapiAddonLoad.cpp(107): error C2894: 模板不能声明为有“C”链接
1>S:/Code/macmini/Game/UE4/puerts/puerts_unreal_demo_check/Plugins/Puerts/Source/JsEnv/Private/PesapiAddonLoad.cpp(111): error C2894: 模板不能声明为有“C”链接

unreal 5.2内存泄漏

16871392364485
unreal 5.2版本打开工程后,直接运行TsGameInstance,跑通后无异常并停止运行,工程打开后内存会不断增长,最后出现out of memory错误。
另外unreal 4.27.2版本不会出现这种问题。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.