Announcement

Collapse
No announcement yet.

ue4 custom functions in c++

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

    ue4 custom functions in c++

    Hi,
    I just start learning c++ in ue4 and have quastion I found tutorial how create custom function and call it in exist blueprint, so i copy this code and some functions this code return errors for example getactorlocation(), i need add some #include in .ccp and .h file?

    #2
    GetActorForwardVector() is defined in AActor, so your function doesn't know what that is.
    You need a reference to the actor you want to process :
    Code:
    void MyFunction(ACharacter* InChar)
    {
       ...
       FVector CurrentForwardVec = InChar->GetActorForwardVector();
       ...
    }
    Last edited by Bolobolo; 05-17-2019, 06:45 PM.

    Comment


      #3
      Thx you! I am ultra noob ;D

      Comment


        #4
        still not working some problem with InChar

        Comment


          #5
          You need to include ACharacter before you can use it.
          Code:
          #include "GameFramework/Character.h"

          Comment


            #6
            GarnerP57 thx I I appreciate your time, becouse find solution in internet is very hard. Why coding in c++ this engine is so hard I try made ultra simple function and every step I got error. After when you add me solution i was error target so i find i must add static void, now when everything should be fine I have ue4 crash to descop after start play wtf?
            MyBlueprintFunctionLibrary.cpp

            #include "MyBlueprintFunctionLibrary.h"
            #include "GameFramework/Character.h"

            void UMyBlueprintFunctionLibrary::MyFunction(ACharacter * InChar, FVector & out)
            {
            FVector vector = InChar->GetActorForwardVector();
            out = vector;
            }

            MyBlueprintFunctionLibrary.h

            #include "CoreMinimal.h"
            #include "Kismet/BlueprintFunctionLibrary.h"
            #include "MyBlueprintFunctionLibrary.generated.h"

            UCLASS()
            class MYPROJECT1_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
            {
            GENERATED_BODY()

            UFUNCTION(BlueprintCallable, Category = "Character")
            static void MyFunction(ACharacter* InChar, FVector& out);
            };



            Comment


              #7
              Jumping into a huge code base like UE4 while learning C++ is not going to be easy. I would recommend that you get some basic knowledge of C++ before taking the plunge into C++ in UE4 or you will be pulling your hair out all day long.

              Calling a function on an instance that doesn't exist (NULL) will result in a crash. You are calling "MyFunction" but you don't input any "InChar".

              Comment


                #8
                > Why coding in c++ this engine is so hard

                One must learn how to program, regardless of the language.

                Comment

                Working...
                X