I have an actor blueprint called “weapon”, inside event graph I created a custom event called “Start”. In another blueprint I want to use the event “Start”, so I dragged and dropped inside it. It says: Start - Target is Weapon. I set a variable named “Rifle” of type “Weapon” and connected to “Start”. When I run the game it reads: Accessed none trying to read property Rifle. What does that mean? How do I fix it?
I have an event called “SpawnMusket” that it runs as soon I start the game. It supposed to spawn a weapon. Maybe I should set the Rifle reference here? But I can’t.
Also, it says that the target is type weapon, but my musket is type actor.
You have to call this Start function to a concrete instance of weapon for it to work. From what I understand from your description, you’re trying to call the function of the empty variable.
Let’s say you have two or more weapons in your level. The game should know which weapon you want to activate. So you need to set that reference.
Select your variable in the list, and check Instance Editable in details (or just click on a little eye icon next to its name); Not you’ll be able to set its value when you select that another blueprint in the level.
I edited my post. How and where should I set the reference to ‘weapon’ ?
When you spawn it, you have Musket Actor. Is it your weapon? What is Rifle then?
Yes, the Musket Actor is the weapon spawned in the game. I created a variable named Rifle of type ‘weapon’, because the function ‘Start’ expects an object of type ‘weapon’.
Is Musket a subclass of Weapon? If yes, yo can set the weapon variable when you spawn it, with the same value as Musket Actor. If not… well, then you need to rework your setup.
No, musket is just an actor. So, I need to create a child of my Weapon, name it musket and rework everything?
You can go to Musket BP and in class settings select Weapon as parent class. Then you’ll have all Weapon’s functions available in Musket too, just with prefix Event (Event Start, etc.).
If you create such a node and right click it, you can Add Call to Parent Function (in case there’s some behavior that must be executed in all weapon types).
I entered MusketActor BP and selected Weapon as a parent. When I try to connect the object ‘MusketActor’ to the function ‘start’, It says “Actor object reference is not compatible with Weapon object reference”. Maybe I did something wrong? I cannot find this “add call to parent function”. In what node should I look for this option? I’m trying to use “cast to weapon” to see if works.
After you reparent your BP, the variables that you created before that may not work. You can try refreshing them.
I compiled and saved everything. I tried Set MusketActor → Cast to Weapon. So now I can connect the node to my ‘start’ function, but the cast is failing, so I still can’t use the function. OK, so after messing around with the “cast to weapon”, i got it working, thanks for your time and help, Tuerer!!
Let me get this straight.
- You have a base Weapon BP with various functions in it.
- You want to have different weapons in the game, but they all will have certain basic functionality, which is defined in Weapon BP.
- Each weapon will have it’s own additional functionality different from the others.
- You want to be able to call the basic functions, no matter which type of weapon is used.
If it’s correct, then what you have to do is have your Weapon BP as a parent class, and derive all your weapons from it. If changing the Musket’s parent class to Weapon BP doesn’t work, right click on Weapon BP and Create Child Blueprint Class, and make your Musket from it (and all other weapons you’ll have in future). Every custom function you’ve created in Weapon BP will be available in its children.
With Weapon BP being the parent class of your weapons, you’ll be able to call the parent functions for every child BP.
try to use the Action RPG Sample from Epic. 100% free in Marketplace. The sample uses all the logic you need( with C++, BP and the Gameability System).
I’m getting some error. I’m going to create a new post. Link: Gettting "cast failed" and other errors