Keeping pawns saved in memory

Hi,

Wondering if it’s possible to keep pawns saved in memory for calculations and running events? Last time I tried to save a pawn using “Do Not Spawn” it would be pending kill.

I know this works for actors, wondering if there’s a way for pawns as well. I want pawns to be possessed by AI (or maybe the player) yet kept in memory (or cached) as I can run calculations on where they are, where they’re going, etc)

Wondering if this is possible or if I should keep them in a separate “calculation” variable that has everything the pawn does, but for calculations only and not spawned in world.

what you are saying doesn’t make sense. Can you show us what you mean by “do not spawn?”

The way you mean to “save” a pawn is to store a reference to it. You do this by creating a variable of an object reference and then you set the variable by getting reference to the pawn and passing that into the set node.

You really ought to slow down and take some time to read over the docs about some of this terminology and maybe do a few project based tutorials as well. It might seem like a slow-down but its going to speed up your learning a lot. Right now you are saying a lot of things which indicate you have an incorrect understanding about a lot of key fundamentals.

Here is an example of caching/setting (what you are referring to as saving) a reference to a pawn:

If you hover the cursor over the inputs/outputs on nodes, it will give you information about what sort of type it is expecting. You’ll need to understand the difference between classes and instances, and you also need to understand Unreals basic inheritance hierarchy. E.g. Actor > Pawn > Character.

image

This is an actor. I use as an item. Yes I could use “Objects”, but some items may be spawned and some items may not. I choose “do not spawn” and store it in an inventory. Why would this work if it’s not intended to be accessed afterwards?

And why does it not work in regards to a pawn? When I do it the same way? I’ve looked up a lot of stuff and done tutorials but certain parts of this don’t make much sense.

Here is an example of caching/setting (what you are referring to as saving) a reference to a pawn:

What you are saying does not work if the pawn is unloaded, as that means the pawn “is pending kill”. My point is I’m trying to have a bunch of pawns and such that are unloaded yet still providing data.

Collision handling override is an argument that is using an enumerator to decide what to do when spawning the actor in the case of a collision problem.

Like I said, the sentences you are saying just don’t make sense. The reason is because you are not understanding what a lot of the terminology means. You got to do some prerequisite studying - game dev is too complicated you can’t just make some assumptions about what you think some terms mean and expect that to be valid.

If you can break down what you aim to do into very small steps that can be described by jsut like one sentence, it will be easier to demonstrate how to use the engine to accomplish that, or point to specific resources that contain the prerequisite knowledge you’ll need.

Thanks.

My general point is, I would like to understand how I can keep pawns loaded in memory without them being spawned in the world. If this is not possible, then would I have to create a temporary non-pawn variable?

Who needs to know about the pawn?

1 Like

The player, other pawns, and other actors. Since there will be interactions not in your control.

So what you are saying is, you want some sort of unit/element that has a visual representation at times in the game world, and can be controlled by the player or AI, and it is also associated with some sort of data.

The data should persist even when you don’t need the visual representation of the pawn.

Is that right?

1 Like

Yes that is 100% correct.

Okay, well there is about one billion answers and examples anybody could give to demonstrate something like that. None of them are going to be easy to understand for a beginner because there is a lot of foundational knowledge you have to know first.

Of course it is boring to go and study object oriented design or inheritance and all that stuff, so what I’d recommend is first doing a few project based tutorials that might show anything even remotely related to a similar idea.

Any game with an inventory, or an RTS game, or a survival game, or a shooter game with multiple characters - anything like that is going to cover a lot of the foundational principles you’ll need.

If I could give a quick easy answer I would, but there just isn’t one.

The problem is that you can store reference to a pawn, or any actor. That’s easy, just do like I showed above. But if you destroy the actor, then it’s data is gone. So you need to have a whole system that is managing the relationship between actors and data - the details are going to be project dependent, but no examples anybody could show you will make much sense if you don’t have some solid foundational knowledge about how unreal works and the basics of object orient design.

1 Like

I would like to say I am a software engineer and I am very well aware of how this works. I built the inventory system and many other aspects of my game without many tutorials for those particularly. The only problems are how unreal specifically handles things. So I’ll take your advice and look deeper into how unreal operates.

In comparison to other game engines (unity and godot), it seems much easier to find quick information. But in regards to unreal I think I have to take a different approach and dive deeper into the docs than I ever needed to in other engines.

I do sincerely appreciate you kinda giving me the wake up call that I need. I’ll have to be more adamant about reading deeper into everything

Thank you for your time

Begin Play | Programming | Epic Developer Community (epicgames.com)

you might find that helpful ^^^

like I said, a few key terms you’ll want to understand is:

inheritance hierarchy in unreal, e.g. what is the difference between actor, pawn, character, uobect?

difference between class, object, I think the more broad principle is Object Oriented Design - some real programmers may be able to better describe the unreal framework in more technical terms you might find familiar.

methods for blueprint communication, e.g. how do objects in the game world communicate?

then you’ll want to be familiar with unreals gameplay framework, which provides a number of classes with defined lifespans - this will help you figure out where you can safely store data. Classes like PlayerController, GameMode, GameState, etc.

you’ll also want to be familiar with data assets like data tables, structs, data assets.

1 Like

First of all, seriously appreciate you providing some resources to look into, will definitely check these out.

Yeah, class and object is basically the difference between an instantiated class instance, and the class itself, as far as I understand that hasn’t really changed in unreal lol.

Thanks so much tho!

2 Likes

If you set Do Not Spawn as a collision setting to SpawnActor, and it is unable to spawn because of collision, then nothing will happen, and it will return null/empty.

I … don’t otherwise understand what you’re asking.

Thanks for replying.

It was already cleared up above ^^