# Is casting expensive?

**URL:** <https://forums.unrealengine.com/t/is-casting-expensive/13589>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [October 19, 2014, 8:41pm UTC](https://forums.unrealengine.com/t/is-casting-expensive/13589 "2014-10-19T20:41:42Z")\
**Posts on this page:** 1\
**Showing post:** 30

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [March 30, 2022, 12:15am UTC](https://forums.unrealengine.com/t/is-casting-expensive/13589/30 "2022-03-30T00:15:38Z")

</div>

At the engine level, casting to another class does not compare any property presence, it compares the unreal-level type info for the class.  
You can have two classes that have exactly the same properties, and both derive straight from AActor, yet when you create an instance of class A, you cannot cast it to an instance of class B.

In C++, casting is fast, because it can be done with compiler support (although in debug mode it can run checks, depending on how you do it.)

In blueprint, is slightly slower, because of the blueprint/c++ marshaling needed, but it’s not terrible. What it _can_ do is walk the chain of UClass in the object, to find the class you want, or not. I haven’t actually timed , but it’s never been a problem – if a blueprint-level cast is a performance problem, then that code shouldn’t be in blueprint to begin with.

You can read the code in `Engine\Source\Editor\BlueprintGraph\Private\K2Node_DynamicCast.cpp` for more details (including the determination when you’re trying to do an impossible or tautological cast, based entirely on the UClass of the castee.)

And just to hammer home, is the implementation of the blueprint VM opcode `EX_DynamicCast`:

```auto
		// check to see if the Castee is a castable class
		else if( Castee->IsA(ClassPtr) )
		{
			*(UObject**)RESULT_PARAM = Castee;
		}

```

Which is the good-old Unreal C++ level cast. (There some additional code above to check for UInterface and NULL cases.)

---

_[View the full topic](https://forums.unrealengine.com/t/is-casting-expensive/13589)._
