get all actor of at random class

So, my problem is a bit complicated. I’m trying to do a pet system, where te player can buy some pets who gives him a special ability. The player can buy the pets in a store, and here is my problem. I would like to do a system where there is only one buyable pet, and this pet is choosen between all the differents pets that i made. Every 10 minutes, the pet buyable will be randozimed again. So my question is, how can i use the ‘‘get all actor from class’’ node but with a randomized class between all of my pets ? (I need the ‘‘get all actor of class’’ node to show the name, the picture, the description, etc of the pet who is buyable).

A different way of doing it could be, let’s say you have all the Pets in single Array (Not sure if yours is a struct with all the pet details), then you could get a Pet based on Random integer between the first index and last index.

make the class pin to GetAllActorFromClass a variable. Select this randomly from an array of classes.

You should make a master blueprint class called say BP_Pet, put all your stuff that all the pets have in this class, such as health or age or whatever. Then right click on it in the content browser and click Make Child Blueprint, you can then make this say a BP_Pet_Dog name. Then set the mesh of this class to be a dog, this dog can have different blueprint graphs to say a BP_Pet_Cat.

When you do this, when you say GetAllActorsOfClass, you get all BP_Pet actors, this will also return all BP_Pet_Dog and BP_Pet_Cats

This is the most effective and efficient way to build your systems.

First, thanks to all of you ! I have two questions, how to do an array of classes ? And for the child / parent blueprint, how would i be able to get the information of the health of a random pet between all the different pets’ health do display it on the buy screen for exemple ?

Here is an exemple. I’m trying to display the name of the random pet buyable. So, i made an array with all of my pets in it, but i can’t get the name variable of the pet who is selected randomly, why ?

from that get now, try to do a “cast to” you BP class first, and then you will be able to access the variables.

from the “Get” that is getting from the pet list, drag and look for “get class defaults” that should give you the name and all other variables you have that are set “expose on spawn” and “editable”.

you don’t need get all actor of class by the way.

only the array of the pets and get as well as the random int, get class defaults.

So, i tried to do what you guys said but it seems that the variables doesn’t appears…?

ok now its really dumb.

show us “Pet List” Variable please.

how did you make that variable?

is there a master class? children of the parent pet list?

make sure the pet name variable in the “pet” blueprint you have has expose on spawn checked in the details panel.

1- make a new blueprint actor and call it Pet_Master,

2- inside the new blueprint “Pet_Master” create a text variable and call it “Pet Name”, expose on spawn checked as well and leave it empty.

3- close “Pet_Master” and on the Content folder, right click on “Pet_Master” and click create child blueprint and call it “Fairy_Pet” or whatever, do this 5 - 4 times as much pets you want but make sure they are children of “Pet_Master”.

4- In your “Pet_Shop_HUD” click on your “Pet_List” Variable and change it to “Pet_Master”.

5- add the pet children you created to the array.

finally test “Get Class Defaults”.

Note: to set the pet names has to be done in each child blueprint NOT from the “Pet_Master” but each blueprint child you created. you will see the variable when you click on the component (Self) as a default variable.

So, as you can see in the first screen, it doesn’t works… So, i’m giving you some screens of everything you need to help me to found the problem, I probably made something wrong. I would like to say thanks for your time, it’s very kind :slight_smile:

my friend.

the Pet_List Variable shouldn’t be an “Actor”!!!

change it from “Actor” To “Pet_Master” please and test again and I think I’ve told you to do so before!!!

the variable type my friend change it to “Pet_Master” instead of “Actor”

4- In your “Pet_Shop_HUD” click on your “Pet_List” Variable and change it to “Pet_Master”.

the variable type*

I have no idea what you are doing but this is wrong.

it will get a random pet name every tick. instead you want it to randomize the pet on purchase and then send the information to keep the pet name and values for the hud to show.

So now it’s working ! Great, step by step haha. So now, how could i have a random pet name between all of my pets choosen to be displayed ?

you changed it to object reference didn’t you?

my head is about to explode! make it a class reference instead of object reference.

your coding is all wrong.

when you purchase a pet as you descripted before it should randomize it and gives you a value or name, and from there you can set the variables in the HUD.

now if you hit play it will shuffle all of your pets names by random the way you coding it.

**my advise is. learn more in the engine from tutorials and courses before you attempt doing anything, because at this stat of knowledge you wont get anywhere. **

you need to put this coding above in the shop when you purchase a pet so it randomize the purchase for you when you buy it.

so you have many ways of doing so.

but I’m giving out the idea for you, so when you purchase a pet and you deduct money from the character and the transaction is completed you also want to make a function that gets the name or the pets values in the character to pass to the HUD.

for further assistant I would like to see more screen shots of :

1- The Shop Blueprint

2- Character Blueprint