Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Managed assemblies loading only from sub-folders #18

Closed
ScottKane opened this issue Aug 13, 2020 · 12 comments
Closed

Managed assemblies loading only from sub-folders #18

ScottKane opened this issue Aug 13, 2020 · 12 comments
Labels
bug Something isn't working

Comments

@ScottKane
Copy link
Contributor

I have just created a new BP project, installed UnrealCLR, created a .NET Core class library, copied C# entry point code from the manual, added reference to UnrealEngine.Framework, built class library to Managed folder with dotnet build -o %Project%\Managed and then ran in editor.

I'm not getting any of the on screen debug messages which I'm assuming means the entry point isn't working. The class library/framework dll's are in the Managed folder.

@nxrighthere
Copy link
Owner

Show me your code please.

@ScottKane
Copy link
Contributor Author

using System;
using System.Drawing;
using UnrealEngine.Framework;

namespace Game
{
    public static class Main
    { // Indicates the main entry point for automatic loading by the plugin
        public static void OnWorldBegin() => Debug.AddOnScreenMessage(-1, 10.0f, Color.DeepPink, "Hello, Unreal Engine!");

        public static void OnWorldEnd() => Debug.AddOnScreenMessage(-1, 10.0f, Color.DeepPink, "See you soon, Unreal Engine!");

        public static void OnWorldPrePhysicsTick(float deltaTime) => Debug.AddOnScreenMessage(1, 10.0f, Color.DeepPink, "On pre physics tick invoked!");

        public static void OnWorldDuringPhysicsTick(float deltaTime) => Debug.AddOnScreenMessage(2, 10.0f, Color.DeepPink, "On during physics tick invoked!");

        public static void OnWorldPostPhysicsTick(float deltaTime) => Debug.AddOnScreenMessage(3, 10.0f, Color.DeepPink, "On post physics tick invoked!");

        public static void OnWorldPostUpdateTick(float deltaTime) => Debug.AddOnScreenMessage(4, 10.0f, Color.DeepPink, "On post update tick invoked!");
    }
}

@nxrighthere
Copy link
Owner

It works fine for me. The test project works for you? Which version of the plugin are you using?

@nxrighthere nxrighthere added the question Further information is requested label Aug 13, 2020
@ScottKane
Copy link
Contributor Author

I'm using the latest version of the plugin with UE4.25.3 and dotnet-sdk-3.1.401-win-x64 although during the installer I said no to the tests, will retry with the tests now

@nxrighthere
Copy link
Owner

If the test project doesn't work for you, then make sure that the plugin is properly initialized https://github.com/nxrighthere/UnrealCLR#running

@ScottKane
Copy link
Contributor Author

It's working now, I think it's because I was building with dotnet build -o %Project%\Managed\ but when I switched to dotnet build -o %Project%\Managed\ClassLib it's now working. I didn't realise output needed to be in a folder relative to the assembly name. Makes sense but could do with being a bit more clear in the docs

@nxrighthere
Copy link
Owner

Nevermind, I found why this might happen, going to fix it quickly.

@nxrighthere nxrighthere added bug Something isn't working and removed question Further information is requested labels Aug 13, 2020
@nxrighthere nxrighthere changed the title Managed Assembly not working Managed assemblies loading only from sub-folders Aug 13, 2020
@ScottKane
Copy link
Contributor Author

Awesome, also just been digging into the Tests and noticed that everything is static. What is the reason for this? Just wondering because in C++ you can for example do ACharacterBase : ACharacter whereas here if everything is static how do you do CharacterBase : Character? I ask because I was planning on using Dependency Injection which would require constructors.

@nxrighthere
Copy link
Owner

I did that in tests to quickly switch between them. If you have experience working with regular .NET applications where you have Main() entry point, then the principle here is the same. You have static entry points from where you kickstart your logic and then organize your code the way you like. There's no intermediate scripts manager or stuff like that. You can use inheritance here too, see this test.

@ScottKane
Copy link
Contributor Author

Ok yeah that makes sense, I was assuming I could do something like the following based on my understanding of the C++ workflow:

public class PlayerCharacter : Character
{
    protected override void Tick()
    {
        base.Tick();
        Debug.Log(LogLevel.Display, "Tick");
    }
}

@nxrighthere
Copy link
Owner

Yea, the approach here is very different. The framework is not following idioms of the engine, so you can organize the execution flow and stuff the way you like with full control over it and keep it all managed. So to reproduce the same approach as in your example, you can create an intermediate scripts manager to execute logic using the object-oriented design or any other one.

@ScottKane
Copy link
Contributor Author

Ok thanks for the info, will spend some time having fun with my own execution plan and see what I can come up with.

johsuacarter added a commit to johsuacarter/Unreal-Engine-Developer that referenced this issue Sep 5, 2022
softdev0arvr added a commit to softdev0arvr/UnrealCLR that referenced this issue Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants