Changing a default value without modifying Opsive code.

chrisk

Active member
Hi,

I'm trying to make a change to a member variable default value without modifying existing code. I like to keep the Opsive code the same as long as I can so that I don't have to merge the changes every time I get Opsive update.

For instance, I would like to change a default value in ShooterWeapon.cs something other than the followings.
Code:
[SerializeField] protected MinMaxVector3 m_ShellVelocity = new MinMaxVector3(new Vector3(3, 0, 0), new Vector3(4, 2, 0));

Obviously, I'll need to inherit the class and I try to hide the member variable with a different default value.

Code:
public class MyShooterWeapon : ShooterWeapon 
{
        [SerializeField] protected new MinMaxVector3 m_ShellVelocity = new MinMaxVector3(new Vector3(0, -3, 0), new Vector3(0, -4, 2));
    }


If I do, I get an error like,

The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(MyShoorterWeapon) m_ShellVelocity


The culprit is having the [SerializedField] in both classes.
If I remove [SerializeField] attribute from MyShooterWeapon, the default value won't change from the base when I first initialize the class.

I guess this is more like a Unity question but I would appreciate if you can help how it can be done.

Thanks a lot!
 
Yeah.. this one is tough. I think for this the best way to handle it would be to create a profile that has all of the values that you like, and then when creating the new item you can use that profile.
 
I see. That might work.
Please do me a favor. This might be a chance to learn about the profile system.
Could you please show me how I can inject the default value profile when the classes are created?
It seems like you already have Profile class but it seems related to the State system and I'm not sure how it can be applied to class initialization.
Thanks.
 
The profile system won't change the actual code - it will only apply the values when you create the item.
 
Understood. Do you have a pointer(doc link or video) how to create a profile? I'm currently looking at DemoStateConfiguration and trying to figure out how it works. thanks.
 
Last edited:
It works beautifully! I'm getting to like UCC more and more. It is very clever and I really appreciate you have done such a great job!
 
Top