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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

TSubObjectPtr not working

Hi, I know this is probable a stupid question but I'm new to programming, and I'm working out a book, Learning C++ by Creating Games with UE4. I'm pretty sure I have entered all the code correctly, but it won't work. My code looks like this:

 #pragma once
 
 #include "GameFramework/Character.h"
 #include "NPC.generated.h"
 
 UCLASS()
 
 class BASICCPP_API ANPC : public ACharacter
 {
     GENERATED_UCLASS_BODY()
 
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
     TSubobjectPtr<class USphereComponent> ProxSphere;
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
         FString NpcMessage;
     
 public:
     // Sets default values for this character's properties
     ANPC();
 
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
     // Called every frame
     virtual void Tick(float DeltaSeconds) override;
 
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
 };

Any help would be much appreciated! Thanks!

Product Version: UE 4.12
Tags:
more ▼

asked Jan 07 '18 at 03:37 PM in C++ Programming

avatar image

Tate Hertel
6 2 2

avatar image Impulse21 Jan 07 '18 at 06:17 PM

Are you able to provide the error message?

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

2 answers: sort voted first

hi im fairly new to unreal. but i think i read that TSubObjectPtr are depricated and that u should jsut use raw pointers like AActor* and stuff.

I am not sure what u try to accomplish, but maybe u need something like that. UPROPERTY(EditDefaultsOnly, Category=Damage) TSubclassOf DamageType;

more ▼

answered Jan 07 '18 at 06:19 PM

avatar image

Kanteh
62 4 4 7

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

Hey there, if you are trying to create a sphere component that will belong to your object then you should just do:

 .h
 
 UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Test")
 USphereComponent * Collision;
 
 .cpp on the constructor
 
 Collision = CreateDefaultSubobject<USphereComponent>("Collision");
 Collision->InitSphereRadius(32.0f);
 Collision->SetupAttachment(Mesh);
more ▼

answered Jan 08 '18 at 10:31 AM

avatar image

xlar8or
6k 161 129 304

(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