# Paper2d sprite scale

**URL:** <https://forums.unrealengine.com/t/paper2d-sprite-scale/312426>\
**Category:** Asset Creation\
**Tags:** sprites, unreal-engine, CPP, question\
**Created:** [March 24, 2015, 8:15pm UTC](https://forums.unrealengine.com/t/paper2d-sprite-scale/312426 "2015-03-24T20:15:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![theonecalledtom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theonecalledtom](https://forums.unrealengine.com/u/theonecalledtom)\
**Post date:** [March 24, 2015, 8:15pm UTC](https://forums.unrealengine.com/t/paper2d-sprite-scale/312426/1 "2015-03-24T20:15:35Z")

</div>

What controls a paper 2d sprite size when generated by C++?

At the moment, in order to apply my own material, I’m duplicating a blueprint APaperSpriteActor. In the actor I’ve setup a sprite with my material.

```
	m_SpriteActor = smp_World->SpawnActorDeferred<APaperSpriteActor>(smp_Class, FVector::ZeroVector, FRotator(0.0f, 180.0f, -90.0f), smp_Owner);
	if (m_SpriteActor.IsValid())
	{
		FSpriteAssetInitParameters initParams;
		initParams.SetTextureAndFill(mp_Texture);
		UPaperSprite *pNewSprite = DuplicateObject<UPaperSprite>(m_SpriteActor->GetRenderComponent()->GetSprite(), m_SpriteActor.Get(), _T("DuplicatedSprite"));
		pNewSprite->InitializeSprite(initParams);
		m_SpriteActor->GetRenderComponent()->SetMobility(EComponentMobility::Movable);
		m_SpriteActor->GetRenderComponent()->SetSprite(pNewSprite);

```

This seems a bit convoluted but I couldn’t find a c++ interface to set my own material or change the sprite material to translucent. Once I resolve this I’m going to be rendering text and other shapes onto a texture for the sprite, which I’m mainly using as a method for rendering 2d at a depth in my scene.

I’m then using SetActorScale3D to scale the actor to fit a predefined 3d size. This works in essence but not practice as different textures have different resultant 3d sizes.

How is the sprite size calculated?

-

---

<div class="post-metadata">

**Author:** ![theonecalledtom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@theonecalledtom](https://forums.unrealengine.com/u/theonecalledtom)\
**Post date:** [March 24, 2015, 8:54pm UTC](https://forums.unrealengine.com/t/paper2d-sprite-scale/312426/2 "2015-03-24T20:54:36Z")

</div>

Looks like the pixels per unit is defaulting to 100. I can’t see how to set this in C++ however can create an extra scaling factor that when multiplied into my calculated actor scale gives me a sprite of the expected size.

```
		m_Scale.Set(100.0f / mp_Texture->GetSurfaceWidth(), 100.0f / mp_Texture->GetSurfaceHeight());

```

Voodoo? Yes. Functional? Yes. Shippable? Time will tell!

---

<div class="post-metadata">

**Author:** ![Manuzor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Manuzor](https://forums.unrealengine.com/u/Manuzor)\
**Post date:** [March 6, 2017, 1:17pm UTC](https://forums.unrealengine.com/t/paper2d-sprite-scale/312426/3 "2017-03-06T13:17:44Z")

</div>

If you don’t mind me asking, what did time tell you about the shippability of this solution? 🙂
