Share You Use Cases

Question, could you use virtual methods for different parts of a weapon? If you created your own building weapon function that took in virtual(stock, barrel, clip) could you not construct something generic like a “gun” but make a bunch of interchangeable meshes/stats?

Also a typical virtual case I can see is Speed and Velocity of cars. Each car would have different functionality for how it drives, but they are using the same logic.

I’ve seen many(virtual overrides) in the toon tanks section previously…

Biggest places I’ve noticed in the default are DeltaTime.

Guessing we can use it to control how things behave or check within the game’s natural tick system. Probably useful we saw with the text based message in treating how a weapon fires or behaves. I’d imagine dealing damage / particle effects / everything can be changed while keeping the same default parent structure.

The TakeDamage() Function from Actor.h is virtual. Does this mean that we could override the TakeDamage function to extend it by adding damage over time effects (fire, poison, etc)?

  • Seen Most notably in the Begin Play, Tick, and Input. But also during Toon Tanks Section we used it as well.

  • I could foresee using it in a case of some interactable environment actors. Where they all inherit say a “Interact” Function but on each of those actors you may want different things to happen. IE. A Door Opening, A button being pressed to trigger something, or things of that nature.

1 Like

I’m coming at this from a few different courses.
virtual functions are used whenever you want to extend the functionality of classes and allow for sub classes to use the same methods that the parent does with polymorphism.
most times you use virtual is when the child classes use the same information to do different outputs.

I’ve seen virtual used before in the BeginPlay, Tick, and SetupPlayerInputComponent functions.

I think virtual functions could be used in a game with weapons with elemental abilities. An ice blade would use the Swing or Attack function of a normal blade to deal damage, while also freezing the enemy.

1 Like

Trying to understand here: if I had an actor component class called Weapon, that I would apply to my different weapon actors, and within the Weapon class definition, there would be a virtual void function called Swing(), which is responsible for what kind of damage was done, how much, area of effect damage, etc., and then if I had children class of Weapon that had different variables or aspects of Swing() I wanted to edit, I would do that with virtual methods. For instance, if I had a child of class Weapon called Blade, and in Blade I wanted to also call Swing(), but I wanted the blade’s swing to be unique in several ways or be it’s own type of swing, I would define void Swing() override in the Blade class.

Is this correct?

Thanks a ton,
Tele

I actually seen this virtual void case a lot in that ToonTanks before.

I try to understand about virtual void. Let’s say I have this FPS game character named Sinon. What I intended to do is to have her ability to shoot any enemy with poison , but I want her also can heal her allies by the very same ability as poisoning her enemy. By using virtual void, I can make her weapon class ie. Rifle class, with Poison() as default function, and then Heal() as the override function for that same Rifle class.

Please correct me if I got wrong in my own understanding.
Cheers,
Tsuk1mi

I think the virtual functions would be useful in a puzzle game.
For example, there are different things that can be opened or activated. So there would be a function “Open()” or “Activate()”, which would be virtual. You can imagine doors and chests, both of them need to be open (play opening animation), but the chest needs to spawn something inside or activate a trap after it is opened.
I believe it basically allows us to specify individual/unique behavior.

1 Like

So, in hence i noticed the virtual used with theplayerinputcomponent , other that beginplay , and the last one which i know which is tick function.

But On the other hand I can imagine the different types of ability i guess , also we can use in making different gun shootes .

I wonder if it could be used for branching dialog options like with telltale games. The basic dialog structure could be virtual and the options extensions and consequences could be preassigned as different outputs even before writing the dialog itself.

I imagine virtual can be used when you have a general type of object in Unreal like a ball that has a function that includes the general functionality. Then you have a kind of ball like a beach ball and has the same function and it has more specific functionality.

I haven’t really seen much of how virtual functions have been used except in the cases of begin play and the tick function. However, now that I have a better understanding of it, I can definitely see where it can be applied. If you created a “worker” base class for example, you could then create several different derived classes based on the profession of any given person. Creating a “work” method in the worker class, each child class of worker would own different virtual methods for each profession that would have a fitting output (e.g. the shoemaker outputs shoes, the farmer outputs produce, etc.).
That’s just what popped into my mind. :slight_smile:

1 Like

I imagine this would be useful for something like a coffee shop, where you run a Purchase function but have different prices and inventory subtractions for each different item.

Privacy & Terms