Download

Dynamically setting defaults crashes editor

Hello! So I have projectiles in my game, I wish multiple entities to be able to use the same projectiles, but that the projectile inherits some values from the entity in order to modify it slightly.
E.G. the shot moves at different speeds depending on who fires it.

ProjectileMovement->InitialSpeed = Cast<AWinstickPawn>(Owner)->ShotSpeed;
	ProjectileMovement->MaxSpeed = Cast<AWinstickPawn>(Owner)->ShotSpeed;

I am presuming the crash happens because InitialSpeed and MaxSpeed are predetermined to be editable ints or floats in the editor and when it suddenly points to a value in an actor that doesn’t exist yet, it doesn’t know what to do and crashes.
What’s the best way to set the speed other than in the constructor? If I set these values after the fact, the projectile has already launched at the default speed.

Currently the “easy” solution would be to make a seperate projectile for each entity and just preset the speeds. But that would mean tons of duplicate projectiles that are otherwise identical apart from those values.

Have you tried in beginPlay instead?

1 Like

You could make a custom init function (e.g. InitBullet) that you call right after spawning the bullet (in your weapon script or whatever spawns the bullet).

1 Like

Thanks, setting it after worked after all. For some reason I assumed that it would only use the value in defaults for velocity.