# Custom UGameViewportClient: call function from blueprint

**URL:** <https://forums.unrealengine.com/t/custom-ugameviewportclient-call-function-from-blueprint/345579>\
**Category:** Blueprint\
**Tags:** calling-a-function, unreal-engine, UE4, CPP, Blueprint, question\
**Created:** [January 27, 2016, 8:28pm UTC](https://forums.unrealengine.com/t/custom-ugameviewportclient-call-function-from-blueprint/345579 "2016-01-27T20:28:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_69b87708](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_69b87708](https://forums.unrealengine.com/u/anonymous_user_69b87708)\
**Post date:** [January 27, 2016, 8:28pm UTC](https://forums.unrealengine.com/t/custom-ugameviewportclient-call-function-from-blueprint/345579/1 "2016-01-27T20:28:04Z")

</div>

I have created a custom `UGameViewportClient` and within it, I have a function called `Initialize`, that looks like this:

**.h**

```
UFUNCTION(BlueprintCallable, Category = "CustomGameViewportClient")
void InitializeCustomGameViewportClient();

```

**.cpp**

```
void UCustomGameViewportClient::InitializeCustomGameViewportClient()
{
		World = GetWorld();
		playerController = World->GetFirstPlayerController();
		myCharacter = UGameplayStatics::GetPlayerCharacter(World, 0);
		initialized = server.Initialize();
}

```

I cannot call this function from another blueprint because the it requires a target and complains:

> This blueprint is not a  
> CustomGameViewportClient, therefore  
> `Target` must have a connection.

I have also tried the `Set Timer by Function Name`, but the function just never gets called.

How can I call my function?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_69b87708](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_69b87708](https://forums.unrealengine.com/u/anonymous_user_69b87708)\
**Post date:** [January 27, 2016, 8:54pm UTC](https://forums.unrealengine.com/t/custom-ugameviewportclient-call-function-from-blueprint/345579/2 "2016-01-27T20:54:59Z")

</div>

Figured it out.

```
UGameViewportClient* gameViewport = GEngine->GameViewport;
((UCustomGameViewportClient*)gameViewport)->InitializeCustomGameViewportClient();

```

Another way is like this:

```
UCustomGameViewportClient* gameViewport = Cast<UCustomGameViewportClient>(GEngine->GameViewport);
gameViewport->InitializeCustomGameViewportClient();

```
