# What exactly is the "Stack" when defining custom thunks?

**URL:** <https://forums.unrealengine.com/t/what-exactly-is-the-stack-when-defining-custom-thunks/2382496>\
**Category:** C++\
**Tags:** uht, unreal-engine, question, CPP\
**Created:** [March 9, 2025, 10:22pm UTC](https://forums.unrealengine.com/t/what-exactly-is-the-stack-when-defining-custom-thunks/2382496 "2025-03-09T22:22:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kotaru\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kotaru\_1](https://forums.unrealengine.com/u/Kotaru_1)\
**Post date:** [March 9, 2025, 10:22pm UTC](https://forums.unrealengine.com/t/what-exactly-is-the-stack-when-defining-custom-thunks/2382496/1 "2025-03-09T22:22:49Z")

</div>

I get the idea behind thunks, but I’m struggling at understanding some details.

What exactly is the Stack? I mean I know **what** a stack is, but not how it’s being used in this context.

Sometimes it seems to be explained as the function execution stack, or maybe something with memory pointers to the parameters passed into the function, but it’s still very unclear to me.

---

<div class="post-metadata">

**Author:** ![Kotaru\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kotaru\_1](https://forums.unrealengine.com/u/Kotaru_1)\
**Post date:** [March 9, 2025, 10:40pm UTC](https://forums.unrealengine.com/t/what-exactly-is-the-stack-when-defining-custom-thunks/2382496/2 "2025-03-09T22:40:16Z")

</div>

NVM, this excerpt helped me understand it better:

"

- _ **Every** _ function call in BPVM (whether native function or script function/event) handled the same way:
- BPVM reads the related `UFunction*` that get linked in runtime we mentioned earlier, and reads its properties, like what kind of params it has and total size of its parameters.
- A memory block is allocated before function call happens (via `FMemory __Alloca__ Aligned` macro). Size of this memory block is equal to total size of the paramters of your function. This is what we call “parms memory”.
- When a function call happens, all the existing parameters in stack/graph that created for the function parameter is copied to said memory block. For example, if you have a local float variable in a BP function, and if thats plugged to a pin of a node that is a custom thunk, that float variable is copied to “parms memory” block BPVM allocated just before this step.
- This “parms memory” can be accessed through `FFrame::Locals`, because `FFrame::Locals` is a `uint8*` pointer that points to the allocated “parms memory”. When you use `PARAM_PASSED_BY_VAL` macros or use `Stack.StepCompiledIn<FProperty>(Object, &Thing)` you actually walk through `Locals`. This part is a bit confusing and it’s normal if you’re lost, but bear with me.

"

> <https://gist.github.com/intaxwashere/e9b1f798427686b46beab2521d7efbcf>

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [April 8, 2025, 10:40pm UTC](https://forums.unrealengine.com/t/what-exactly-is-the-stack-when-defining-custom-thunks/2382496/3 "2025-04-08T22:40:43Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
