Code Monkey home page Code Monkey logo

unrealcsharp's Introduction

Logo

license release PRs Welcome

概述

    UnrealCSharp是UE下C#编程插件,基于.NET 7(Mono)。提供多种编程模式,功能强大且容易上手,能够灵活高效地进行游戏开发。

特性列表

  • 支持全部的反射类型,自动生成C#代码
  • 能够静态导出各种数据类型和函数
  • 拥有强大的动态类特性,可以通过C#直接生成UClass,UInterface,UStruct和UEnum,并且不需要蓝图载体
  • 支持跨平台
  • 简单方便的代码调试
  • 能够通过Pak进行C#热更新
  • 编辑器下,能够热重载C#变更

平台支持

  • 运行平台:Windows / macOS / Linux / Android / IOS
  • 引擎版本:Unreal Engine 5.0 - Unreal Engine 5.3

文档

社区

Contributors

unrealcsharp's People

Contributors

bladerzhu avatar cesun avatar codeex222 avatar crazytuzi avatar emiyawan avatar jomixedyu avatar karrycharon avatar rhm0325 avatar srkmn 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  avatar  avatar  avatar

unrealcsharp's Issues

[Bug] System.Action`9 Exception

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.Action9 member:(null)
Exception: Exception 0xc0000005 encountered at address 0x7ffb5df2dbb8: Access violation reading location 0x0000000c

CppSharp自动生成C++的绑定代码

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函数

UE5.3编译UnrealCSharp错误及解决方案

问题1

报错:

[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"

问题2:

报错:

[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,比较菜,可能上述内容有问题。

[BUG] Unreal freeze.

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

[BUG] UButton Event Bind failed

绑定 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后仍然是空对象

[Perf] Some iterator method can be improved by using internal method

实际对性能影响未测试, 仅为猜测, Remove 和 Find 等可替换为 内置实现

  1. int32 TGarbageCollectionHandleMapping::Remove(const MonoObject* InKey)
  2. MonoObject* FContainerRegistry::GetObject(const void* InAddress)
  3. T* TGarbageCollectionHandleMapping::Find(const MonoObject* InMonoObject)
  4. bool FContainerRegistry::RemoveReference(const void* InAddress)
  5. bool FDelegateRegistry::RemoveReference(const void* InAddress)

[Bug] C# Side Override Method Not Called

  1. 蓝图Actor B 继承自 A
  2. 蓝图A 有方法 Print
  3. 蓝图A的BeginPlay中调了 Print
  4. 蓝图B没有重写BeinPlay
  5. 蓝图B重写了Print
  6. C# 侧 实例化 Actor B, 这时会调A中的Print 而非B的Print

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.