Announcement

Collapse
No announcement yet.

How to use UFUNCTION macro with inline methods?

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

    How to use UFUNCTION macro with inline methods?

    I have the following method in my game mode class (header file):

    Code:
    void BadBugDied(APawn* BadBug) { BadBugs.Remove(BadBug); }
    This compiles and works fine.
    Now I add the UFUNCTION macro, to call this method from BP:

    Code:
    UFUNCTION(BlueprintCallable, Category = "Bad Bugs")
    FORCEINLINE void BadBugDied(APawn* BadBug) { BadBugs.Remove(BadBug); }
    This leads to the following error during compilation:

    "Unrecognized type 'void' - type must be a UCLASS, USTRUCT or UENUM"

    The same error occurs also when I use the inline keyword instead of the FORCEINLINE macro.

    Am I missing something here?
    Last edited by MaFloBra; 07-17-2016, 08:17 AM.
    Modular Menu System @ UE4 Marketplace: "Build your UMG Menus in Minutes!"
    Marketplace Page | General Discussion | Support Thread | Preview Video

    #2
    My game mode class starts like this:
    Code:
    UCLASS(minimalapi)
    class AGDemoGameMode : public AGameMode
    {
    	GENERATED_BODY()
    Have you tried moving the implementation to the .cpp file or to the end of the header?

    HTH
    Never say Never, Because Never comes too soon. - ryan20fun

    Frames Per Second is NOT a proper performance metric, You should use frame time. You can read this or this as to why.
    (Profiling) Tools: RenderDoc (UE4 Plugin), NVIDIA nSight, AMD GPU PerfStudio, CodeXL
    Good articles/Series: A trip through the Graphics Pipeline 2011

    Comment


      #3
      Originally posted by ryan20fun View Post
      Have you tried moving the implementation to the .cpp file or to the end of the header?
      Sure, that would work.
      But my intention was to compile this method inline ...
      Modular Menu System @ UE4 Marketplace: "Build your UMG Menus in Minutes!"
      Marketplace Page | General Discussion | Support Thread | Preview Video

      Comment


        #4
        Why do you want it to be inlined?

        I would suggest getting the function to show up in BP before (trying) to get it inlined.

        HTH
        Never say Never, Because Never comes too soon. - ryan20fun

        Frames Per Second is NOT a proper performance metric, You should use frame time. You can read this or this as to why.
        (Profiling) Tools: RenderDoc (UE4 Plugin), NVIDIA nSight, AMD GPU PerfStudio, CodeXL
        Good articles/Series: A trip through the Graphics Pipeline 2011

        Comment


          #5
          Well, whether or not a function or method in C++ should or should not be inlined is a broad topic, which I don't want to discuss here. My question was more if it is possible in UE4 to have an inlined UFUNCTION
          Modular Menu System @ UE4 Marketplace: "Build your UMG Menus in Minutes!"
          Marketplace Page | General Discussion | Support Thread | Preview Video

          Comment


            #6
            It's probably just a limitation of UHT (it has many).

            It's completely unnecessary though, inline or not is totally insignificant in comparison to the overhead of calling a function from blueprint. If you need to call this function from C++ a lot, then make an inline function to do the work, and then a separate BlueprintCallable UFUNCTION that just calls the inline function.

            If you're going to be calling the function so often from blueprint that you're worrying about inlining it though, then you just shouldn't be calling it from blueprint in the first place.

            Comment


              #7
              Originally posted by kamrann View Post
              It's probably just a limitation of UHT (it has many).

              It's completely unnecessary though, inline or not is totally insignificant in comparison to the overhead of calling a function from blueprint. If you need to call this function from C++ a lot, then make an inline function to do the work, and then a separate BlueprintCallable UFUNCTION that just calls the inline function.

              If you're going to be calling the function so often from blueprint that you're worrying about inlining it though, then you just shouldn't be calling it from blueprint in the first place.
              Seems to be a wise summary, thanks a lot!
              Modular Menu System @ UE4 Marketplace: "Build your UMG Menus in Minutes!"
              Marketplace Page | General Discussion | Support Thread | Preview Video

              Comment


                #8
                for BlueprintNativeEvents use this syntax:

                Code:

                UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "local") FORCEINLINE
                USoundCue* getEmptyChamberSound();
                USoundCue* getEmptyChamberSound_Implementation(){return nullptr;};


                thank me later
                Last edited by Arty-McLabin; 02-06-2018, 09:28 AM.

                Comment


                  #9
                  is it possible to create a #define macro to create blueprint callable functions?

                  Comment


                    #10
                    Definitely possible yeah.

                    Comment


                      #11
                      It may be a bug, but the solution is simple. Just remove the 'inline', and write the definition to the header. All definitions in a header will be treated as inline function.
                      class UAxx
                      {
                      GENERATED_BODY()
                      public:
                      UFUNCTION(BlueprintCallable)
                      void Hello(){printf("xxx");};
                      }

                      Comment

                      Working...
                      X