Trouble with programming.

I’ve been trying to read up on the basics to programming in UE4, but it seems like a lot of the tutorials, while they are good- don’t really break down what you’re doing, just give you an overview of what code to use to achieve something.

For example, here’s some code from C++ Programming How-To 1. | Customize a Pawn


// Create a dummy root component we can attach things to.

RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));

// Create a camera and a visible object

UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));

OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));

// Attach our camera and visible object to our root component. Offset and rotate the camera.

OurCamera->AttachTo(RootComponent);

OurCamera->SetRelativeLocation(FVector(-250.0f, 0.0f, 250.0f));

OurCamera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));

OurVisibleComponent->AttachTo(RootComponent);

For me, a lot of this gets confusing and tedious.

RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT(“RootComponent”));
I’ve seen CreateDefaultSubobject a lot now, but rather than being told to use it I’d like explanation on what it does. “A dummy root component”, okay- well I’ve also seen this written as PCIP.CreateDefaultSubobject- well what’s the difference? I’m still unsure as to what PCIP even is, because it was simply copypasted into the tutorial I was watching.

UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT(“OurCamera”));

Why is this a pointer? I just think that I’d never be able to remember to simply do these things if I wasn’t sure why.
I’m sure a lot of you are pretty skilled in this, and I just seem like an idiot for posting this. That’s okay- but does anyone know where I should go to just get a tutorial that starts from square one?

Welcome to computer programming, where solving confusing and tedious puzzles is what we do all day!

Does this help? https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/FObjectInitializer/CreateDefaultSubobject/3/index.html

If not, do you in general know how the Unreal object/component system works? Have you worked through the general tutorials on the structure of the engine?

This means that you have a specific object instance called PCIP. In the code, higher up, you should see where it is declared, to figure out what it does.

When the member function is used without a particular scope, it has to be used within a class/subclass that defines the function, so typically a subclass of FObjectInitializer.

Looking at your question another way: It seems you’re trying to learn three things at once. You’re trying to learn how to program in C++, you’re trying to learn how to develop in a large code base, and you’re trying to learn the specifics of the Unreal Engine. This is a bit like trying to learn Latin and Mathematics at the same time, by reading a Mathematics textbook written in Latin. In the end, you may get where you’re going, but it might be more efficient to first do one, then the other.

Hello Sheeplie

Please pardon the Veteran apparently on a snarky day (but he is right). Yes programming is confusing and tedious and there is a lot to learn, and there is a lot to research, and there area lot of tutorials who do not take the time to actually explain from a starting perspective. But we have all been there. For us who have been using UE4 from the launch (or even older UE tools) we have managed to see the progression of the engine over time and know how things change. Unfortunately anyone coming into it right now must dig through (what I can only imagine is a ) sea of obsolete YouTube videos from previous versions without knowing that you are working on obsolete versions of code. The code does not change much but it does change as things are obsoleted for better implementations. So concepts that are no longer applicable such as the PCIP from versions before 4.6 or 4.7 actually do not work and result in much more confusion than some of us veterans realize to Newbies to UE4 C++

Unfortunately I cannot give you any better advice on how to learn to program UE4 other than to dig deep and hunker down, learn the objects by viewing the documentation, learn from tutorials from credible sources (such as the UE4 site itself) and augment that with specialized videos on YouTube. Epic is usually pretty good at going back to their previous training seriese and annoting them so I strongly suggest starting with their training videos. It will take time but give it 6 months and you should have a decent idea of most of the concepts. Give it a year and you should be quite knowledgeable. My BIGGEST suggestion is start your own project. You can start small just to learn and reinforce the basics, then force yourself to tackle bigger and bigger problems such as networking and replication. Don’t be afraid to experiment. Though I will make an additional note that this is assuming you already HAVE a programming back ground as far as the time frames go… it may take you longer if you are just getting into programming period I suggest learning the basics of C++, Object Oriented Principals, and then diving into UE4 coding as it is NOT trivial.

Do the Quick Start Videos

Become Familar with Actor, PlayerController, Pawn, ActorComponent, and UObject

Overview the C++ Programming Guide

Get Familiar with the Game Framework

Become Familar with the other UE4 Libraries

Become Familiar with the Source Code

If you are just starting Programming you can Learn from many languages that are “like” C++ such as C# or Java. The Concepts are similar but you may enjoy learning from these more because of their “higher level”, but the syntax (what you write) is very similar to C++ with a few caveats. For instance with both C# and Java it is a bit easier to write code with a GUI as GUI is not a native library for C++.

Anyway… that’s my advice… oh and one more thing DON’T BE AFRAID TO ASK QUESTIONS. I have asked a TON of good and stupid questions on answer hub and the forums. It’s all part of the process of learning.

Thanks guys. Does this mean that starting with the earlier parts of the UE4 guide before just the stuff about programming will help me understand what I’m actually doing when it comes to programming?

From my own experience I can say that working with UE4 is primarily trial and error. There are lots of little tricks and catches that you just can’t figure out on your own, or at least if you do it can take a very long time. What little documentation there is for C++ in the engine (there is a lot for blueprints) is often outdated and not that useful.

Your experience so far sounds quite normal - there isn’t anything wrong with you - it’s a very steep learning curve and can be very frustrating trying to get even the simplest things working. Having said that, I’ve found that after a few months of insane frustration things are now a lot easier. So it does get better… whether that is worth it is another question.

It is useful to read the general documentation about how Actors, Objects, etc all fit together, because that general stuff hasn’t changed very much. Any specific documentation however (ie, code) may well be obsolete.

I would say you don’t need to know everything in the editor just the basic stuff (at first). When I first started learning UE4 I began with the basics of the editor itself. I learned the basic moving around and blocking in things, then I learned blueprints and materials. Then I did the C++ tutorials. What you do in Code Affects the Editor so knowing the relationship between the code, the editor, and blueprints is extremely useful/important. Epic has done a lot to make this easier which is why I suggest running through the getting started series:

None of this comes overnight it takes time, dedication, and you will probably find yourself frustrated. Then the more you do, the more natural it will become until you are building bigger and more complex things. Took me 3 months to really start getting it. By 6 months I had a decent grasp on many of the coding structures. By a year I could pretty much build anything (with a few exceptions) but that is why you always keep learning and pushing forward.

What everyone above said is right. Even if you know C++ you can get mind-bombed frequently with the logic especially if you’re not used to certain design patterns. We use CreateDefaultSubobject because prior to that you just have a pointer such as UStaticMeshComponent* a pointer must point to an existing object or your program is undefined when you dereference it ‘->’. So CreateDefaultSubobject creates the object and returns a pointer to it which we store and do work on.

Right- but why does it need to be a pointer?

See, the top one is a pointer, but the second one is just a normal old variable. But they both have the -> operator used on them, which I’m guessing dereferences here.

Well, earlier on in that tutorial, OurVisibleComponent is declared as:



UPROPERTY(EditAnywhere)
USceneComponent* OurVisibleComponent;


so it is indeed a pointer as well, not a normal old variable. Which makes sense of course, otherwise the -> notation would be gravely out of place.

Any significantly large object you want to have control over is going to be passed by a pointer(*) or a reference (&), this is because under the hood both are simply passing around an address (which is a simple 32/64 bit value) of where that object lives in memory and not doing an object copy which is what would happen if you tried to pass it normally through the = operator. It also allows UE to manage the lifetime of the object where values allocated on the stack are destroyed when they go out of scope (but that’s a bit more advanced).

Here’s a good video if you aren’t familiar with pointers.