官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 犍为县| 会泽县| 通江县| 曲靖市| 三门峡市| 保定市| 夏津县| 台湾省| 泗水县| 德阳市| 昭通市| 湟源县| 玉田县| 胶州市| 大新县| 黑水县| 保山市| 惠水县| 奉节县| 佛冈县| 三穗县| 阳原县| 德惠市| 辽中县| 肇源县| 溧阳市| 海盐县| 霸州市| 雷山县| 分宜县| 大石桥市| 静海县| 吉木乃县| 山丹县| 绵竹市| 土默特右旗| 滕州市| 肃北| 安龙县| 文成县| 亚东县|