- Unreal Engine 4 Game Development Quick Start Guide
- Rachel Cordone
- 202字
- 2021-06-24 13:44:01
Working With Object/Actor References
As with traditional programming, we need to avoid errors in our code that can occur from trying to access null variables. In Blueprints, there are a few ways in which we can make sure a variable is valid before using it:
- Depending on the context, we may just need true or false (uncommon, but may be required in an if statement before a function call, for example).
- The second method uses an IsValid function call with two outputs. Both of these can be found by typing valid in the search box.
- The third method, which I prefer, is to use a Validated Get, which can be created by right-clicking on a normal Get node and clicking on Convert to Validated Get. This is essentially the same as the second method, but keeps the code cleaner:

Using a validated GET is the same as this snippet of code:
if ( MyActorReference != null )
{
// This is the Is Valid output.
}
else
{
// This is the Is Not Valid output.
}
The Is Valid output ensures that the MyActorReference variable isn't null, and you won't get any errors trying to access its variables and functions:

推薦閱讀
- Python數(shù)據(jù)分析基礎
- 深入淺出Spring Boot 2.x
- Java從入門到精通(第5版)
- 編程珠璣(續(xù))
- Learning Neo4j 3.x(Second Edition)
- Learning Python Design Patterns(Second Edition)
- Kali Linux Wireless Penetration Testing Beginner's Guide(Third Edition)
- SSM輕量級框架應用實戰(zhàn)
- 第一行代碼 C語言(視頻講解版)
- Illustrator CS6設計與應用任務教程
- MongoDB Cookbook(Second Edition)
- 現(xiàn)代CPU性能分析與優(yōu)化
- Mastering ASP.NET Core 2.0
- After Effects CC技術大全
- 精益軟件開發(fā)管理之道