Need Help With Data Table

So i am making a spawner actor, for now it looks like this


My problem is there is a booelan in my npc bluprints and i want to get that booelan via this spawner blueprint and change it, how can i manage that?

have you tried casting to your BP, using the structure NPCBlueprint as the Target, then just get your variable from there? (You may need to make sure the variable is instance editable in your BP)

The NPCBlueprint in the structure is a class reference so i cant put that target in to my blueprints cast, but even if i could do that i wouldnt do it. This system will be used in more than at least 10 15 npcs so i cant make another blueprint for each of them, at least until i completely agree that it cannot be done another way.

you can get the default bool from classdefaults but if you want to change it you need to spawn the actor, in which case just expose the bool on spawn

The boolean is not on the class defaults, its in the custom bp that i make under the class. I am tryin to recieve and change that.

so the boolean isn’t actually in your character bp, why not just add it to your game instance, you can get and set a variable from there anywhere

My problem is i have 2 parts of my game, in one of them the player will save an npc from the creatures if he managed to do so the BeenRescued boolean in the npc bp will be true and he will spawn in the other part of the game. So there is not 1 singular npc there are lots of them i am trying to implement a system that i can easily to manage all this by a data table and just a few blueprints. Can i manage that in the game instance?

Yeah, for this case I’d put it in the game instance. It’s as simple as adding variables to it, give them a default value and thats it. No code. Anywhere else you can ‘get game instance’ and get or set the variable. Think of it as a global variable. you can retrieve it from any bp or ui etc. it’s also how you will eventually implement your save system. Any variables you want to be saved should go there too, its easy to use a save game object to get and set from the game instance.

So instead of duplicating variables and making a mess in loads of different bps, you just get the game instance and adjust the variable there. good for global stuff like your example of a world event boolean, other things like ‘speed’ or ‘health’ that will be individual for each instance should go into the npc’s bp - hope this helps

Thank you, should i make another boolean for each npc or it can be made another way?

you dont need to make the boolean again in the npc, that might only confuse things, just get game instance, cast to game instance (plug get game instance into the casts target) and then get the variable. Done.

I didnt tried to say that, lets say i have 2 different npcs, i saved first of them in the second part of my game and set bool to true and he spawned in the other part of my game, should i make another rescued booelan for my second npc?

ah, so this is a question of code it this way or that for whatever outcome you desire, I was just giving you a framework. But in your example:
if you have 2 events where you want to save an npc, with differences to what happens if he saves 1 or 2 or 3 or saved one in this area but not in this other area etc… it depends, for example, instead of a boolean, which will only give you a true or false to work with you could make an integer variable ‘NoOfNPCsSaved’, after saving an NC you just increment the values by 1 (get ‘NoOfNPCsSaved’ > ++ (add 1) > set ‘NoOfNPCsSaved’, now you have a running tally of how many NPCs he’s saved. With that you could check a condition like ( if ‘NoOfNPCsSaved’ is less than or equal to 4 > do this, other wise do that)

that might work if you have an infinite amount of NPCs and events/rewards.

if you have the same reward you could just set the variable to false after you teleport and once he saves the second NPC he’ll set it to true again.

It all depends on exactly what you want to achieve, you could code it so many ways

Some of the npcs will be random some will be not, for example if you finish level 5 you will rescue NPC:A no matter what but if you finish level 6 you will rescue one of the npcs from B,C,D etc.

I see. in this case you could create an array boolean variable. Each index referencing each NPC. Does that make sense?

Thanks for all your help i believe i can do it from here, i am new to unreal, thanks for all your helps <3.

1 Like


1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.