Time for action – Fixing an Accessed None
Our Projectile variable doesn't have anything assigned to it, so let's try to fix that. We'll use the foreach
iterator to find one and assign it to our MyProjectile
variable.
Let's add the lines to our
PostBeginPlay
function:var Projectile MyProjectile; simulated function PostBeginPlay() { local float ProjectileSpeed; foreach DynamicActors(class'Projectile', MyProjectile) break; `log("Projectile:" @ MyProjectile); ProjectileSpeed = MyProjectile.Speed; `log("ProjectileSpeed:" @ ProjectileSpeed); }
Now the code will search for a
Projectile
and assign it to ourMyProjectile
variable.Compile the code and run the game.
Exit the game and take a look at the log:
[0005.14] ScriptLog: Projectile: None [0005.14] ScriptWarning: Accessed None 'MyProjectile' BrokenActor BrokenMap.TheWorld:PersistentLevel.BrokenActor_0 Function BrokenGame.BrokenActor:PostBeginPlay:004F [0005.14] ScriptLog: ProjectileSpeed: 0.0000
Well that didn't work...