So I’ve been trying to solve this for days and i’m stumped… I’m new to C++ but my goal is to:
Modify the Actor class by creating a child class called “PLO_Actor” so I can add general functions that will be used heavily throughout my project for certain objects.
I’ve created the class and functions, it works great (when creating my own child classes of “PLO_Actor”) so far!
BUT I would like the Pawn class to also inherit from my “PLO_Actor” class instead of the default Actor class.
I’ve tried the following:
Opening the Pawn.h class in Visual Studio 2017 and changing the parent class from “AActor” to “APLO_Actor” but I can’t get the #include to recognize the “PLO_Actor.h” file.
I’m not sure how to reference header files from my game project, inside the engine project in Visual Studio even though they are both in the same solution.
You would need to modify the engine and add your PLO_Actor class.
At that stage, you might as well just modify the original Actor class
What functions do you need from the PLO_Actor class?
Can they be moved to a component?
Could you use an interface instead?
Could they simply be part of a function library instead?
Hey Kris thanks for the reply! That’s what I was afraid of haha.
The game I’m prototyping has a lot of destructible parts so I made my own
TakeDamage function that also takes in an index if the part of the object hit
and stores a health array so each piece can have it’s own health.
I’m also interested in having a lot of actors on screen so I made an LevelOfDetail
index to control how often the code updates and maybe switch to a 2D sprite at
far enough distances.
I just googled UE4 Interfaces and it looks like that would very useful in my case!
Thanks again
Well there are a couple of ways you can handle this. Since you have the engine source, you could just add your functionality to AActor. In the realm of modifying the engine, this is probably the safest way (vs say changing all other child of AActor to point to your class). The only real problem with this is that you have to maintain and merge those changes each time you do an engine upgrade which can be annoying. But limited to one class not that big a deal. FYI if you go this route, use a second cpp file for just your changes so you only have to really merge the header.
You could use an actor component to provide the new functionality to only classes that need it. This is a good solution of the general functions are truly general. You just add the component to any actor that needs that functionality.
Or if PLO_Actor isn’t coupled to AActor at all, just use multiple inheritance. (ie: class PLO_Pawn : public APawn, public PLO_Actor). Best of both worlds right there.
You can use interfaces, but from the little you’ve said of what you’r doing I think it’s probably overkill.
In terms of you prototyping a new type of damage system, why not just have the new damage system implemented in your custom pawn class, and have your projectile/weapon/gamemode classes call your take damage system instead of the default?
Hey Joe thanks for the reply! I’ll probably try downloading, modifying, and compiling the engine source as a learning experience if nothing else. I really like the idea of the second cpp file, I was unaware you could do that. I’m working in Windows but I do plan on building for mac as well so keeping the my code as contained as possible is important to me so it will make that process easier.
I’ve made a shooter game in blueprints and I’m trying to avoid the following this time around: Having a bullet class that has to run though a growing list of classes to figure out what was hit.
One of the ideas I heard about was having a high level of abstraction and shared functionality in the code. The game I’m prototyping has many different classes that can take damage:
Players
Vehicles
Trees
Buildings
Even Items and weapons
So I’d like every object it my game that can take damage to share the same function so in the bullet class I can just say something like “if has tag “PLO” then cast and do damage”.
After reading up on interfaces I realized you can’t pass in parameters like damage so they won’t work for that part of the game.
Thanks again for the reply, like I said I’m new to C++ and wasn’t yet aware that I could use second cpp files and multiple inheritance so I’m exited to give those a try!
Then yea, interfaces are probably the way you want to go. I don’t know where you got the impression that they don’t support parameters though, they certainly do. It’s the whole point. The interface (we’ll call it I) is just a way to say class C guarantees implementation of functions X, Y, Z and gives you a way to see if object O implements interface. What C does with the parameters passed in via X,Y,Z is up to C. There is more to it but that’s the gist. So you would create IPLODamageInterface and all of your pawns would implement it. Then your bullet/weapon/etc would check if the hit object implements IPLODAmageInterface and call the proper function if it does.
You’re right, I had read one tutorial on interfaces in UE4 and they just called an event that took no arguments so I wrongfully jumped to a conclusion.
So far I’ve been using interfaces for my own TakeDamage function and it works great so far. Thanks again.