Download

Moving from UDK to UE4(pointers)

Hi guys…

I started learning Unreal Script 3 months back and was kind of ok with it. When UE4 got released I decided to switch engines. But now I am feeling as if I hit a wall. I need little help in understanding pointers. Generally the documentation and the wiki didn’t help me a lot. I know what c++ pointers are though.

Here is a small code from 3rd person which I want to start learning from.


UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
	TSubobjectPtr<class USpringArmComponent> CameraBoom;

From what I understood, this creates a pointer of the class SpringArmComponent which


 * This component tried to maintain its children at a fixed distance from the parent,
 * but will retract the children if there is a collision, and spring back when there is no collision.

I need help to understand what this do. And how does “->” work…


	// Create a camera boom (pulls in towards the player if there is a collision)
	CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
	CameraBoom->AttachTo(RootComponent);
	CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character	
	CameraBoom->bUseControllerViewRotation = true; // Rotate the arm based on the controller

And this part



	// Create a follow camera
	FollowCamera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FollowCamera"));
	FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation


See this Wiki thread. Rama explained pointers extremely well including why we should use it and the advantages.

He also explains about those signs like “->” and “::” etc.

I had read it I still had doubts.

Like what is


CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));

Mostly from what I understand, it creatures a instance of the class SpringArmComponent

And here,


CameraBoom->TargetArmLength = 300.0f;

CameraBoom-> points to the data location of TargetArmLength in the instance class that was created. Am I correct?

Pointerb it self is just addrress to instance on varable by using “.” You diracly refereing to pointer or object instance direcly (if its not pointer), when you use -> you refering to what pointer point to. Either way intelisence in VS2013 should red out if you use wrong symbol

Hmm didn’t understand properly what you said.


UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
	TSubobjectPtr<class USpringArmComponent> CameraBoom;

This basically creates a variable CameraBoom , this is done in header (.h) file.


// Create a camera boom (pulls in towards the player if there is a collision)
	CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
        CameraBoom->AttachTo(RootComponent);
	CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character	
	CameraBoom->bUseControllerViewRotation = true; // Rotate the arm based on the controller
	

This creates a subobject and attaches to the root component of your actor.
Last two lines are simply settings for the ArmComponent.


// Create a follow camera
	FollowCamera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FollowCamera"));
	FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation

Obviously these lines create a camera and attach it to the ArmComponent.

Now what happens here is you’re simply adding a camera to your character,
if you open the editor, open the blueprint for the default template character,
switch to “Components” tab, and there you shall see a camera above the character,
and a red line pointing from camera to the character.
Well this is same thing, and the red line is TargetArmLength , it defines the distance and angle from ArmComponent to the camera.


->

This sign means it points to a variable of created object(s).