How can I retrieve default values from class using Blueprint?

I would like to know how to retrieve the default values from a blueprint class.

Context: I have a turret that fires artillery shells. The shells are regular projectiles, so they are controlled by the physics engine. I have the equation to solve for the appropriate firing angle, given the projectile’s speed and the location of the turret and its target. The problem is that I can’t retrieve the projectile’s initial speed until after I spawn it. However, the blueprint has the projectile mover component, which has an initial velocity. How can I retrieve this number before I spawn the projectile?

Thanks!

Hey NuclearPhoenix,

I don’t believe there is a way to access default variables without an object in BP. What I would suggest is having the projectile communicate back on construction to set its initial velocity. Given the angle could be set at spawn, the call-back for other calculations such as speed should work fine.

Would that work for you?

Peace

The issue is that I want to rotate the turret and its barrel before spawning the projectile (assume movement speed of the turret is finite).

I did consider this: when the player selects a location to fire at, I could spawn the projectile, get the speed, and then destroy it. That does’t really get at the heart of the problem though.

You can expose the variable to set Rotation in the Blueprint. Are you utilizing the setting Expose On Spawn, within the Blueprint Class you’re attempting to Spawn? You must add it to the variable that will be used in construction of said blueprint.

Also, I did not suggest spawning and destroying the actor. What I suggested is a common-practice used in coding applications. Its a “Callback” technique. http://en.wikipedia.org/wiki/Callback_(computer_programming)

Basically, the main Class, the character, calls another Class, the turrent/barrel, the turrent/barrel class calls back the Character Class for further instructions. This way turrent/barrel get/send the information you’re trying to get/send it, rather then sending/getting it directly.

The thing about spawning the actor was just an aside I had thought of, I didn’t mean to imply it’s what you had said.

I think your original answer told me what I wanted to know: there is no way to retrieve the default value from the blueprint class alone.

I can think of several ways of getting around this problem, but I was hoping the answer was going to be “Why yes you can, and here’s how!” Thanks anyways friend :slight_smile:

My misunderstanding, and maybe its out there. I’ve had a few people come to me saying this exact problem. If you ever figure it out, a lot of people will be happy to know.

Was there ever a better solution found for this problem? I have a similar situation where I’d like to get some default values from the class default object. Right now I am spawning an instance, retrieving the values I need, and then destroying it immediately, though this seems less than ideal.

Im wanting a solution to this as well.
Every time I setup script to needlessly spawn an actor to get default values only to destroy it immediately, I get more and more annoyed.

Hey guys,

as there is still need for this, I’ll do my best to answer this question. I assume you have the appropriate class of the projectile. (TSubclassOf of yourProjectileClass)
Now you can use yourProjectileClass->GetDefaultObject() and use it to get its “default” values that are applied on creating those projectiles at runtime. That’s the way I did it for (basically) the same problem.
I hope I didn’t misunderstand the question and helped somebody out there :slight_smile:
Regards,

PS: The code would look like this:

YourClassX* ProjectileDefaultObject = yourProjectileClass->GetDefaultObject<YourClassX>();
	float result = ProjectileDefaultObject->ProjectileMovementComponent->InitialSpeed;

(No 100% guarantee, but pretty sure :wink: )

The issue is not that it can’t be done in code.

The issue is that it can’t be done via blueprint scripting. (as far as I am aware)

I’m not sure if there was ever a way to get this directly. I’m also looking for a way to get the initial/max speed from a class’s projectile component.

I ended up working around it by creating my own max speed variable on the class, and setting the speed in the constructor. This way, the value is exposed, and is guaranteed to be consistent with the instanced classes (at least at spawn).

Old topic, but whatever. I just confirmed on 4.15 you can call “GetClassDefaults” to do exactly that.