GetWorld() no longer works in a Blueprint Library? [BETA 6]

Hey there,

I’m trying this right now in my custom Blueprint Library but GetWorld() cannot be found:

AQUBEPlayerController* PC = Cast(GEngine->GetFirstLocalPlayerController( GetWorld() ));

I’ve looked through the documentation with no joy :frowning:

Not sure why some of these functions require GetWorld() in BETA 6 whereas they didn’t require it in the previous builds.

Cheers,

Jon

It would be very nice to distinguish between

GetWorld()

and

GetFirstLocalPlayerController()

So can you do a test related to just GetWorld()

like DrawDebugLine?

and see if that works?

:slight_smile:

Rama

I’m not sure I’m following you?

DrawDebugLine(GetWorld(), …, …); won’t work as GetWorld() cannot be found.

My compiler output:
Private\Engine\QUBEBluePrintLibrary.cpp(15): error C3861: ‘GetWorld’: identifier not found

Jon

Ooooh

hee hee

no that’s not an error

that’s normal

BP Libraries are made of static functions based on a non-instanced UObject extended class called BlueprintFunctionLibrary.

you can’t call getworld() from such a function.

you have to pass in an AActor or get an actor using Object Iterator

You can then use all GetWorld Functions since it is likely they will share same world in the in-game instance.

Here’s some examples from my BP Library

case 1: get from input actor

case 2: use object iterator to find a player controller, assumes not used in Editor, only in game instance

Here’s link to my BP library, I included the CPP Source code in my plugin download
http://forums.epicgames.com/threads/977316-(33)Rama-s-Blueprint-Nodes-Plugin-For-You!-Float-as-Str-w-Precision-Ragdoll-Traces

#1

void UVictoryBPFunctionLibrary::Draw__Thick3DLineFromCharacterSocket(AActor* TheCharacter,  const FVector& EndPoint, FName Socket, FLinearColor LineColor, float Thickness, float Duration)
{
	ACharacter * AsCharacter = Cast(TheCharacter);
	if (!AsCharacter) return;
	if (!AsCharacter->Mesh) return;
	//~~~~~~~~~~~~~~~~~~~~
	
	//Get World
	UWorld* TheWorld = AsCharacter->GetWorld();
	if (!TheWorld) return;
	//~~~~~~~~~~~~~~~~~
	
	const FVector SocketLocation = AsCharacter->Mesh->GetSocketLocation(Socket);
	DrawDebugLine(
		TheWorld, 
		SocketLocation, 
		EndPoint, 
		FColor(LineColor), 
		false, 
		Duration, 
		0, 
		Thickness
	);
	
}

#2

void UVictoryBPFunctionLibrary::Draw__Thick3DLineFromSocket(USkeletalMeshComponent* Mesh, const FVector& EndPoint, FName Socket, FLinearColor LineColor, float Thickness, float Duration)
{
	if (!Mesh) return;
	//~~~~~~~~~~~~~~
	
	//Get an actor to GetWorld() from
	TObjectIterator Itr;
	if (!Itr) return;
	//~~~~~~~~~~~~
	
	//Get World
	UWorld* TheWorld = Itr->GetWorld();
	if (!TheWorld) return;
	//~~~~~~~~~~~~~~~~~
	
	const FVector SocketLocation = Mesh->GetSocketLocation(Socket);
	
	DrawDebugLine(
		TheWorld, 
		SocketLocation, 
		EndPoint, 
		FColor(LineColor), 
		false, 
		Duration, 
		0, 
		Thickness
	);
}

Hope this fully resolves your issue!

Rama

#Your Actual Goal

By the way, if your actual goal is just to get a local player controller within your static BP function,

here’s a function you can call any time anywhere, even having it as a BP node

APlayerController* YourBPLibrary::GetAQubePC()
{
    TObjectIterator Itr;
    if(!Itr) return NULL;
    return *Itr;
}

:slight_smile:

Rama

PS: If this fully resolves your question please check mark it :slight_smile:

Thanks Rama!

The Object Iterator is just the thing I was looking for!

The second solution seems the best for me. I already had the first solution before and changed it, but didn’t want to need to change the blueprints again by referencing an Actor.

Thanks!!! :smiley:

Jon