# Logging values gets me this error

**URL:** <https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551>\
**Category:** C++\
**Tags:** logging, unreal-engine, UE4, CPP, question\
**Created:** [July 2, 2018, 5:03pm UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551 "2018-07-02T17:03:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hemlock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hemlock](https://forums.unrealengine.com/u/Hemlock)\
**Post date:** [July 2, 2018, 5:03pm UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551/1 "2018-07-02T17:03:21Z")

</div>

I’m trying to log a string then an int value and it’s just not working. I have looked up answers but nothing is helping me at all so can someone please put my question to rest. I just want to log a string + int to screen. This is what I have so far.

```
		if (GEngine) {
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Number in the world: %s"), *iNumberOfBasicUnits);
		}

```

All that is logged is this

```
Number in the world: %s

```

I’m also getting an error message:

```
operand of '*' must be a pointer
```

---

<div class="post-metadata">

**Author:** ![Velrin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Velrin](https://forums.unrealengine.com/u/Velrin)\
**Post date:** [July 2, 2018, 5:26pm UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551/2 "2018-07-02T17:26:18Z")

</div>

Here is an example of how to log an int:

UE\_LOG(YourLog,Warning,TEXT(“MyCharacter’s Health is %d”), MyCharacter-\>Health );

Use %d instead of %s and don’t use a dereference \*.

---

<div class="post-metadata">

**Author:** ![Zilphy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zilphy](https://forums.unrealengine.com/u/Zilphy)\
**Post date:** [July 2, 2018, 5:29pm UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551/3 "2018-07-02T17:29:57Z")

</div>

You’re trying to print an int with string formatting it seems.

Try this instead:

```
         if (GEngine) {
             GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Number in the world: %d"), iNumberOfBasicUnits);
         }

```

However I’d recommend using UE\_LOG instead, but it won’t print to screen, it’ll print into your output log, like so:

```
         if (GEngine) {
            UE_LOG(LogTemp, Warning, TEXT("Number in the world: %d"), iNumberOfBasicUnits);
         }

```

Reference this documentation:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![Hemlock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hemlock](https://forums.unrealengine.com/u/Hemlock)\
**Post date:** [July 2, 2018, 8:58pm UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551/4 "2018-07-02T20:58:28Z")

</div>

That doesn’t work. it prints  
Number in the world: %d

---

<div class="post-metadata">

**Author:** ![Zilphy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zilphy](https://forums.unrealengine.com/u/Zilphy)\
**Post date:** [July 2, 2018, 10:35pm UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551/5 "2018-07-02T22:35:07Z")

</div>

Can you post your source code please?

---

<div class="post-metadata">

**Author:** ![Hemlock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hemlock](https://forums.unrealengine.com/u/Hemlock)\
**Post date:** [July 3, 2018, 4:31am UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551/6 "2018-07-03T04:31:24Z")

</div>

iNumberOfBasicUnits = aBasicUnit.Num();  
if ((iMaximumOfBasicUnit - iNumberOfBasicUnits \<= 10) && bCanSpawnBasicUnits == true) {

```
		//spawns more units without setting timer
		spawnMoreAi(EAiToSpawn::BasicUnit, iMaximumOfBasicUnit - iNumberOfBasicUnits);

		if (GEngine) {
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("number of basic units: %d"), iNumberOfBasicUnits);
		}
	}
```

---

<div class="post-metadata">

**Author:** ![Zilphy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zilphy](https://forums.unrealengine.com/u/Zilphy)\
**Post date:** [July 3, 2018, 9:23am UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551/7 "2018-07-03T09:23:32Z")

</div>

Try this:

```
if (GEngine) {
              GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf("Number in the world: %d"), iNumberOfBasicUnits);
          }

```

GEngine works a bit differently when you’re adding in values. I believe this code will work. I’m used to using UE\_Log and I’m making the assumption they work the same…which I don’t think is the case. In fact it says to use Fstring::Printf right in the documentation I posted when adding values to your string.

---

<div class="post-metadata">

**Author:** ![Hemlock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hemlock](https://forums.unrealengine.com/u/Hemlock)\
**Post date:** [July 3, 2018, 3:44pm UTC](https://forums.unrealengine.com/t/logging-values-gets-me-this-error/428551/8 "2018-07-03T15:44:34Z")

</div>

i tried it with UE\_LOG and it worked so i will just do that.
