# C++ Actor class array search

**URL:** <https://forums.unrealengine.com/t/c-actor-class-array-search/358730>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 27, 2016, 3:49am UTC](https://forums.unrealengine.com/t/c-actor-class-array-search/358730 "2016-05-27T03:49:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_93d485201](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_93d485201](https://forums.unrealengine.com/u/anonymous_user_93d485201)\
**Post date:** [May 27, 2016, 3:49am UTC](https://forums.unrealengine.com/t/c-actor-class-array-search/358730/1 "2016-05-27T03:49:03Z")

</div>

I’m wondering how I might go about scanning an array for a specific class. Here’s the code I want to do in BP:

 ![92192-contains.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/2/a1209dc9f07f1ca6a408f8e405c0073dfc9a8ea9.png)

(Basically the “Contains” node just searches an array for a given input which is the bottom)  
I’ve tried this:

```
//.H file
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Element)
		TArray<TSubclassOf<AActor>> ClassArray;
		
//.CPP file
bool AMyClass::SearchArray(TSubclassOf<AActor> ActorIn)
{
	bool bArrayContains = ClassArray.Contains(ActorIn);
	return bArrayContains;
}

//It's the "ClassArray.Contains" that seems to be messing up.

```

I’m not sure what to do here. The rest of my project kinda rides on this and I don’t want to use BP because it’s easier (for me) to use C++ as a main parent class. Any help is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [May 27, 2016, 5:50am UTC](https://forums.unrealengine.com/t/c-actor-class-array-search/358730/2 "2016-05-27T05:50:27Z")

</div>

I don’t understand whats the problem? How “ClassArray.Contains” messing up?

---

<div class="post-metadata">

**Author:** ![Zarkopafilis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zarkopafilis](https://forums.unrealengine.com/u/Zarkopafilis)\
**Post date:** [May 27, 2016, 5:55am UTC](https://forums.unrealengine.com/t/c-actor-class-array-search/358730/3 "2016-05-27T05:55:14Z")

</div>

I think you have to use an actor pointer to check

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [May 27, 2016, 3:03pm UTC](https://forums.unrealengine.com/t/c-actor-class-array-search/358730/4 "2016-05-27T15:03:24Z")

</div>

Hey catellus-

Can you explain how line 8 above is messing up? If it is not compiling, can you provide the compile error you’re getting? If it is causing issues in the editor, please explain what the behavior is.

Also, was Zarkopafilis’ suggestion of using an Actor pointer instead of TSubclassOf helpful? Let us know what you’re experiencing and we can investigate further.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_93d485201](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_93d485201](https://forums.unrealengine.com/u/anonymous_user_93d485201)\
**Post date:** [May 27, 2016, 5:46pm UTC](https://forums.unrealengine.com/t/c-actor-class-array-search/358730/5 "2016-05-27T17:46:48Z")

</div>

After messing with this for a while, I’ve managed to fix it. It seems that the ActorIn was not putting through a class properly. Unfortunately I did not put the code for the ActorIn variable so I do apologize for that. Thanks to you all for trying to help me. Can’t cure stupidity, unfortunately.
