Use UE4 to develop FPS games for nearly 1.5 of the time. With a growing understanding of UE4. The previous programming concept has changed a lot. Write it down and make a record
1, add functionality for actor or create component encapsulation feature
Recently in the writing of a sense of control function, according to the direction of the motion controller to determine the direction of the movement of the role. Whether jumping or not. When I start using UE4, I put the function in the character class, gradually the function of character class more and more, Maintenance is also complicated. And the character class is included in many files, each time the declaration of the character class needs to be reproduced to compile many files, the development efficiency becomes lower. When creating component to encapsulate the somatosensory control function, the code becomes cohesive, The character class only needs to hook up with this componnent to provide functionality. When you develop this component, compiling this component is a great speed to compile. So using component to develop functional advantages is obvious.
2. Use the Blueprintcallable,blueprintimplementableevent function to debug in the Blueprint
Adding blueprintcallable to a function can be easily called in a blueprint, and a function with Blueprintimplementableevent can be implemented in a blueprint, then a variable is plotted, or a debug graphic is drawn. Call the Debugdrawline series function.
3, add Ublueprintfunctionlibrary function
The functions in Ublueprintfunctionlibrary can be called globally in the blueprint, and the commonly used functions can be written into it to improve the development efficiency. For example, use meta = (Worldcontext = "Worldcontextobject") Tags can pass the current context object in the Blueprint
Uclass ()classShootergame_api ushooterblueprintfunctionlibrary: Publicublueprintfunctionlibrary{//get the other playersUfunction (blueprintpure, meta = (Worldcontext ="Worldcontextobject"), Category ="Player") Staticashootercharacter* Getotherplayer (uobject* worldcontextobject, ashootercharacter*Player);} Ashootercharacter* Ushooterblueprintfunctionlibrary::getotherplayer (uobject* worldcontextobject, ashootercharacter*Player) { if(Uworld* world = gengine->Getworldfromcontextobject (Worldcontextobject)) { for(Tactoriterator<ashootercharacter> it (world); it; + +it) { if(*it! =Player) { return*it; } } } returnnullptr;}
Unreal 4 C + + programming experience Summary