Multiple questions from one new beginner...

  1. Confused why this isn’t working:


RunSpeed = 600.0f;
WalkSpeed = 200.0f;
GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;


No errors, just isn’t changing the walk speed.

  1. How to access world from cpp file
    Would it be something like:

#include <UEWorld>

?

I’m also new to C++. I believe you have to get your character’s movement component and declare it as a pointer. Here’s the code I came up with, and it works:


UCharacterMovementComponent* MyMovement;
MyMovement = FindComponentByClass<UCharacterMovementComponent>();
MyMovement->MaxWalkSpeed = 100.f;

Not sure about the world thing.

When I need to access the world, I just get the reference from something that has a valid GetWorld().

In my case, I had a UObject-derived class (GameManager) that needed a reference to the world. To get it, I override GameManager’s GetWorld() (which it inherits from UObject) to have it reference TextUI, which is a blueprint class and thus has a valid GetWorld().

GameManager.h


	//Begin UObject interface
	virtual class UWorld* GetWorld() const override;
	//End UObject interface

GameManager.cpp


UWorld* UGameManager::GetWorld() const
{
	if (TextUI != nullptr)
		return TextUI->GetWorld();
	else
		return nullptr;
}

That should work, but it’s possible where you are doing those changes is causing them to get stomped by the incoming data for those fields that is set through the editor. Try moving the code to some place like PostLoad, or elsewhere.

If you are referencing a UObject/Actor, you can simply call “GetWorld()” from the UObject which will get you its’ World. Otherwise you can include “Engine/Engine.h” and use “GEngine->GetWorld()” which should get you the world as well (normally there is only 1 world so this is probably fine - the exception being an Editor session in which case there could be multiple worlds).

Calling “GetWorld()” from a UObject you already have a reference to, is by far the safest/easiest way.

Thank you very much.
As for the GetWorld() part, would then accessing parts be like this?


GetWorld()->APawn

?