Announcement

Collapse
No announcement yet.

Creating a survival system?

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

    Creating a survival system?

    Hi there! I have spent a while on UE4 (I am fairly new) and I'm starting to get the gist of the workflow. I used to work on Unity, but I really wanted to work on Unreal because I think it's time for an upgrade . Anyways, there was something that I wanted to create that I managed to get in Unity, and I'm wondering if I can replicate it here?

    First things first, I am working in C++. I know the language decently so I shouldn't have a problem with that.

    Ok so in Unity, I made this thing called the Survival system. Think of a typical survival game -> there's always health, hunger, stamina etc. All of these share some common values like their currentValue, or their maxValue, or their depletionRate etc. We can think of each of these as "Subsystems". In my survival system I created a parent class called BaseSystem. This class essentially has all the variables that each subsystem will contain. Then, for each subsystem (like health for example), I create a new class which inherits from BaseSystem. Ideally, all subsystems will derive from BaseSystem. In this particular subsystem, I can define more unique variables and methods.

    This approach has been very flexible with me in Unity. Once I have made all the subsystems, I create another class called Character. In unity, this was a component that would be attached to the player object. Character will be the place where I declare what subsystems I'll be using. Then, I can call their methods in Start or Update.

    I hope to do something similar in Unreal. I am starting off from the Third Person Template that you can choose from when you create a project in Unreal. My question is, will my approach in unity be the same?

    What I know so far is that when I make the subsystem classes and BaseSystem, I want them to derive from UObject. The class called Character that I made in Unity will be replicated in the form of an ActorComponent. Is this a good start?
    Additionally, I am also concerned about this : In Unity, I can edit the values for each subsystem declared within the inspector. Unreal has a similar window : the details panel. I know that you can expose properties by calling UPROPERTY on an individual variable. If I do this on classes, will all the individual variables of that class be exposed?

    Thanks and let me know if I have to be more clear!

    #2
    Alright, so in sections:

    Originally posted by nerdares View Post
    Anyways, there was something that I wanted to create that I managed to get in Unity, and I'm wondering if I can replicate it here?
    This is usually not a problema at all. It only depends on your willingness, saviness and time which you are willing to put into the project. UE4 is far more exposed and dynamic than Unity, so its all about yourself, your creativity and knowledge.

    Originally posted by nerdares View Post
    I hope to do something similar in Unreal. I am starting off from the Third Person Template that you can choose from when you create a project in Unreal. My question is, will my approach in unity be the same?
    Should work just fine. Personally, I have worked with similar systems for overall character stats, and they worked just fine, we called them StatsSet.

    Originally posted by nerdares View Post
    What I know so far is that when I make the subsystem classes and BaseSystem, I want them to derive from UObject. The class called Character that I made in Unity will be replicated in the form of an ActorComponent. Is this a good start?
    If you want to replicate the StatsSet, then yes, derive them from UObject, if not, then its fine to use an empty class. Just remember you'll have to GC any objects you dynamically create since it doesn't have UE4's GC. In principle, you should derive from UObject, but if you want to avoid the overhead...

    Originally posted by nerdares View Post
    Additionally, I am also concerned about this : In Unity, I can edit the values for each subsystem declared within the inspector. Unreal has a similar window : the details panel. I know that you can expose properties by calling UPROPERTY on an individual variable. If I do this on classes, will all the individual variables of that class be exposed?
    Yes, you can expose each individual variable using the UPROPERTY macro and selecting the specifiers (consult the documentation/wiki on this subject). If you do it on classes, it means your class will be exposed to blueprints, meaning, you can instantiate them and manipulate its objects. Its purpose is not to expose all of its objects, just think of the amount of unecessary variables you would expose to the editor by doing so.


    Hope I helped and I haven't lied :P

    To make sure I understand your point, what you're trying to achieve is:

    Code:
    class Health : public BaseSystem
    class Heat : public BaseSystem
    Where BaseSystem is something like:
    Code:
    UCLASS(ABSTRACT)
    class BaseSystem : public UObject
    {
    protected:
     float depletionRate;
     float currentValue;
     float maxValue;
    
    public:
     BaseSystem();
    }
    Last edited by Horus; 05-29-2017, 04:51 AM.
    [On Hold]WIP: Vertex-Based Ledge Detection/Parkour Engine

    Looking for fellow programmers to develop a project.

    Comment


      #3
      Thanks! I am still confused on one thing though, so let me clear myself up.

      Say I have a c++ class called MyObject which inherits from UObject right? Now let's say this class has a variable of type int32 called someNumber. I also have a UPROPERTY(EditAnywhere) macro on top of it. The class "MyObject.h" has this code:


      Code:
      #pragma once
      
      #include "CoreMinimal.h"
      #include "UObject/NoExportTypes.h"
      #include "MyObject.generated.h"
      
      /**
       * 
       */
      UCLASS()
      class LEARNING_API UMyObject : public UObject
      {
      	GENERATED_BODY()
      	
      public:
      	UMyObject();
      
      	UPROPERTY(EditAnywhere, Category = "MyObject's fields")
      		int32 someNumber = 0;
      	
      };
      Now let's say I have an ActorComponent class called TestComponent. This class MUST be attached to an actor in my scene.

      My goal is to make it so that TestComponent can expose MyObject's fields. Is this possible? What is the correct approach? Here was my attempt of the TestComponent.h file - of course, this wouldn't work. It would be expecting an actual instance of MyObject instead. I am quite confused here..

      Code:
      #pragma once
      
      #include "MyObject.h"
      #include "CoreMinimal.h"
      #include "Components/ActorComponent.h"
      #include "TestComponent.generated.h"
      
      
      UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
      class LEARNING_API UTestComponent : public UActorComponent
      {
      	GENERATED_BODY()
      
      public:	
      	// Sets default values for this component's properties
      	UTestComponent();
      
      	UPROPERTY(EditAnywhere, Category = "Something")
      	UMyObject* myObject;
      
      protected:
      	// Called when the game starts
      	virtual void BeginPlay() override;
      
      public:	
      	// Called every frame
      	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
      
      		
      	
      };
      Essentially in Unity, I was able to accomplish this. If I made a class that had some variables and made sure to set them as Serializable, then if i create an instance of that object inside a script-component (in which that script-component get's attached to a game object), I can access those variables.
      Last edited by nerdares; 05-30-2017, 08:38 PM.

      Comment


        #4
        I found that this thread answered my questions:

        https://forums.unrealengine.com/show...-for-UPROPERTY

        Comment


          #5
          Originally posted by nerdares View Post
          I found that this thread answered my questions:

          https://forums.unrealengine.com/show...-for-UPROPERTY
          Glad to hear that!

          To be honest I was unaware of the existence of such flag. And I don't really see a use for ActorComponents for most engines, guess I'll have to dig deeper and understand them better.


          Good luck!
          [On Hold]WIP: Vertex-Based Ledge Detection/Parkour Engine

          Looking for fellow programmers to develop a project.

          Comment

          Working...
          X