# Problem with async graph tasks and Hierarchical Instanced Static Mesh Components

**URL:** <https://forums.unrealengine.com/t/problem-with-async-graph-tasks-and-hierarchical-instanced-static-mesh-components/140008>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 18, 2020, 10:19am UTC](https://forums.unrealengine.com/t/problem-with-async-graph-tasks-and-hierarchical-instanced-static-mesh-components/140008 "2020-03-18T10:19:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LordStuff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LordStuff](https://forums.unrealengine.com/u/LordStuff)\
**Post date:** [March 18, 2020, 10:19am UTC](https://forums.unrealengine.com/t/problem-with-async-graph-tasks-and-hierarchical-instanced-static-mesh-components/140008/1 "2020-03-18T10:19:42Z")

</div>

Hi there!

I followed this tutorial here: [https://wiki.unrealengine.com/Multi-…k\_Graph\_System](https://wiki.unrealengine.com/Multi-Threading:_Task_Graph_System)

And made Tasks that receive a Pointer to a HierarchicalInstancedStaticMeshComponent and a Pointer to a custom Actor Component and when the Task is executed and comes to this line:

```auto

// Task properties set through constructor
UHierarchicalInstancedStaticMeshComponent * HISM;
UDataComponent * Data;
// and in DoTask
HISM->AddInstance(FTransform(Data->GetLocation(idx)));

```

it crashes with an “Access violation writing location” message.

I am checking both for != nullptr.

I’ve read that it could be caused by the fact that I’m not using virtual method stubs but I tried making GetLocation virtual and it didn’t fix it.

Any ideas?

UPDATE:  
I split the line up into this:

```auto

// DoTask
FVector location = Data->GetLocation(idx);
FTransform transform = FTransform(location);
HISM->AddInstance(transform); // <--- Access violation writing location

```

And it only crashes in the last line.

Postet it on Answerhub as well: [https://answers.unrealengine.com/que…0178/view.html](https://answers.unrealengine.com/questions/950178/view.html)  
But as there are not many ppl doing c++ there I was hoping I’d get an answer in the forums.

UPDATE:  
 ![settingRefs.jpeg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/7/271f04350a3500837628f51fe33328b0bc9acf44.jpeg)  
In the first pic you can see the hierarchy, “VoxelDataRenderThread” is an Actor Component that creates the tasks.

It receives references to the other components (HISM and Data) as shown in the second pic. This happens before the tasks are created.

As of now, I tried moving the AddInstance call into the “VoxelDataRenderThread” (out of the Task) but it didn’t change anything.

Could there be a problem with the way I’m setting the references? Or is it just not possible to call AddInstance from a peer component and I need to somehow move it up once again, to the Actor for example?

---

<div class="post-metadata">

**Author:** ![LordStuff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LordStuff](https://forums.unrealengine.com/u/LordStuff)\
**Post date:** [March 18, 2020, 10:21am UTC](https://forums.unrealengine.com/t/problem-with-async-graph-tasks-and-hierarchical-instanced-static-mesh-components/140008/2 "2020-03-18T10:21:35Z")

</div>

Maybe if, from the task, I call a function of the class that created the task, and add the instance from there, so I don’t AddInstances from within the task but only trigger it from there?

EDIT: It’s not sufficient to make it from the custom actor component that creates the tasks. It crashes with the same error.

---

<div class="post-metadata">

**Author:** ![LordStuff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LordStuff](https://forums.unrealengine.com/u/LordStuff)\
**Post date:** [March 18, 2020, 1:15pm UTC](https://forums.unrealengine.com/t/problem-with-async-graph-tasks-and-hierarchical-instanced-static-mesh-components/140008/3 "2020-03-18T13:15:54Z")

</div>

UPDATE: Even when I convert the Render Thread to a child class of HISMC and the AddInstance code is inside a class function, there is an access violation…

Is it even possible to use graph tasks for this?

EDIT: If said function is a UFUNCTION and triggered from BP, everything works fine. If it’s triggered from the task, it crashes.

---

<div class="post-metadata">

**Author:** ![LordStuff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LordStuff](https://forums.unrealengine.com/u/LordStuff)\
**Post date:** [March 18, 2020, 5:16pm UTC](https://forums.unrealengine.com/t/problem-with-async-graph-tasks-and-hierarchical-instanced-static-mesh-components/140008/4 "2020-03-18T17:16:43Z")

</div>

Tried using ThreadSafe TSharedPtr; same result…

EDIT:  
Found another wiki article on the topic:

> **[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...

Is it even possible to trigger Render calls from tasks?

---

<div class="post-metadata">

**Author:** ![bambi186](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bambi186](https://forums.unrealengine.com/u/bambi186)\
**Post date:** [April 18, 2021, 6:14pm UTC](https://forums.unrealengine.com/t/problem-with-async-graph-tasks-and-hierarchical-instanced-static-mesh-components/140008/5 "2021-04-18T18:14:29Z")

</div>

Hi hi!  
Resing this thread since this is the closest one to my issue and clicking the link is no option since the new, community hosted wiki.  
Have you solved this issue? or found a walkaround?

---

<div class="post-metadata">

**Author:** ![LordStuff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LordStuff](https://forums.unrealengine.com/u/LordStuff)\
**Post date:** [September 1, 2021, 9:06pm UTC](https://forums.unrealengine.com/t/problem-with-async-graph-tasks-and-hierarchical-instanced-static-mesh-components/140008/6 "2021-09-01T21:06:07Z")

</div>

Sorry for the late answer to an even older thread!  
I fear I can’t really recall what I actually did back then. I looked up the old project that was still 4.24 and I think most of the code was commented.  
Probably I just went with the synchronous approach and called the logic from Blueprint. As it was an educational project without real performance requirements it was enough.

If you find out anything, I’d be happy if you post it here. I’d be really interested in how these things work in Unreal!
