I used UE4 for a while in the beginning and found that using the blueprint system really didn't suit my style. Because I have always used Unity3D for program development. But after I came into contact with UE4's C++, I felt quite good. It seems that there are no relevant books and teaching materials in China, so you can only go to the reference documents on the official website.
https://docs.unrealengine.com/latest/INT/Programming/index.html
My general impression of UE4 and Unity3D:
1. UE4 consumes more performance than Unity. Basically, UE4 games cannot be opened
. 2. The blueprint of UE is suitable for artists to see. Programmers should be honest and practical with C++
. 3. Unity can save C# code every time it is written. Running, and UE4 can only be used by manually recompiling and restarting every time the code is written. This is very dependent on computers with strong performance, especially CPU, solid-state, solid-state
4. Unity is based on component programming, each in the view window. Gameobject inherits from MomoBehavior and has system callbacks such as OnGUI, Update, and Start for you to use. However, UE4 can only manually inherit the virtual functions Tick and BeginPlak by itself, and rewrite it. It gives me the feeling that there are 2 good cars, one is automatic and the other is manual.
Create a new C++ basic project for Unreal 4
![](https://upload-images.jianshu.io/upload_images/442033-cfa2588cc2e60e86.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/692)
After the new
![](https://upload-images.jianshu.io/upload_images/442033-26b663e75adde788.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/692)
Create a new Actor class
![](https://upload-images.jianshu.io/upload_images/442033-21ba6519635df83c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/692)
add code to it
#pragma once #include "GameFramework/Actor.h" #include "MyActor.generated.h" UCLASS () class EMPTY_API AMyActor : public AActor { GENERATED_BODY() public : // Running time float RunningTime; // Constructor AMyActor(); // The callback executed at the beginning is equivalent to void Start() in Unity virtual void BeginPlay() override ; // The callback executed in each frame is equivalent to void Update() in Unity virtual void Tick( float DeltaSeconds ) override ; }; #include "empty.h" #include "MyActor.h" #include "iostream" //构造器 AMyActor::AMyActor() { // Set Tick() to be executed once per frame, set to false if not needed PrimaryActorTick.bCanEverTick = true ; } // Callback executed at the beginning void AMyActor::BeginPlay() { Super::BeginPlay(); std::cout << " Start execution " ; } // Callback executed every frame void AMyActor::Tick( float DeltaTime ) { std::cout << " execute every frame " ; Super :: Tick (DeltaTime); // Get the Actor's location and save it to the NewLocation variable FVector NewLocation = GetActorLocation(); // Get the time difference float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime)); // Changed Height, incremented by 20.0f each time NewLocation.Z += DeltaHeight * 20.0f ; // Change the value of running time RunningTime += DeltaTime; // Set the current Actor's position SetActorLocation(NewLocation); }
Finally, add the code MyActor to a cone, press Ctrl+F5 to compile and you can see it shaking up and down
![](https://upload-images.jianshu.io/upload_images/442033-645fa2db0f290b37.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/692)