Announcement

Collapse
No announcement yet.

Object Numbering

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

  • replied
    Yes, it seems to work, thanks!

    Leave a comment:


  • replied
    Well static variables should be initialized at compile time, so your .cpp file should look like this:
    Code:
      // Fill out your copyright notice in the Description page of Project Settings.  
    #include "BotTargetPoint.h"    
    int32 ABotTargetPoint::ThisClassInstanceCounter = 0;  
    
    ABotTargetPoint::ABotTargetPoint()
    {    
    }  
    void ABotTargetPoint::BeginPlay()
    {    
    Super::BeginPlay();    
    ABotTargetPoint::ThisClassInstanceCounter = 0;
    }

    Leave a comment:


  • replied

    Maybe I’m writing something wrong, but when I try to assign a certain value to the static variable, I get an error
    Code:
    // Fill out your copyright notice in the Description page of Project Settings.  
    #pragma once  
    #include "CoreMinimal.h"
    #include "Engine/TargetPoint.h"
    #include "BotTargetPoint.generated.h"  
    UCLASS()
    class MYTESTPROJECT224_API ABotTargetPoint : public ATargetPoint
    {    
        GENERATED_BODY()        
            ABotTargetPoint();
    protected:    
        virtual void BeginPlay() override;  
    public:    
        static int32 ThisClassInstanceCounter;
    };
    Code:
    // Fill out your copyright notice in the Description page of Project Settings.  
    #include "BotTargetPoint.h"  
    ABotTargetPoint::ABotTargetPoint()
    {  
    
    }  
    void ABotTargetPoint::BeginPlay()
    {    
        Super::BeginPlay();    
        ABotTargetPoint::ThisClassInstanceCounter = 0;
    }
    Click image for larger version  Name:	-1.PNG Views:	0 Size:	7.3 KB ID:	1694620
    Last edited by whitegоld; 12-05-2019, 10:44 AM.

    Leave a comment:


  • replied
    Originally posted by whitegоld View Post
    I searched the Internet, and I can’t find how static variables can be created in ue4, I get an build error
    In the project I'm working I have a bunch of AActor class that use static variables and I have absolutely no compilation errors.
    I think you cannot mark a static variable as UPROPERTY however you can create UFUNCTIONs to return values from static variables if you need to access them in Blueprint classes.

    Leave a comment:


  • replied
    I searched the Internet, and I can’t find how static variables can be created in ue4, I get an build error

    Leave a comment:


  • replied
    If "place it on the stage" means spawning I think you can do something like that
    Code:
    void AYourActor::BeginPlay()
    {
       Super::BeginPlay();
       AYourActor::ThisClassInstanceCounter++;
    }
    Where ThisClassInstanceCounter is a static int32 variable of AYourActor.

    Leave a comment:


  • started a topic Object Numbering

    Object Numbering


    Hi, I need to create a variable that numbers every object of this class when I place it on the stage, how can this be done?
Working...
X