crazytuzi / unrealcsharp Goto Github PK
View Code? Open in Web Editor NEWUnrealCSharp, based on .NET 8 (Mono), is a C# programming plugin for UE.
Home Page: https://unrealcsharp.github.io/
License: MIT License
UnrealCSharp, based on .NET 8 (Mono), is a C# programming plugin for UE.
Home Page: https://unrealcsharp.github.io/
License: MIT License
蓝图定义的函数 如果入参标记里 ref 则不能按out 处理, 因为 传入参数不能确定用途
`using System;
using Script.Dynamic;
using Script.Engine;
namespace Script.CoreUObject;
[UClass]
public partial class AMyActor : AActor
{
public AMyActor()
{
PrimaryActorTick.bCanEverTick = true;
Console.WriteLine("AMyActor Constructor!" + PrimaryActorTick.bCanEverTick);
}
[Override]
public override void ReceiveBeginPlay()
{
base.ReceiveBeginPlay();
Console.WriteLine("ReceiveBeginPlay!");
}
[Override]
public override void ReceiveTick(float time)
{
base.ReceiveTick(time);
Console.WriteLine("ReceiveTick: " + time);
}
}`
直接spawn 这个类,ReceiveBeginPlay 的日志可以正常输出, ReceiveTick 不会被触发。
[356/359] Compile [x64] MulticastDelegateHandler.cpp
[357/359] Link [x64] UnrealEditor-UnrealCSharp.lib
正在创建库 E:\xiuxian\xiuxian5\Plugins\UnrealCSharp-0.2.0\Intermediate\Build\Win64\x64\UnrealEditor\Development\UnrealCSharp\UnrealEditor-UnrealCSharp.lib 和对象 E:\xiuxian\xiuxian5\Plugins\UnrealCSharp-0.2.0\Intermediate\Build\Win64\x64\UnrealEditor\Development\UnrealCSharp\UnrealEditor-UnrealCSharp.exp
[358/359] Link [x64] UnrealEditor-UnrealCSharp.dll
正在创建库 E:\xiuxian\xiuxian5\Plugins\UnrealCSharp-0.2.0\Intermediate\Build\Win64\x64\UnrealEditor\Development\UnrealCSharp\UnrealEditor-UnrealCSharp.sup.lib 和对象 E:\xiuxian\xiuxian5\Plugins\UnrealCSharp-0.2.0\Intermediate\Build\Win64\x64\UnrealEditor\Development\UnrealCSharp\UnrealEditor-UnrealCSharp.sup.exp
FRegisterQuat.cpp.obj : error LNK2001: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EForceInit@@@@YAPEAVUEnum@@xz)
FRegisterRotator.cpp.obj : error LNK2001: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EForceInit@@@@YAPEAVUEnum@@xz)
FRegisterVector2D.cpp.obj : error LNK2001: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EForceInit@@@@YAPEAVUEnum@@xz)
FRegisterVector4.cpp.obj : error LNK2001: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EForceInit@@@@YAPEAVUEnum@@xz)
FRegisterBox2D.cpp.obj : error LNK2001: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EForceInit@@@@YAPEAVUEnum@@xz)
FRegisterLinearColor.cpp.obj : error LNK2001: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EForceInit@@@@YAPEAVUEnum@@xz)
FRegisterMatrix.cpp.obj : error LNK2001: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EForceInit@@@@YAPEAVUEnum@@xz)
FRegisterPlane.cpp.obj : error LNK2001: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EForceInit@@@@YAPEAVUEnum@@xz)
FRegisterWorld.cpp.obj : error LNK2019: 无法解析的外部符号 "class UEnum * __cdecl StaticEnum(void)" (??$StaticEnum@W4EObjectFlags@@@@YAPEAVUEnum@@xz),函数 "public: virtual class FString __cdecl TTypeInfo<enum EObjectFlags,0>::GetName(void)const " (?GetName@?$TTypeInfo@W4EObjectFlags@@$0A@@@ueba?AVFString@@xz) 中引用了该符号
E:\xiuxian\xiuxian5\Plugins\UnrealCSharp-0.2.0\Binaries\Win64\UnrealEditor-UnrealCSharp.dll : fatal error LNK1120: 2 个无法解析的外部命令
Total time in Parallel executor: 81.17 seconds
Total execution time: 90.16 seconds
LogInit: Warning: Still incompatible or missing module: UnrealCSharp
LogInit: Warning: Still incompatible or missing module: UnrealCSharpEditor
LogInit: Warning: Still incompatible or missing module: Generator
LogInit: Warning: Still incompatible or missing module: Compiler
LogInit: Warning: Still incompatible or missing module: UnrealCSharpCore
LogInit: Warning: Still incompatible or missing module: CrossVersion
LogCore: Engine exit requested (reason: EngineExit() was called)
LogExit: Preparing to exit.
LogXGEController: Cannot use XGE Controller as Incredibuild is not installed on this machine.
LogXGEController: Cleaning working directory: C:/Users/qiuhaohui2020/AppData/Local/Temp/UnrealXGEWorkingDir/
LogPakFile: Destroying PakPlatformFile
LogExit: Exiting.
有些项目可能不想把所有代码都放到一个Game.dll中,希望可以更灵活点,支持使用者自己创建项目编译出的dll可以在编辑器中使用
#390
pull 这个 issue 后,c# 动态函数可以正常触发回调,但是静态函数仍然无法触发
编译错误。这个要怎么处理?
Hello,
I'm experiencing an issue with the use of the C# plugin for Unreal. I have successfully installed the plugin, but as soon as I press the "Play" button to launch the project, Unreal freezes and becomes unresponsive.
I have tried uninstalling and reinstalling the plugin, but the issue persists. I have tested this issue with both Unreal versions 5.1.1 and 5.0.3, and have verified that the plugin's minimum requirements are met.
Do you have any advice or suggestions for resolving this problem?
Thank you in advance for your help.
Best regards
https://github.com/mono/CppSharp
这个库只需要提供头文件和.lib文件就可以自动生成绑定代码
源码的
Engine\Intermediate\Build\Win64\UnrealEditor\Inc\ 文件夹下有UHT生成的反射文件
Engine\Intermediate\Build\Win64\x64 文件夹下是编译模块时的宏
Engine\Binaries\Win64里的dll导出成lib就可以用了
再把DllImport改成MethodImplOptions.InternalCall应该就能用
CppSharp是一个C#的库,功能很强大,就是教程有点少,只有几篇官方文档
https://github.com/mono/CppSharp/tree/main/docs
也没有对所有API介绍,有些函数只能自己猜
可能对一些复杂的模板类不能导出
我还看到虚幻还可以将整个引擎导出成一个库
在C#就可以启动UE,但也不是很好用,而且只支持Windows平台
https://docs.unrealengine.com/5.2/zh-CN/building-unreal-engine-as-a-library/
实际导出后发现dll没有export所有函数,只有文档里的4个内置api
查看UBT的Definination发现导出时没有将XXX_API宏define为DLLEXPORT
请问大佬知道怎么才能导出函数吗
最近的.Net7 新增的NativeAOT可以将C#代码导出为C++可以调用的DLL,唯一的缺点是只能导出static函数
实际对性能影响未测试, 仅为猜测, Remove 和 Find 等可替换为 内置实现
干得漂亮啊,话说什么时候可以用于生产了呢,目前支持哪些平台?
容器类型的 Add正常, 但 Remove 和 Contains 结果错误
AudioTextBox 蓝图的 cs脚本导出会 有两个同名的Property UnitsText, 但类型是不同的
编译 UE.csproj 和 Game.csproj的时候 没有指定固定.net sdk
类似verse做法,注册个资源类型,可在资源管理器上看到相应C#类资源,让C#成为一等公民[dog]
绑定 UButton 的 OnPressed 事件总是失败
平台:
Win11, UE 5.1
在Widget的PreConstruct中 给按钮的OnPressed 添加回调
[IsOverride]
public void PreConstruct(Boolean IsDesignTime)
{
// btn_About = Unreal.NewObject<UButton>(this, UButton.StaticClass(), "btn_About");
Console.WriteLine("------1");
btn_About.OnPressed = new FOnButtonPressedEvent();
Console.WriteLine("------2");
btn_About.OnPressed?.Add(f);
Console.WriteLine("------3");
}
尝试过 不给 OnPressed new 对应的 事件对象, 以及自己new一个UButton 并 set给 btn_About, 结果一样
Debug模式下可以看到 btn_About.OnPressed为Null对象, set后仍然是空对象
Could not load signature of Script.Engine.AActor:get_OnTakePointDamage due to: Could not resolve type with token 01000037 from typeref (expected class 'System.Action9' in assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51') assembly:netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 type:System.Action
9 member:(null)
Exception: Exception 0xc0000005 encountered at address 0x7ffb5df2dbb8: Access violation reading location 0x0000000c
as the title indicates, to enable AOT
蓝图定义的结构体 对成员变量赋值时不会生效
报错:
[1/7] Compile [x64] Module.Generator.cpp
E:\Unreal Projects\Test\Plugins\UnrealCSharp\Source\Generator\Private\FBlueprintGenerator.cpp(8): fatal error C1083: 无法打开包括文件: “UMGEditor/Public/WidgetBlueprint.h”: No such file or directory
解决方案:
UnrealCSharp\Source\Generator\Private\FBlueprintGenerator.cpp: Line 8
#include "Engine/UserDefinedStruct.h"
- #include "UMGEditor/Public/WidgetBlueprint.h"
+ #include "WidgetBlueprint.h" // 这里应该用#if控制更好,不过我不会写x
#include "FGeneratorCore.h"
报错:
[3/7] Compile [x64] Module.UnrealCSharp.cpp
...... (此处省略 10 warnings)
E:\Unreal Projects\Test\Plugins\UnrealCSharp\Source\UnrealCSharp\Private\Reflection\Container\FMapHelper.cpp(213): error C4855: “/std:c++20”中已弃用通过 "[=]" 来隐式捕获 "this"
E:\Unreal Projects\Test\Plugins\UnrealCSharp\Source\UnrealCSharp\Private\Reflection\Container\FSetHelper.cpp(106): error C4855: “/std:c++20”中已弃用通过 "[=]" 来隐式捕获 "this"
解决方案:
UnrealCSharp\Private\Reflection\Container\FMapHelper.cpp: Line 211
ElementPropertyDescriptor->Set(InValue, Data);
+ #if __cplusplus >= 202002L
+ ScriptMap->Rehash(ScriptMapLayout, [=, this](const void* Src)
+ #else
ScriptMap->Rehash(ScriptMapLayout, [=](const void* Src)
+ #endif
{
return ElementPropertyDescriptor->GetValueTypeHash(Src);
});
UnrealCSharp\Private\Reflection\Container\FSetHelper.cpp: Line 104
KeyPropertyDescriptor->Set(InKey, Data);
+ #if __cplusplus >= 202002L
+ ScriptSet->Rehash(ScriptSetLayout, [=, this](const void* Src)
+ #else
ScriptSet->Rehash(ScriptSetLayout, [=](const void* Src)
+ #endif
{
return KeyPropertyDescriptor->GetValueTypeHash(Src);
});
刚接触UE,比较菜,可能上述内容有问题。
my csproj is empty i just installed the plugin and clicked generate code added the nessary modules but still and i know the other guy have the same issue but he didnt tell us how to fix
定时器快速生成(0.1s) 随机AIMoveTo的Charactor 运行时间太长导致异常.
CopyCSProj函数中的路径值正确但是没有生成sln文件
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.