< reprint > UE4 's actor Class C + + simple attempt

Source: Internet
Author: User
Tags sin

original link: Jane bookSmall crisp xx https://www.jianshu.com/p/2bcc80f0e789

At first I spent a period of time UE4, and found that if the blueprint system really does not suit my style. Because it has been developed with Unity3d program. But then, after touching the UE4 C + +, it felt pretty good. It seems that there is no relevant books and textbooks in the country, it can only go to the crossing Web reference document

Https://docs.unrealengine.com/latest/INT/Programming/index.html

UE4 and Unity3d give me the general feeling:

1.ue4 consumes a lot more than unity N, basically open UE4 game can not open
2.UE blueprint for the artist to see, the programmer should honestly use C + + Bar
3.Unity each time after writing C # code save can be run, and UE4 can only be used each time after writing code manually recompile and restart, this is very dependent on a particularly strong computer, especially CPU, solid state, solid state
4.Unity component-based programming, each gameobject in the view window inherits from Momobehavior has Ongui, Update, start and other system callbacks for you to use. Instead, UE4 can only manually inherit the virtual function tick and Beginplak, and replicate it. Give me feel is 2 good car, one is automatic block, one is manual block.

Create a new C + + Foundation project for Unreal 4

Paste_image.png

When the new is complete

Paste_image.png

Create a new actor class

Paste_image.png

Add code to it

#pragmaOnce#include"Gameframework/actor.h"#include"myactor.generated.h"Uclass ()classEmpty_api Amyactor: Publicaactor{generated_body () Public:    //Run Time    floatRunningtime; //ConstructorsAmyactor (); //the callback executed at the start is equivalent to the void start () in Unity    Virtual voidBeginplay ()Override; //each frame executes a callback equivalent to void Update () inside Unity    Virtual voidTick (floatDeltaseconds)Override;}; #include"Empty.h"#include"MyActor.h"#include"iostream"//ConstructorsAmyactor::amyactor () {//set tick () once per frame, set to False if not requiredPrimaryactortick.bcanevertick =true;}//callback to execute at startvoidAmyactor::beginplay () {super::beginplay (); Std::cout<<"Start Execution";}//callbacks executed at each framevoidAmyactor::tick (floatdeltatime) {Std::cout<<"each frame executes";    Super::tick (deltatime); //gets the position of the actor saved to the NewLocation variableFvector NewLocation =getactorlocation (); //Get the time difference value    floatDeltaheight = (Fmath::sin (runningtime + deltatime)-Fmath::sin (runningtime)); //change the height of each increment by 20.0fNewlocation.z + = Deltaheight *20.0f; //change the value of run timeRunningtime + =Deltatime; //set the position of the current actorsetactorlocation (newlocation);}
 

Finally add the code myactor to a cone and press CTRL+F5 to compile it to see it shaking up and down.

< reprint > UE4 's actor Class C + + simple attempt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.