# Help Please VERY STUMPED? Key not setting, DebugMessage printing "0" to screen

**URL:** <https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [April 3, 2014, 2:44am UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711 "2014-04-03T02:44:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_cae9bcfa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cae9bcfa](https://forums.unrealengine.com/u/anonymous_user_cae9bcfa)\
**Post date:** [April 3, 2014, 2:44am UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/1 "2014-04-03T02:44:14Z")

</div>

Could really use some help/advice here. This Behavior Tree stuff isn’t really documented yet so having some trouble setting these keys properly. Also stumped as to why my DebugMessage is printing “0” in Blue color.

Behavior Tree  
 ![27a85c05c368441fa7a9d1bcb23ee95c078f45d4.jpeg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/7/a/27a85c05c368441fa7a9d1bcb23ee95c078f45d4.jpeg)

Blackboard Key  
 ![d5d9e69a7aed51d92635ee551b4a6ab88e302cb3.jpeg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/5/d/d5d9e69a7aed51d92635ee551b4a6ab88e302cb3.jpeg)

in BTService\_FindAndDetectPlayer.cpp

```auto

void UBTService_FindAndDetectPlayer::ReceiveTick(AActor * OwnerActor, float DeltaSeconds)
{
	AActor * PtrToAnActor = NULL;
	UBehaviorTreeComponent* MyComp = Super::CurrentCallOwner;
	if (MyComp == NULL)
	{
		return;
	}

	for (TObjectIterator<AActor> Itr; Itr; ++Itr)
	{
		//any coditions on choosing which actor, such as name or other things;

		if (Itr->GetName()=="PlayerDetTest")
		{
			//Assign your created Ptr to actual Actor in game world
			PtrToAnActor = *Itr;
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "AM I WORKING?"); //WHY THE F IS THIS PRINTING "0"??
			MyComp->GetBlackboardComponent()->SetValueAsObject(PointKey.SelectedKeyID, PtrToAnActor); //PointKey is set in the BehaviorTree to Player...I have TargetPoint named "PlayerDetTest" in level.
			return;
		}

	}

	//no actor found, return
	if (!PtrToAnActor) return;
}

```

in .h

```auto

UCLASS()
class UBTService_FindAndDetectPlayer : public UBTService_BlueprintBase
{
	GENERATED_UCLASS_BODY()

	virtual void ReceiveTick(AActor * OwnerActor, float DeltaSeconds) OVERRIDE;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Blackboard)
	FBlackboardKeySelector PointKey;
};

```

---

<div class="post-metadata">

**Author:** ![Solid\_Snake](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Solid\_Snake](https://forums.unrealengine.com/u/Solid_Snake)\
**Post date:** [April 3, 2014, 7:45am UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/2 "2014-04-03T07:45:42Z")

</div>

All literal text strings should be wrapped with the macro “TEXT”. This is because all text / strings in Unreal Engine are unicode.

```auto

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("AM I WORKING?"));

```

However, if you want to be on the super safe side, you could also wrap the text in an FString since that is actually the parameter type the function is looking for.

```auto

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString(TEXT("AM I WORKING?")));

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_cae9bcfa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cae9bcfa](https://forums.unrealengine.com/u/anonymous_user_cae9bcfa)\
**Post date:** [April 3, 2014, 12:13pm UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/3 "2014-04-03T12:13:16Z")

</div>

> [@Solid Snake;11344](#):
>
> All literal text strings should be wrapped with the macro “TEXT”. This is because all text / strings in Unreal Engine are unicode.
> 
> ```auto
> 
> GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("AM I WORKING?"));
> 
> ```
> 
> However, if you want to be on the super safe side, you could also wrap the text in an FString since that is actually the parameter type the function is looking for.
> 
> ```auto
> 
> GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString(TEXT("AM I WORKING?")));
> 
> ```

Yeah I had it like this before. I forgot to change it back. With TEXT(“”) and “” it prints 0 either way. It works fine when I call this directly from an Actor. Is this the same as the “Print String” function in Blueprint?

Any input on the rest of the code and why it’s not setting Player key to anything?? I wonder if my Blackboard pointer is wrong…

---

<div class="post-metadata">

**Author:** ![Daniel\_Broder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daniel\_Broder](https://forums.unrealengine.com/u/Daniel_Broder)\
**Post date:** [April 4, 2014, 12:49am UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/4 "2014-04-04T00:49:20Z")

</div>

Are you sure you are hitting the AddOnScreenDebugMessage? I suspect that blue zero may be coming from some other source since you are printing in yellow there. Make sure you set a breakpoint and that you actually hit the debug message.

If you aren’t getting inside that conditional, the problem may be with the “if (Itr-\>GetName()==“PlayerDetTest”)” I haven’t double-checked, but I’m not sure if that syntax works properly since you don’t have the string literal wrapped in the TEXT macro (TEXT(“PlayerDetTest”)).

If your conditional is firing, let me know and I’ll take another look at that specific function. (I don’t normally use that, and we’re trying to eliminate the use of global variables in the engine generally.) You might try calling the Blueprint PrintString function instead, which you can find in KismetSystemLibrary.h. You’d call it like this:

```auto

UKismetSystemLibrary::PrintString(PtrToAnActor, FString(TEXT("AM I WORKING?")), true, true);

```

WorldContextObject is any UObject from which a world can be retrieved. For example, any Actor would be fine, which is why I passed in the PtrToAnActor which you’d just set (and was not NULL). I can’t recall all of the other classes that are supported, but I suspect Components are supported because you can get an Actor (owner) from the component. Many other classes are also supported.

(You can specify the yellow color as an optional final parameter if you like.)

A few more comments:  
Using TObjectIterator is potentially very costly in terms of performance, because you’ll iterate over every actor in the game! If it’s a large number of actors, that can really add up. It’s generally better to pick as specific a class as you can, depending on what the actor type you’re trying to find. For instance, if you were iterating over characters, use TObjectIterator.

Lastly, it looks like you accidentally left a line in your function from an earlier version, because this code isn’t doing anything:

```auto

//no actor found, return
if (!PtrToAnActor) return;

```

You return anyway right after that line. So I presume at some point you had other code there, but you can remove the line now.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_cae9bcfa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cae9bcfa](https://forums.unrealengine.com/u/anonymous_user_cae9bcfa)\
**Post date:** [April 4, 2014, 2:14am UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/5 "2014-04-04T02:14:42Z")

</div>

> [@;11845](#):
>
> Are you sure you are hitting the AddOnScreenDebugMessage? I suspect that blue zero may be coming from some other source since you are printing in yellow there. Make sure you set a breakpoint and that you actually hit the debug message.
> 
> If you aren’t getting inside that conditional, the problem may be with the “if (Itr-\>GetName()==“PlayerDetTest”)” I haven’t double-checked, but I’m not sure if that syntax works properly since you don’t have the string literal wrapped in the TEXT macro (TEXT(“PlayerDetTest”)).
> 
> If your conditional is firing, let me know and I’ll take another look at that specific function. (I don’t normally use that, and we’re trying to eliminate the use of global variables in the engine generally.) You might try calling the Blueprint PrintString function instead, which you can find in KismetSystemLibrary.h. You’d call it like this:
> 
> ```auto
> 
> UKismetSystemLibrary::PrintString(PtrToAnActor, FString(TEXT("AM I WORKING?")), true, true);
> 
> ```
> 
> WorldContextObject is any UObject from which a world can be retrieved. For example, any Actor would be fine, which is why I passed in the PtrToAnActor which you’d just set (and was not NULL). I can’t recall all of the other classes that are supported, but I suspect Components are supported because you can get an Actor (owner) from the component. Many other classes are also supported.
> 
> (You can specify the yellow color as an optional final parameter if you like.)
> 
> A few more comments:  
> Using TObjectIterator is potentially very costly in terms of performance, because you’ll iterate over every actor in the game! If it’s a large number of actors, that can really add up. It’s generally better to pick as specific a class as you can, depending on what the actor type you’re trying to find. For instance, if you were iterating over characters, use TObjectIterator.
> 
> Lastly, it looks like you accidentally left a line in your function from an earlier version, because this code isn’t doing anything:
> 
> ```auto
> 
> //no actor found, return
> if (!PtrToAnActor) return;
> 
> ```
> 
> You return anyway right after that line. So I presume at some point you had other code there, but you can remove the line now.
> 
> I hope this helps!

My ReceiveTick function isn’t even running. The blue 0 was coming from somewhere else…still not sure as I have no other print calls anywhere. That issue has been resolved.

I have overloaded ReceiveTick in a class extended from ACharacter and that ReceiveTick function worked just fine.

One thing I have noticed, is that REGARDLESS of the content of BTService\_FindAndDetectPlayer, it always tries to tick innately through the Behavior Tree… I have verified this by using both an empty BTService\_Blueprint BP and removing all functions other than the constructor from my .cpp. It looks like Services tick by default at a rate set in the editor.

Am I correct in assuming that the ReceiveTick function is “ticked” automatically by the engine without needing to be called? (like BeginPlay())

---

<div class="post-metadata">

**Author:** ![phoboz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phoboz](https://forums.unrealengine.com/u/phoboz)\
**Post date:** [April 4, 2014, 3:36am UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/6 "2014-04-04T03:36:01Z")

</div>

1. Don’t make 2 threads about the same thing 😉
2. Try adding **PrimaryActorTick.bCanEverTick = true** in the class constructor.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_cae9bcfa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cae9bcfa](https://forums.unrealengine.com/u/anonymous_user_cae9bcfa)\
**Post date:** [April 4, 2014, 2:14pm UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/7 "2014-04-04T14:14:51Z")

</div>

UPDATE: BTService\_FindAndDetectPlayer is not even showing up in the editor. This is what is going on.

I created a blueprint for BTService named FindAndDetectPlayer and after deleting this, it still shows up under Services. It’s basically an empty Service that does nothing.

**Unfortunately this leads to another problem.** …Why isn’t code extended from BTService\_BlueprintBase showing up as a Service inside the Behavior Tree?

---

<div class="post-metadata">

**Author:** ![IceWraith](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IceWraith](https://forums.unrealengine.com/u/IceWraith)\
**Post date:** [April 4, 2014, 2:59pm UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/8 "2014-04-04T14:59:58Z")

</div>

First of all, please do not use \*\_BlueprintBase classes when creating native c++ implementations. Those, as name suggest, are wrappers for blueprint functionality and some functions may not be even called without being implemented through blueprint objects. For example, Receive events won’t be called if object don’t have their blueprint implementation - performance reasons.

Try creating your service using either UBTService or UBTService\_BlackboardBase (built in support for single blackboard key), the same rules goes for task and decorators nodes. Tick function can be implemented using TickNode() override (will be called with requested interval, instead of every frame).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_cae9bcfa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cae9bcfa](https://forums.unrealengine.com/u/anonymous_user_cae9bcfa)\
**Post date:** [April 4, 2014, 3:13pm UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/9 "2014-04-04T15:13:13Z")

</div>

> [@;12163](#):
>
> First of all, please do not use \*\_BlueprintBase classes when creating native c++ implementations. Those, as name suggest, are wrappers for blueprint functionality and some functions may not be even called without being implemented through blueprint objects. For example, Receive events won’t be called if object don’t have their blueprint implementation - performance reasons.
> 
> Try creating your service using either UBTService or UBTService\_BlackboardBase (built in support for single blackboard key), the same rules goes for task and decorators nodes. Tick function can be implemented using TickNode() override (will be called with requested interval, instead of every frame).

That actually makes too much sense 😃

It would appear that I went full potato here. The BTTasks I have created are working fine…and consequently, those are \_BlackboardBase’s

Will try this out as soon as I can. Thanks.

---

<div class="post-metadata">

**Author:** ![Daniel\_Broder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daniel\_Broder](https://forums.unrealengine.com/u/Daniel_Broder)\
**Post date:** [April 4, 2014, 3:27pm UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/10 "2014-04-04T15:27:27Z")

</div>

Oops! Somehow I missed that inheritance point; I got bogged down in your cpp and didn’t pay enough attention to the header. Sorry about that.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_cae9bcfa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cae9bcfa](https://forums.unrealengine.com/u/anonymous_user_cae9bcfa)\
**Post date:** [April 4, 2014, 3:31pm UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/11 "2014-04-04T15:31:47Z")

</div>

> [@;12179](#):
>
> Oops! Somehow I missed that inheritance point; I got bogged down in your cpp and didn’t pay enough attention to the header. Sorry about that.

So did I…it has been driving me up the wall. I didn’t realize that it was an old empty blueprint showing up in the editor until I made a project exclusively to test BTService…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d4195eea](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d4195eea](https://forums.unrealengine.com/u/anonymous_user_d4195eea)\
**Post date:** [April 8, 2014, 12:55pm UTC](https://forums.unrealengine.com/t/help-please-very-stumped-key-not-setting-debugmessage-printing-0-to-screen/1711/12 "2014-04-08T12:55:09Z")

</div>

It’s very simply ,first you should read couple of books about C++ ,start with The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt and David Thomas than Effective C++ and More Effective C++ by Scott Meyers ,and other staff like that .Maybe than you can understand code more clearly also it will increase your basic “brain level” . And when you’ll be ready to code ,think whether it worth to do this or not…cuz maybe you just get nothing at the end ,so why you need all of these efforts.Who knows…
