Announcement

Collapse
No announcement yet.

Object Oriented Weapon System

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Object Oriented Weapon System

    Dear reader,

    I am trying to build an extension to the First Person Template, making it easier to change the weapon used.
    My Idea was: Create an Actor Blueprint Class called Weapon, and make every weapon used in the game a Child Instance of this blueprint, so that events like"Fire", "Reload" etc. can easily be called by the character blueprint
    and the appropriate method for each weapon could be called immediately.
    However, once I add the "Weapon" variable to the character blueprint (replacing the Rifle Skeletal Mesh), I kinda get stuck. I can't put in a default value for my Weapon Variable ("Editing this Value is not allowed"), nor can I set a child blueprint of the Weapons class as default, or used weapon,
    for they are also "empty" instances of the Weapons Class, even though they've got their properties assigned.

    When I try to attach the "Gun" Skeletal Mesh (Base property of the "Weapons" class), as other skeletal meshes would be attached to the character mesh as seen in the FPP template, I get these errors:

    Error Accessed None 'Weapon' from node AttachTo in graph 'UserConstructionScript' in blueprint PlayerController
    Error Accessed None from node AttachTo in graph 'UserConstructionScript' in blueprint PlayerController

    I'd appreciate any help with solving this issue, or an entirely other way in which I could make an easy, widely usable weapon system. Because I am thinking about using around 30 weapons, Trying to cast my "Weapon" to each different weapon instance actor is not an option.

    Thank in Advance, any help is welcome.
    1
    Try to improve my existing mechanics
    100.00%
    1
    Try something entirely different, and if so, what? ;)
    0.00%
    0

    #2
    Im not sure if youre able to wait a bit, but Im currently working on a template extension for the marketplace that has exactly what youre looking for.

    https://forums.unrealengine.com/show...erson-Template
    Stylized Low Poly Environment
    Stylized Low Poly Pine Forest
    Stylized Low Poly Buildings
    First Person Horror Template

    Comment


      #3
      I would make an Interface functions for the one's you want. A component based system is just as valid, and maybe even more valid than a strict OOP one. Or a combination. But, there's no reason you can't do it as you are describing, just make sure to make those variables editable so that subclasses can change them.

      Comment


        #4
        What do you mean? Should I extend my "Weapons" class or make a new one? The problem is that I don't think I can change the value of the Weapon variable in my PlayerController, which is the entire goal of the class. Is there any way I could create "Objects" based off the Weapons class, like Meshes are Based off a "Mesh" class? Right now I am creating subclasses, which are still classes and are still not implementable in the Player Controller (?) The communication between Class and Subclass is not an issue, it's the communication between Player Controller and Weapon that necks me.

        Nevertheless, thanks for your view on the issue

        Comment


          #5
          Well, I'm doing this to learn how this kind of logic works in blueprints, and i could really use help, but I think the best way to learn this kind of class usage is, in the end, to make something like that yourself. I really appreciate your help on the issue, and your project sure looks awesome, but, I'd rather try to make something like that myrself (and I think it'd be a lot more fun to do so ) than to use an entire aspect of game mechanics someone else made. Nevertheless, Thanks! And if you could push me in the right direction, I'd really appreciate that.

          Comment


            #6
            The way my system works is I have a BaseWeapon blueprint class that contains all the weapon functionality, and then I make child classes based off of that (like youve done). The major difference between mine and yours is that I have the child weapon actors in the world, and when my player hits them with a trace it adds the hit actor to an array, and then I cycle through the array and set a variable CurrentWeapon to whatever actor was hit. This allows me to cast to BaseWeapon and call any function in the blueprint.
            Stylized Low Poly Environment
            Stylized Low Poly Pine Forest
            Stylized Low Poly Buildings
            First Person Horror Template

            Comment


              #7
              If you want to set a value to an Actor Class Reference variable, you must spawn that actor and use the resulting reference to set your "Weapon" variable. This will surely work for you if you node sequence right in the Begin Play Event, all those errors you are facing about attaching is because you try to attach a null Reference. Try the node SpawnActorFromClass and select the Weapon Class you've created, along with some other parameters. This node will output you a Reference from this class, that you must use it to set the "Weapon" variable value inside your Character class.

              About the way you are doing, personally I think yours is the best way to implement a weapon system, using a Base Weapon class and derive others from that one, always implement the Common functions and events that the other classes will share, as well some particular properties. It will save you repetitive coding.

              Comment


                #8
                If you defined the Weapon variable inside your PlayerController class, you should cast it right after spawning your Weapon Class to set the variable inside your PlayerController.

                Comment

                Working...
                X