x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to write UPROPERTY?

The following is my code for NPC which is a sub-class of a chracter

 UCLASS()
 class GOLDENEGG_API ANPC : public ACharacter
 {
     GENERATED_UCLASS_BODY()
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
     TSubobjectPtr<class USphereComponent> ProxSphere;
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
     FString NpcMessage;
     // When you create a blueprint from this class, you want to be
     // able to edit that message in blueprints,
     // that's why we have the EditAnywhere and BlueprintReadWrite
     // properties.
 }

The compiler returns missing ; on line 25 (which is after the closing bracket)

I've tried to simplify it and only adds UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision) But it still return an error.

How to properly write UPROPERTY?

Product Version: Not Selected
Tags:
more ▼

asked Apr 10 '15 at 08:46 AM in C++ Programming

avatar image

LoveTune
3 1 2 4

avatar image Matom_Bomb Mar 16 '16 at 05:30 AM

I got that same error message once bc I had accidentally added a ; after the UPROPERTY parenthesis i.e.

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage); <-- a semicolon here will cause this error FString NpcMessage;

I don't see a typo like that in the section of code you've given us, but keep an eye out for that in the rest of your file.

avatar image emperor_katax Oct 07 '17 at 11:51 AM

Same here ....`" ; "` caused the issue ...

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Its not the UPROPERTY that is missing the ;.

Try to add a ; after your closing curly bracket of your ANPC class. I.e.:

  UCLASS()
 class GOLDENEGG_API ANPC : public ACharacter
 {
 GENERATED_UCLASS_BODY()
 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
 TSubobjectPtr<class USphereComponent> ProxSphere;
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
 FString NpcMessage;
 // When you create a blueprint from this class, you want to be
 // able to edit that message in blueprints,
 // that's why we have the EditAnywhere and BlueprintReadWrite
 // properties.
 };
more ▼

answered Apr 10 '15 at 09:03 AM

avatar image

Dratone
65 6 8 12

avatar image LoveTune Apr 10 '15 at 09:13 AM

Hi Dratone, thanks for the input.

I've tried that before and still have compiler error.

If I remove everything except UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision) it will return "Missing variable type". Any idea what that might be?

Cheers

avatar image Dratone Apr 10 '15 at 09:36 AM

After a UPROPERTY you always need to define the actual variable. The UPROPROPERTY macro generates code that needs that variable.

Could you paste the complete file? It might be that you have other syntax errors in other parts of the file.

avatar image LoveTune Apr 10 '15 at 10:57 AM

The completed code is as follow

 UCLASS()
 class GOLDENEGG_API ANPC : public ACharacter
 {
 GENERATED_UCLASS_BODY()
 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category =
 Collision)
 TSubobjectPtr<class USphereComponent> ProxSphere;
 // This is the NPC's message that he has to tell us.
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
 NPCMessage)
 FString NpcMessage;
 // When you create a blueprint from this class, you want to be
 // able to edit that message in blueprints,
 // that's why we have the EditAnywhere and BlueprintReadWrite
 // properties.
 }

And the CPP file have nothing inside.

Can u tell me how to define the variable of the UPROPERTY? The book doesn't seems to declare anything and it's the complete code that was given in the text. I'm using 4.7 atm the tutorial using 4.5 build. I hope it doesn't make any problem. Can you please tell me how to declare the variable to resolve this issue?

avatar image eXi ♦ Apr 10 '15 at 11:03 AM

You need to add the ; at the end of the Class body. So after the last }

After that, come back and post the new compile error.

We can't help you if you don't give us the exact errors.

He already told you how to fix the ";" error, now fix it and come back with the new one. (:

avatar image LoveTune Apr 10 '15 at 12:58 PM

Sorry about that guys. I've forgot to pasted the new code.

This is the header file

 #pragma once
 
 #include "GameFramework/Character.h"
 #include "NPC.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class GOLDENEGG_API ANPC : public ACharacter
 {
     GENERATED_UCLASS_BODY()
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
     //TSubobjectPtr<class USphereComponent> ProxSphere;
     //UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
     //FString NpcMessage;
     // When you create a blueprint from this class, you want to be
     // able to edit that message in blueprints,
     // that's why we have the EditAnywhere and BlueprintReadWrite
     // properties.
 };

The CPP file is empty.

I'm following a tutorial where I make a subclass out of character. And the above are the codes I need to paste on the header file. Strangely it didn't work for me. Could you please which variable to declare?

I;m just trying to expose this class to the blue print I;'m not sure what to declare. Again thanks for the help. My compiler error is still the same as above "Missing variable type"

avatar image Dratone Apr 10 '15 at 12:59 PM

You are not declaring any variable anymore. Try something like this:

  #pragma once
  
  #include "GameFramework/Character.h"
  #include "NPC.generated.h"
  
  /**
   * 
   */
  UCLASS()
  class GOLDENEGG_API ANPC : public ACharacter
  {
      GENERATED_UCLASS_BODY()
      UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
      FString NpcMessage;
      // When you create a blueprint from this class, you want to be
      // able to edit that message in blueprints,
      // that's why we have the EditAnywhere and BlueprintReadWrite
      // properties.
  };
avatar image LoveTune Apr 10 '15 at 05:51 PM

Hey Dratone I got it working. Thank you very much for your help.

I'm using 4.7 and TSubobjectPtr can no longer be used.

This is the final code for viewers. Bare the noobness I just started C++.

 #pragma once
 
 #include "GameFramework/Character.h"
 #include "NPC.generated.h"
 
 /**
 *
 */
 UCLASS()
 class GOLDENEGG_API ANPC : public ACharacter
 {
     GENERATED_UCLASS_BODY()
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
     USphereComponent* ProxSphere;
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
     FString NpcMessage;
 
     // When you create a blueprint from this class, you want to be
     // able to edit that message in blueprints,
     // that's why we have the EditAnywhere and BlueprintReadWrite
     // properties.
 };

Cpp file

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "GoldenEgg.h"
 #include "NPC.h"
 
 
 
 
     ANPC::ANPC(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
     {
         //GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "interact");
     }

avatar image darkgaze Aug 29 '17 at 04:53 PM

Would be nice you mark the right answer as the answer, please.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question