The reason you need to select the correct build configuration for intellisense to work is that the binding assemblies are per-configuration. This is partly technical - we mirror/blit types like FName that vary in size for different engine builds, and some types and members are only accessible for certain engine builds. However, this also allows you to use constructs like #if CONFIG_SHIPPING in your C# code.
I added a build error to the start of the C# build when the binding assemblies for the active config/platform are missing… hopefully it’s clearer than all those missing type errors
First… for some reason when using C++/C# the GAMENAME_Managed.sln looses (when using Rider IDE) its reference
to the Binding project. I managed to get around this by adding the ./Intermediate/…/Mono/GameBindings.csproj to the GAMENAME_Managed.sln and making a reference to the newly added project… Now everything builds and can run the game.
As far as HOW or WHEN that ./intermediate/…/Mono project gets created or updated… Can we force that binding project to re-create or update itself or something like that…
The reason I ask… I added a simple Blueprint Function Library class to my C++ and a MyActor… The MyActor shows up in the intermediate bindings project BUT the Blueprint Function Library does not…
This is a simple class that is NOT showing up in the bindings (UNLESS ITS NOT SUPPOSED TO … I AM GOING ABOUT IT THE WRONG WAY… for creating Utility type functions that I would like to expose to C#… in case I gotta write some performant C++ worker function… not associated with an actor or a specific game object class… just like C++ Blueprint function libraries are exposed to blueprint)… I think thats what I want
Header file:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
include “CoreMinimal.h” include “Kismet/BlueprintFunctionLibrary.h” include “MyBlueprintFunctionLibrary.generated.h”
/**
*
*/
UCLASS()
class TESTMIXPROJECT_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
When you say I can access static and instance methods (UFUNCTIONS) … that if for Game object specific classes right…liek the putting the static and instance function on the class the blueprint is derived from ???
Is there a way of using static utility functions are not on the blueprint base class…
Sorry keep asking same type of question… I am just trying to figure out what I can and can’t do from C++ to C# and how I am going to design some of my General Purpose Game functions that required THUNKING down to the c++ layer… basically the same way Blueprint Function Libraries provide that general purpose util functions to blue print… I assumed that was the same thing for C++ to C# worker util functions…
@MackeyK24 Instance functions would be UFunctions on game objects, static functions would be UFunctions on UBlueprintFunctionLibrary subclasses, just like with C++.
@MackeyK24 also… the sln/cs/csproj files in Intermediate/…]/Mono/…] are generated by the MonoScriptGenerator UHT plugin. To regenerate them, re-run UHT. You can do this by touching one of the c++ UObject “Classes” header files and re-running UBT.
Ok… I see that for a C# only project … Create C# class to subclass UBlueprintFunctionLibrary in your Managed Game Project…
BUT HOW DO I Subclass a Custom C++ Blueprint Function Library like in my C++ I have a class:
UCLASS()
class TESTMIXPROJECT_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
In my managed code I wanna subclass my Custom ‘UMyBlueprintFunctionLibrary’. But when building the C++ project it does NOT generate a MyBlueprintFunctionLibrary.cs with the bindings to the underlying UMyBlueprintFunctionLibrary C++ class…
Should I be able to subclass a Custom Blueprint Library Function in my Managed Project
public class MyManagedBlueprintFunctionLibrary : UMyBlueprintFunctionLibrary {
}
and in C++ the native class would be:
UCLASS()
class TESTMIXPROJECT_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
Well I don’t know that I need to subclass a Blueprint Function Library…
I just wanna be able to call some WORKER type functions in the C++ layer from my C# layer.
I get the binding of of C++ native classes (Kinda like Xamarin IOS does to provide the C# iOS layer)
But where would I put a static worker function (not associated with an actual game object) in the C++ like:
static void SomeWorkerClass : : DoSomeExpensiveWork(Actor* pActor) {
// Do work here with passed in actor
}
then in one of my subclassed actor C# code
void SomeManagedFunction(Actor actor) {
// Call native C++ worker function from managed code
SomeWorkerClass.DoSomeExpensiveWork(actor);
}
So I figured subclass a Blueprint Function Library to generate bindings for native c++ base blueprint functions. then in my managed code I could just use something like:
Many thanks Mikayla for making this happen! Succesfully compiled the plugin and managed to open up a project in Visual Studio and have started C# scripting :). Looking forward to hot reload and debug functionality. Great work!
Did you just clone the mono-ue 4.17 fork and run the 4 commands in the directory:
Setup.bat
GenerateProjectFiles.bat
Engine\Build\BatchFiles\Build.bat ShaderCompileWorker Win64 Development
Engine\Build\BatchFiles\Build.bat UE4Editor Win64 Development
and it worked? Or you made some changes or compiled with visual studio or other?
I’ve been doing some testing on Enums and Structs. On enums the following compiles fine:
[UEnum]
public enum EItemState : System.Byte
{
UnDamaged,
Damaged
}
But when I load the project Unreal gives me the following error:
Update (Issue fixed): I had the enum inside a class. Moving the enum code outside the class fixed the problem. The project loads and I’m able to see the Enum type in the Editor.
On structs the following also compiles fine but the struct is not visible as a type in the Editor.
[UStruct]
public struct ItemData
{
public float Value;
}
@Shuuny
Yes the build worked for me. Just follow the installation instructions on this page:
I was checking out the monoue-4.16 branch (not 4.17). Don’t forget to download and unzip the “MonoUEDependencies-c8df6088.zip” and make sure you have the Visual Studio 2017 workloads installed. It’s all mentioned in the instructions.
Anyways, if you want to expose C++ to C#, you can put instance UFunctions on a class, then subclass that class from C#. Or, you can put a static UFunction on BlueprintFunctionLibrary and call it from anywhere. It’s pretty much the same as exposing C++ or C# to blueprint.
I tried adding attributes to the struct and now the ItemData property shows up in the Editor.
public struct ItemData
{
[UProperty, BlueprintVisible, EditorVisible]
[Category(“Item”)]
public float Value;
}
public class Item: Actor
{
public ItemData itemData { get; set; }
}
However, it seems it’s not possible to define a variable inside the Editor of the struct type. The struct type does not show up in the Variable Type list in the Editor. If this should be possible I can file a Github issue.
Thanks @mhutch … The UFunction works on an instance… I just have not been able to implement a static Blueprint function because the binding generations are still a little
quirky… Thanks you for looking into C++ and C# issues…
From what I can tell so far…
1… UBLueprintFunctionLibrary in native DO NOT get bindings generated during UHT build like actors and uobjects…
2… the managed solution file (GAMENAME_Managed.sln) should have a reference to the Intermediate Bindings project and the GAMENAMEMono.csproj should Also
reference that intermediate assembly…
Then everything works great… Except missing UMyBlurprintFunctionLibrary.cs in intermediate project (But you looking into that).
As a workaround, I just use a UFunction on the actor to do heavy c++ stuff… Until I can move that code to UMyBlurprintFunctionLibrary C++ and then access from anywhere in C# as UMyBlurprintFunctionLibrary.DoMyWork() … I think that how it will work when your done fixing things…
Anyways… beside those C++ / C# binding issues (which can be worked around for now)… This thing is freaking awesome… I am going to mainly be writing C# (Which is freakin awesome … AGAIN)… I just needed to know that CAN thunk down to C++ should I need to… And I can
UPDATE: Oh yeah… And I’m on a Mac… Using JetBrains Rider (For Now)… The editor, the compiling… everything working fine on Mac… Granted not the MOST performant graphics compared to windows… But Looks great for Mac… and runs smoothly… So far
Thanks again Mikayla… I know you get that a lot… But thank you, thank you, thank you… From ALL OF US in the community… Thank you
@JohDav I’m not sure of any underlying engine limitations, but in general, if something can be exposed to the editor or Blueprint with C++, it should be possible with C#.