My head is smoking, the basics please again.

Hello friends of the code,

I am just desperate again.
It’s extremely annoying, you learn, try to understand, practice and do, especially with tutorials (I’ve had books before).

With the time you get the feeling that you could already do some things, then you have a creative idea, a very simple one and want to realize it, then nothing fits in front and back anymore. I now have the feeling that I don’t know anything anymore.
How do you proceed in principle? I will describe my learned way, please tell me where the mistake is.

Let us say I am in the AIController.

I google AIController and come to the Doc.unrealgine page where I get a list of all its functions that AIController can execute directly.
In the hierarchy above it says that AIController is the child of AActor. So I should be able to use all functions of AActor too, right?

So I want to create a VectorVariable that gets the location of AIController at the start of the game.


FVector Starting Point = GetActorLocation();

This simple thing doesn’t work, I don’t understand anything anymore, ask for help, I get involved and can’t do the simplest things myself.

Actor term is very broad. AIController is not a visible object, its location does not matter. What did you expect? :wink:
AIController derives from AController, AController derives from AActor.
AIController does not override the GetActorLocation() function, AController neither, so it uses an implementation from the AActor class.
AActor::GetActorLocation() returns location of RootComponent. If the AActor class instance does not have a RootComponent, a zero vector is returned

Thanks for answering Emaer, but I’m mainly interested in the general principle of working with C++ in Unreal.

I have described a little bit how I approach the functions, I would like to know how others do it or how to do it right?

Well, working with UE4 is not much different than working with other frameworks.
Generally, a lot depends on what kind of project you want to create.
To get to know the engine architecture better, it is worth taking the available templates one by one and modifying them, checking what and how it works.

It is also worth doing research on the internet to check if anyone has done something similar before, how did he do it, what did he use?
Then check what Unreal offers in this aspect, what is missing or maybe prefer a different approach?

And practice FTW. No tutorials will help if you don’t do it on your own.
More typing = more familiarity = more intuition = more knowledge = more confidence.

It’s hard to say more.

PS. To quickly check where and by how a function is used, TotalCommander (alt + f7-> search text) is enough :slight_smile:

So AAIController is an Actor, yes, but perhaps more importantly it’s an AController. In the docs these are described as “Non-physical controllers” which attached to an APawn (not just any AActor) by “possessing” them. So a particular character (pawn) could be controlled by an AIController or a PlayerController - they’re interchangeable, and can even change at runtime.

For your particular case, in the AController docs you’ll find the GetPawn() function, which should return the pawn (actor) which is actually being controlled.

Yep, this is the answer to your specific issue. Calling GetPawn() will return the pawn currently controlled by your AI controller, which can of course be set up easily in BP. As for your broader question, just being dogged in your approach is the only thing that’s been effective for me. Look through old forum posts related to your problem and you’ll quite often find something on here or the website. In thirty seconds I pulled this up, and after speed-reading each post in a few seconds, I saw the last one which contained my answer:…ontroller.html

You are getting discouraged because you are approaching it from a mindset of expectations. You expect things to make sense from your perspective, and they don’t, like your dilemma with not being able to pull up a function related to actors in an actor-derived file. I often feel the same way with Unreal – it’s not just you! But I just plugged in my problem and found out the way to make it work within minutes or less, regardless of how much it made complete sense to me. I am not saying anything negative about you – I’m simply saying that if you want to succeed at all with Unreal Engine and coding you’re going to need to be a bit more pragmatic in your attack. Taking the time to post a lot on here is also going to hold you back generally – I rarely do it unless I’m completely stuck AND can’t find anything ANYWHERE on any of the numerous forums (stack exchange, answers.unreal, here, the docs, tutorials, etc.).