10 Unreal Engine Tips

by on

Greetings,
Recently we switched to Unreal Engine 4 for our game development. Previously we used Unity, Panda, Godot, and SDL2 by itself.

The following is a list of issues that we have encountered so far and how we solved them.

1. Sprite appears brighter and faded.
The issue is most likely due to the sprite sheet texture itself, having an oddball transparency floating point conversion error.
However rather than having the artist redo the sprites you can fix this by increasing the RGBCurve value in the Source Texture settings under Adjustments, a value of 4 seems to be what gets it back to its original glory.

Bright Sprite  Sprite Normal

2. Figuring out how to C++ from Blueprints.
Unreal's documentation leaves a lot to be desired, and most of the examples you'll find are for Blueprints. Blueprints, in our opinion, also leave a lot to be desired, but the C++ extensibility is incredible in Unreal if you can figure out how to do things in C++.
Fortunately most of the time, you can open up the Blueprint graph, and most of the function calls that you see for a class will be identical in C++. So, Blueprint graphs are usually pretty good for finding what function you need to call in C++. Use it.

3. Applying force to a PaperSpriteActor.
Usually, you would have a RigidBody or something to apply force to but in Unreal everything is done by the renderer component. Seeing the renderer component in the blueprint graph is what brings us back to number 2 on the list. I noticed in the blueprint graph that the method was a member of the RendererComponent.

In your Tick function or wherever you are trying to apply force from you can do a GetRenderer()->ApplyImpulse(Vector), or whichever force action you are trying to use.

4. Using C++ or Blueprints.
If you're making a game in Unreal, you had better be able to do C++; we started off doing a mix in Blueprints and C++. That was a mistake, and it might be possible; however, it is far more comfortable in C++. Save for the Editor crashing when you make a mistake Unreal gives you a very gentle introduction to C++ and IMHO is a great place to start although this might be a biased opinion from someone that finds programming easy to understand no matter what the language is.

Blueprints do have their use they make assigning references and modifying other variable values very nice compared to having to recompile every time you want to change and for the most part that's all we use them for.

5. Playing music, sounds, and stopping them.
You'll see some recommend playing a sound using UGameplayStatics::PlaySound2D(...args); However, You're not going to be able to stop that precise sound.

What you want is to attach a UAudioComponent to an Actor, tell it to play the sounds and you can then tell it to stop playing the sound when you're finished with it.

For music, there is a looping checkbox you can tick when editing the imported file.

6. Attach an inherited component using C++.
I'll use a recent example. You want to attach a collider to your player character to detect if the player can grab a ledge:

Import required:

#include "Components/BoxComponent.h"

In your PlayerCharacter.h file:


UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collider, meta = (AllowPrivateAccess = "true")) class UBoxComponent* LedgeGrabBox;

 

In your PlayerCharacter.cpp file's constructor:


APlayerCharacter::APlayerCharacter() {


LedgeGrabBox = CreateDefaultSubobject<UBoxComponent>(TEXT("LedgeGrab"));
LedgeGrabBox->SetupAttachment(RootComponent);
// <snip> There's more you need for this to work as a ledge grab collider.


}

You'll notice in your Blueprint that there is now an inherited component for your LedgeGrab collider.

7. Editor only functions fail to compile when building a deployment.
Notably, this had happened when we tried to get the sprite's size, so far.

// Don't do this:
actorReference->GetRenderComponent()->GetSprite()->GetSourceSize();
actorReference->GetRenderComponent()->GetSprite()->GetSourceTexture();

// Do this:
FBoxSphereBounds b = actorReference->GetRenderComponent()->GetSprite()->GetRenderBounds();

It would be nice to get some Intellisense that says, only use for editor extensions! Or something similar.

8. TextRender font color is black.
You might be able to add a light, changing the material to an unlit material also works.

9. Flipbook Particle transparency.
When trying to add a thruster smoke effect the result was a black sprite box, adding the Result to the Emissive and we had a sprite but still a box, it was interesting.

The fix is described best with a picture. You need to change the material's blend mode to Translucent and the shading mode to Subsurface.

Then drag your texture object's pin into a FlipBook component's Texture (T2d) pin. Take the Result and drag it to the Base Color and the Emissive Color, Drag Alpha into Opacity and Subsurface Color.

That gives you an animated particle that is transparent and lit.

10. Collision overlap events.
In another post, we'll cover how to set up collision channels, presets, and what not. But we're going to keep this short, to generate overlap events in the preset you need to have overlap selected, not block, overlap. We set up channels and ignored anything that was not the channel that we wanted to overlap with because by default only the first overlap event is triggered on OnComponentBeginOverlap or so we have read.


 


Comments 0
No comments have been left yet.