Can I get an explanation with what I'm doing wrong?

Hi Forums,

I can’t seem to wrap my head around what I am doing wrong here…

I want my blueprint_pickup class to be able to store reference to a blueprint_WeaponActor.

In my pickup class I have this variable.

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Weapon”)
AAweapon* WeaponToPick;

but have come to realise upon after compiling that in order for the blueprint_WeaponActor to be able to stored in my blueprint_pickup object, I need to place the blueprint_WeaponActor into my level?

now if I change AAWeapon* WeaponToPick variable to UClass* WeaponToPick,

I can now, choosing from a heeeeeap of options, can find blueprint_weapons in the list and set them to WeaponToPick variable…

Any help would be muchingly appreciated.

Thanks,

Jarrad T.

Hi Jarrad! First of all, you have to follow your code back. Make sure that everything is listed as public. Secondly, you have to initialize your actor. If an actor is not initialized, you will not find it.

For example:

WeaponToPick =CreateDefaultSubobject<AAWeapon>(TEXT(“Weapon”));

Put it in your constructor, and you should be okay.



    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon")
    TSubclassOf<class AAweapon>  WeaponToPick = nullptr;


Now you should be able to select any AAweapon based weapon.

Heya, thank you both for your replies but just to further add onto my predicament. I tried what you suggested Aericks, and all that this is doing is setting a weapon to fill the WeaponToPick list, where as I actually need to add BP_Weapons I have created in the unreal editor to this list, I am not sure if that entirely makes sense… I am relatively new to this.

Now with what you have suggested EvilCleric, doing the whole subclass approach, are these actually creating objects that can be used in my game??

Will not create any object. It will only hold a reference to which type of weapon you want. You then use this reference to Spawn the real thing when you need it - you’ll now use this reference to indicate the Spawn node what to spawn:

spawn.png

It’s like the projectile reference in the character’s BP in the FPS BP template.

Is this your goal, or do you want to spawn it also in C++?

Hey Evil, essentially what went down last night is I tried Aericks method first, didn’t work, posted that reply about thanking you both, then tried your method and found I can make do with what you have put forward, so! thanking you for the suggestion, I think it will do just fine!

However!!! one little miiiinor complication I have with the Subclass approach is, I have a GettName() function that simply returns a string WeaponName of the C++ AWeapon class, I have indeed purposely called the function GettName to differentiate between the stock standard inherited GetName() function provided.
Furthermore, in the C++ class of Pickup in either constructor or beginplay methods, I can’t call GettName, like this:
this->bName = WeaponToPickup->GettName(); as it appears it does not exist.

The reason I want to do this approach is so that I don’t have to manually set names to each and every pickup object that gets spawned in my game. I’d rather let references do the job.

If you can shed some light on what’s now going on here, that would be a most appreciated!!! :smiley:

Thanks,

Jarrad T.

essentially, this is what I am attempting in the pickup c++ constructor/beginplay

Ok… I figured out this little awesome node that provides me with the exact WeaponName that I need (from AWeapon class), any chance you know the C++ equivalent???

To get the defaults, for example, the WeaponName property, you can use one of these:


AAWeapon::StaticClass()->GetDefaultObject<AAWeapon>()->WeaponName

or


WeaponToPick->GetDefaultObject<AAWeapon>()->WeaponName

If you have added the name functionality in Blueprint, you won’t be able to access it in C++.

That isn’t entirely true, but yeah better not go that route.

Hey guys,
sorry for the delay, haven’t been around to check out what you suggested EvilCleric, but just got around to it now, and that is exactly what I’m after, and it works, thank you very much!!!

now… I’m not really too familiar with forum procedures and what not, sooo if I have ultimately gotten what I need from this thread am I meant to close it or something???

Thanks,

Jarrad T.

Nope, threads are usually always left open to encourage discussion!


And yeah you can write functions to read back values from blueprint if you want too… but IMO it’s a terrible design.

Thanks Jamsh,
am also glad that this thread didn’t end up getting closed after all as I am having a further issue with the whole setting and reading name business.

when I click “play” and walk up to any pickup, the name is set entirely correct and reads back to me on a HUD component I have made “Scar : press f to pickup”

now…

when I drop the weapon (spawn actor from class, this does work for the most part) hovering over the object no longer displays the weapon name, just: " : press f to “pickup”

has anyone encountered this before? / is more information needed to be provided?

Thanks,

Jarrad T.

It sounds like you’re spawning a different class of object which doesn’t have the weapon name set - but it’s hard for me to say really without seeing the code really!

What you want to do I believe is create a Blueprint class of your weapon, and set the default properties (such as name, projectile etc.) in there. Then you set the weapon class to THAT blueprint and not the C++ class.

Typically you don’t change the properties of a class at runtime, in fact I’m not entirely sure if you can off the top of my head.

Hi Jamsh,

problem with what you have suggested is me attempting that earlier up this thread. I was never actually able to set BP_Weapons based of my Weapon C++ class in the BP_WeaponPickup Objects.