Casting in Blueprints (theory): what Cast To does and when to use it
Cast To is a more versatile way to communicate than direct reference: besides accessing one specific Blueprint, it can access a specialized version of a Blueprint, several Blueprints of the same class at once, or one specific child of a parent Blueprint. It tests whether the object is of that class and, if so, gives you access to its members.
From the course
Taken from the hands-on project of the course; the lessons show every step on video.
When do I use Cast To?
- Accessing a specialized version of a Blueprint: a character with a limited amount of money, say 1,000, buys a chair that costs 200. Cast To the character's Blueprint changes how much money it has.
- Accessing many instances the same way: a lamp Blueprint with several instances in the scene. Cast To lets you change something in all of them at once, like turning every light off or changing a price.
- Accessing one specific child Blueprint: a parent Furniture with children BP Sofa, BP Chair and BP Table. A Cast To BP Table reaches only the table, so you can change its own features, such as number of seats or tabletop material.
How is it different from a direct reference?
A direct reference points to one particular instance. Cast To asks whether an object is a given class, which also covers specialized versions and child classes, and gives you that class's variables and functions.
A mental model
Think of it as asking this object: are you a BP Table? If yes, you can use everything a BP Table has. The practical guide that follows builds a purchase system this way.
Free PDFs that go with this page
One-page guides made from the lessons, sent by e-mail.
- Cast, Interface or Event Dispatcher? — A one-page guide to choosing how two Blueprints talk to each other, with the example from the course for each method.
- Blueprint Cheat Sheet — A free one-page PDF for Unreal Engine 4/5, made from the lessons of the course. Keep it next to your editor while you learn.
- Free PDFs
Frequently asked questions
What does Cast To do?
It converts or tests an object as a specific class so you can access that class's data and functions.
When should I use it instead of a direct reference?
When you need to reach specialized versions, child classes or many instances of the same class.
Can I reach only one child class?
Yes. For example, only BP Table out of a Furniture family.