# Games crashes when calling a function from another actor class

**URL:** <https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009>\
**Category:** Getting Started & Setup\
**Tags:** actor, unreal-engine, crash, functions, question, calls\
**Created:** [March 28, 2021, 4:41pm UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009 "2021-03-28T16:41:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7c355ee2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7c355ee2](https://forums.unrealengine.com/u/anonymous_user_7c355ee2)\
**Post date:** [March 28, 2021, 4:41pm UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/1 "2021-03-28T16:41:58Z")

</div>

Hello,

When I call a function of an actor by another actor, my game crashes. Let’s say actorA call a SetActorTickEnabled() function of actorB and my game crashes.

 ![333927-cppfile.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/7/c/47c978456f635d1ab8be0e1af691f1db43f2acbf.png)

Thank you

---

<div class="post-metadata">

**Author:** ![GrumbleBunny](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GrumbleBunny](https://forums.unrealengine.com/u/GrumbleBunny)\
**Post date:** [March 28, 2021, 8:29pm UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/2 "2021-03-28T20:29:52Z")

</div>

Could BackAndForthActor be nullptr at any point? Maybe wrap the call in an if statement.

---

<div class="post-metadata">

**Author:** ![ACBYTES](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ACBYTES](https://forums.unrealengine.com/u/ACBYTES)\
**Post date:** [March 29, 2021, 6:19am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/3 "2021-03-29T06:19:39Z")

</div>

Are you sure your pointer is really pointing to an actor? How have you set the pointer to point to the actor? If this script is being used on a Blueprint class, you probably aren’t able to point to an actor unless it’s being used inside a scene and the pointer is being altered inside the scene.

If you’re trying to set the pointer using BP nodes, you should set it to `BlueprintReadWrite`.

If you’re straightly using the class, then I’m guessing that the class is inheriting from AActor as you said it’s an actor, remember to assign the actor through engine’s internal scene combo-box.

If it’s something else, maybe share the error as well and we’ll find it out but I’m mostly sure that your pointer is `nullptr`.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7c355ee2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7c355ee2](https://forums.unrealengine.com/u/anonymous_user_7c355ee2)\
**Post date:** [March 29, 2021, 10:10am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/4 "2021-03-29T10:10:54Z")

</div>

Thank you for your reply.  
Yes it’s a null pointer, is there a way to fix it?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7c355ee2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7c355ee2](https://forums.unrealengine.com/u/anonymous_user_7c355ee2)\
**Post date:** [March 29, 2021, 10:11am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/5 "2021-03-29T10:11:16Z")

</div>

Thank you for your reply. Yes it’s a null pointer, is there a way to fix it?

---

<div class="post-metadata">

**Author:** ![GrumbleBunny](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GrumbleBunny](https://forums.unrealengine.com/u/GrumbleBunny)\
**Post date:** [March 29, 2021, 11:24am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/6 "2021-03-29T11:24:26Z")

</div>

Are you setting it somewhere else in code?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7c355ee2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7c355ee2](https://forums.unrealengine.com/u/anonymous_user_7c355ee2)\
**Post date:** [March 29, 2021, 11:29am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/7 "2021-03-29T11:29:51Z")

</div>

No, I have only declared the pointer to ABackAndForthActor class, like this:

ABackAndForthActor \* BackAndForthActor;

that’s it, in the cpp file I use BackAndForthActor-\>function() to call a function and it crashes

---

<div class="post-metadata">

**Author:** ![GrumbleBunny](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GrumbleBunny](https://forums.unrealengine.com/u/GrumbleBunny)\
**Post date:** [March 29, 2021, 12:22pm UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/8 "2021-03-29T12:22:05Z")

</div>

So that line: ABackAndForthActor \* BackAndForthActor; just declares a pointer to an instance of ABackAndForthActor, you need to spawn on somewhere and get a reference to it.

You can either do this in this class somewhere using GetWorld()-\>SpawnActor

Or you could spawn it somewhere else / put one in the level in the editor and get a reference to it, eg with something like UGameplayStatics::GetActorOfClass

---

<div class="post-metadata">

**Author:** ![ACBYTES](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ACBYTES](https://forums.unrealengine.com/u/ACBYTES)\
**Post date:** [April 3, 2021, 7:42am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/9 "2021-04-03T07:42:13Z")

</div>

You should set it to point to an actor in the engine or from another code if you are pointing to an actor. Drag and drop an instance of your actor into your preferred level and under your script menus, you’ll see some drop menus that will show actors to you. From there, select your preferred actor.

If you’ve made a BP instance out of your class and you’re trying to set the pointer using BP nodes, you should set the actor’s `UPROPERTY` to `BlueprintReadWrite`. The , you’ll be able to say `Set BackAndForthActor` and then you’ll be able to set your pointer up.

---

<div class="post-metadata">

**Author:** ![ACBYTES](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ACBYTES](https://forums.unrealengine.com/u/ACBYTES)\
**Post date:** [April 3, 2021, 7:43am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/10 "2021-04-03T07:43:03Z")

</div>

There are so many ways to setup your pointer.

You can either get your actor instantiated through code that you can either instantiate using a custom AActor class that you have created, or you can get a reference to one of your actor assets by using the normal `UPROPERTY(EditAnywhere) AActor* ActorAsset`.

If you already have it in a level, drag and the current actor class to the level you want and select your script. From there, you can use the drop-down menu to point to the actor you have in your level.

If that actor exists as a `ChildActorComponent` in a blueprint class and you want to setup your pointer in a blueprint class, you can also use the blueprint nodes to setup your pointer by adding `BlueprintReadWrite` to your `BackAndForthActor`'s `UPROPERTY`. Then you can use the `Set BackAndForthActor` node to setup your actor.

As I said, there are many ways to do this. See which you’d like to use.

---

<div class="post-metadata">

**Author:** ![Mynkela](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mynkela](https://forums.unrealengine.com/u/Mynkela)\
**Post date:** [July 30, 2021, 6:05am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/11 "2021-07-30T06:05:30Z")

</div>

Because : the class variable “Illegal TEXT reference to a private object in external package”  
Very Sufficient way to solving this  
Use `UPROPERTY(EditAnywhere) TSoftObjectPtr<ABackAndForthActor> BackAndForthActor;`  
Chance class variable Pointer\* to **TSoftObject\<\>**

---

<div class="post-metadata">

**Author:** ![Mynkela](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mynkela](https://forums.unrealengine.com/u/Mynkela)\
**Post date:** [July 30, 2021, 6:19am UTC](https://forums.unrealengine.com/t/games-crashes-when-calling-a-function-from-another-actor-class/481009/12 "2021-07-30T06:19:03Z")

</div>

Remember its Work when  
1: ABackAndForthActor Actor exist on Map (`ABackAndForthActor != NULL`)  
2: Declare/Set the Actor on BP UPROPRTY() //Select on Map or `BackAndForthActor = Cast<ABackAndForthActor>(UObject::GetClass());`
