Announcement

Collapse
No announcement yet.

Adding an Actor class to plugin?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Adding an Actor class to plugin?

    This might be a ridiculous question, but....

    I have a plugin that I am working on, and I need to add a new class to it. The 'add code to project' feature from the UE editor will not let me, as I am restricted to adding to the Source folder.
    If I manually create a new .cpp, when I refresh the visual studio project it vanishes.

    How should I be doing this?

    Thanks!

    #2
    Yeah you have to add them through VS so it can generated the 'Generated Headers' but buggered if I can remember how...

    See if this helps:
    https://docs.unrealengine.com/latest...#codeinplugins

    Comment


      #3
      here is a way to do it:

      1-Close Visual Studio
      2-Go to your plugin classes folder
      3-Add 2 empty files TestActor.h and TestActor.cpp
      4-Then , "Generate Visual Studio Project
      5-Open Visual Studio , then the files created

      TestActor.h
      Code:
      #pragma once
      
      #include "GameFramework/Actor.h"
      #include "TestActor.generated.h"
      
      UCLASS()
      class  ATestActor : public AActor
      {
      	GENERATED_UCLASS_BODY()
      
      };
      TestActor.cpp

      Code:
      #include "MyPluginPCH.h"
      #include "TestActor.h"
      
      ATestActor::ATestActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
      {
      
      }
      PS : No class constructor in the header needed
      Website [ LINK ]
      Twitter [ LINK ]
      Support ! [ LINK ]

      Comment


        #4
        Hi, thanks for getting back to me. I used your code, and make the files, but it still will not compile.

        TestActor.cpp

        Code:
        #include "m2uPluginPrivatePCH.h"   //cannot find this file, it is linked in every cpp in the plugin. It is in the 'Private' folder though, is this why?
        #include "TestActor.h"
        
        ATestActor::ATestActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)  //ObjectInitializer is not a type name.
        {
        
        }
        TestActor.h

        Code:
        #pragma once
        
        #include "GameFramework/Actor.h"
        #include "TestActor.generated.h"  //cannot open file
        
        UCLASS() //Type name is not allowed. 
        class  ATestActor : public AActor
        {
        	GENERATED_UCLASS_BODY() // expected a ')'
        
        };


        I have added the errors in //

        Am I missing something here?

        thanks again!

        Comment


          #5
          In the test I made there all the files are in private folder

          Make sure your plugin Build.cs have these included
          Code:
          PrivateDependencyModuleNames.AddRange(
          			new string[] {
                                          "Core",
          				"CoreUObject",
          				"Engine",
                                          "InputCore",
          				"UnrealEd"
          			}
          Website [ LINK ]
          Twitter [ LINK ]
          Support ! [ LINK ]

          Comment


            #6
            and this too

            Code:
             PrivateIncludePaths.Add("TestPlugin/Private");
            Website [ LINK ]
            Twitter [ LINK ]
            Support ! [ LINK ]

            Comment


              #7
              Ah I didn't have them in the Private folder. Many thanks! Works great.

              Comment


                #8
                I think a more appropriate answer would be: open Unreal Editor, go to File --> New C++ Class, choose the base class and hit Next, and change the module (the dropdown just right of the class name) to your plugin.

                I suppose the plugin must reside in the project folder for this to work though (not in the engine folder).
                --

                Comment

                Working...
                X