Announcement

Collapse
No announcement yet.

Data from actors

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Data from actors

    Hello everyone,

    I was creating an inventory for my game. All of my items will be actors with data stored in them as variables. I created an inventory struct with just the actor and the amount as pins. How can I get a variable from an actor without reference to that specific actor? Calling a get or something asks for specific actors and I need one that works for all of them since I will be using a variable.

    For example, I am trying to create a list of things in my inventory. I broke apart the struct and have the actor. How can I extract the name of the item which is stored as a text variable in the actor?

    I figure that I will need to pull data from actors all the time in the future that have no reference to a specific actor.

    #2
    One method would be using Blueprint Interfaces.
    You would make an interface and declare a function like "GetName" that returns the name. You implement it then in your inventory item class.

    Comment


      #3
      Originally posted by ZyronDel View Post
      Hello everyone,

      I was creating an inventory for my game. All of my items will be actors with data stored in them as variables. I created an inventory struct with just the actor and the amount as pins. How can I get a variable from an actor without reference to that specific actor? Calling a get or something asks for specific actors and I need one that works for all of them since I will be using a variable.

      For example, I am trying to create a list of things in my inventory. I broke apart the struct and have the actor. How can I extract the name of the item which is stored as a text variable in the actor?

      I figure that I will need to pull data from actors all the time in the future that have no reference to a specific actor.
      As far as I know, there is no way. If you have spent time studying a programming language, you may know that it can be a pain to get data from other places, as you have to have some sort of reference to them. I believe the only way you can do this is by casting using some sort of reference, are you familiar with casting?
      Marketplace Assets

      Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
      Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
      Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

      Comment


        #4
        As far as I know, there is no way. If you have spent time studying a programming language, you may know that it can be a pain to get data from other places, as you have to have some sort of reference to them.
        He said he has a name reference. So he could use "GetAllActorsFromClass", iterate and inspect until he finds his actor...
        Brute force, but could work...

        Comment


          #5
          In other programming languages, it is difficult to grab variables from other places sometimes. The difference is that when coding with C I can type whatever I want. The blueprint system is a little more restrictive, which I can see helps in a way. If I were to try to pull a variable from an actor that didn't have it, bad things would happen.

          Can I call a function when creating my inventory list with a variable reference to an actor that has the actor as input and text as output which triggers an event inside of the actor that was input that then calls a function inside of that actors blueprint and returns the information to the first function which in turn returns that variable? Also, that run on sentence was confusing.

          So in my function library it would look like this:

          get item name ++++_____+++++++ i dont know how to do this+++++++++++++ReturnNode
          +++++++|>===============<|++++++++++++++ |>==============<| ++++
          ++++item O================O item​||||||||||||| name O===============O Name


          i dont know how to do this would trigger an event in the referenced actor that would call its own function to return the name variable

          I hope you can understand my ramblings. Would this work and if so, how would I go about it?
          Last edited by ZyronDel; 06-25-2015, 09:15 AM.

          Comment


            #6
            So if this is not a thing that is possible, is there another method to store this information? I am fairly certain that people store information on actors or pawns and then retrieve it all the time.

            Comment


              #7
              A change *just* went into the engine today to let you get the ClassDefaults from a class variable reference in blueprints. It will probably be a while though before a release includes it. There's an experimental naive implementation below if you can't wait.

              All you need to do is store a reference to an objects CLASS somewhere and not store the actual object. In that way you can create data structures that use "data only blueprints" to define data that can be used in your scripts.

              For example I just got done making a radial menu system using data-only BP widgets. Each asset is a BP of a custom UIWidget class, and each has a struct of info similar to what you have. Such as the widget name, enums for functionality etc. An array of 'child' widgets. In that way the system can destroy and re-create any menu depth by getting defaults from the classes.

              Ie, if the user selected "Place Objects", all current widgets get destroyed (and I use a "struct" of components for that), then the selected widget children get read as simple class references. Then the BP can create each of the widgets from that data at each step. The nice thing about a system like that is the final menu rendering BP doesn't have to know much of anything about the menu structure and it doesn't need ANY references to start other than a Root Widget link (and the root's only settings are its list of children since the rest never gets used).

              It will probably be a while before that change makes it to an approved build. I am actually on a separate project that does not have the changelist merged yet so I added a VERY PLACEHOLDER BP node to get class defaults. It can be risky since it will give you the ability to WRITE to the default object which you should NOT DO.

              If you need to set up a workflow like this and cant afford to wait a few months here is all you need.

              I added this to "KismetSystemLibrary.cpp" and .h.

              Add to KismetSystemLibrary.cpp (or any of the kismet library files):
              Code:
              //@TODO RYAN REMOVE THIS TEMP FUNCTION AFTER PHILLIP Ks PROPER VERSION IS CHECKED IN!!!!
              UObject* UKismetSystemLibrary::GetDefaultObject(TSubclassOf<UObject> ObjectClass)
              {
              	if (ObjectClass)
              	{
              		return ObjectClass->GetDefaultObject();
              	}
              	return nullptr;
              }
              Add to matching .h file:
              Code:
              	//@TODO RYAN REMOVE THIS TEMP FUNCTION AFTER PHILLIP Ks PROPER VERSION IS CHECKED IN!!!!
              	UFUNCTION(BlueprintCallable, Category = "Utilities|Object")

              Warning once again that this code is experimental and probably can do dangerous things if you do anything besides "Get class defaults". You still have to cast with this node.
              Last edited by RyanB; 06-25-2015, 05:55 PM.
              Ryan Brucks
              Principal Technical Artist, Epic Games

              Comment


                #8
                The other case that comes up a lot is when you have a reference to something and need to cast to its actual object type before you can access any data.
                In those cases you can sometimes make it easier by "pre-casting" which is try to do the cast ahead of time such as on begin play then store an actual object reference so you can access all the variables without casting. May be better for performance and is certainly cleaner in your script.

                I was unsure which case you were talking about so I answered both

                How can I extract the name of the item which is stored as a text variable in the actor?
                If that is your main problem, you should be able to "Cast" to the correct object type. If you first make all of your inventory assets parented off of the same BP (which is just another BP you make first where you add all the struct variables), then you should be able to cast to that shared type for all of them and access the variables. Furthermore you could then refer to each item type simply by "Class" which would be a reference to the class of that exact blueprint name.


                Ie you make first "BaseInventoryClass". This has all the settings all items get.
                Then you made a child of that called "InventoryItem1"

                You should be able to cast InventoryItem1 to "BaseInventoryClass" and access data that way. Then you don't have to worry about what type things are.


                My suggestion with the above "get default objects" is to refine things to the point where all your player needs to know is an array of Classes that are stored in inventory. More efficient unless you need to communicate to the exact item in invetory. If you are actually drawing the items for the most part it may not be any better.
                Last edited by RyanB; 06-25-2015, 06:05 PM.
                Ryan Brucks
                Principal Technical Artist, Epic Games

                Comment


                  #9
                  Thank you very much for your response. I will do a bit of research and attempt to implement your suggestion.

                  My main problem was not having a function to use to get things from a variable. I can get things from a specific actor using a function from that actor, but I am not able to create a function that works on variables.

                  I had tried to make a parent class earlier today and my editor promptly crashed. I will try again.

                  You are much appreciated.
                  Last edited by ZyronDel; 06-25-2015, 08:27 PM.

                  Comment


                    #10
                    I did some experimenting and tried to make a "master class" that is the parent of all. It did not have the desired effect. I could not give all of my actors the same variable names, so a function that would be called would not know what to get. Even if I could, I would have to name the functions all differently. I just need one function to be able to work for all of my actors.

                    Maybe I am not able to explain myself clearly. I am a novice and I think that my problem is relatively simple. I hope that what I want to do is possible. All I want to do is bridge this gap:

                    Click image for larger version

Name:	problem.png
Views:	1
Size:	80.2 KB
ID:	1080661

                    I have several items that I want to pull a variable from using the same function (or some set of functions.)

                    I think that most people, from what I have seen, save their items as actors. I figure that you would want to save some parameters in these items, such as the attack power on a sword for instance. If this is the case, I will probably need to do this very often as I interact with items in the game. If not, is there a better way to go about it?

                    RyanB, I found the new change to be very interesting. I understood about 80% of it. Maybe I will learn more when it is released.
                    Last edited by ZyronDel; 06-25-2015, 11:44 PM.

                    Comment


                      #11
                      Why don't you simply make the properties such as "Item Name" and Type variables within your Inventory Struct? Then any time you add something to inventory you just pass some info about it. It seems like in this case you already have an actor created so there maybe be nothing to benefit from using the class defaults thing.
                      Ryan Brucks
                      Principal Technical Artist, Epic Games

                      Comment


                        #12
                        I had considered that. I wanted to know if I can pull variables from inside of these actors for the future mostly. I would have to add all attributes from every item such as useable, weapons, armor, accessories, etc, and make a huge struct. Then whenever I want to interact with an item, I would have to find it in the struct. It seemed a bit messy. It also raises questions about how to implement equipment and things. I was also worried about how to make pawns interact with things if they could not access data from each other.

                        I will do a bit more research. Thank you for the advice. I was just used to doing one of these -> when I wanted to pull data from something but I understand that actors are different from this.
                        Last edited by ZyronDel; 06-26-2015, 08:10 AM.

                        Comment


                          #13
                          this may help you: http://shootertutorial.com/2015/06/0...ate-inventory/ type can be class.
                          How to create first person shooter game from scratch. Lots of tutorials: http://www.shootertutorial.com - celebrating 50th Tutorial!

                          My Marketplace Assets

                          Comment


                            #14
                            If you just want to pull data directly from the actors you can do a cast to the object type and then get anything.

                            But using the parent class makes this a bit easier since currently you may need a different cast for each unique object type.
                            Ryan Brucks
                            Principal Technical Artist, Epic Games

                            Comment


                              #15
                              I tried using casting but I would have to make a node that casts to a specific thing and I need this to work for any variable.

                              I have just read through the shooter tutorial and it says that he wants to store damage, price, etc in the struct rather than inside of the actor itself. I guess that there is not a way to get data from actors. It's really not about the inventory at all. I wanted to know this for many other applications. I honestly have no idea now how I will make anything interact with anything else or where to store its data. Like the stats of a mob or something.

                              There are probably some things that I do not understand. The way in which I envisioned doing things is likely impossible so I will find a new way.

                              Thank you all for your responses. I appreciate all of your help.
                              Last edited by ZyronDel; 06-26-2015, 04:45 PM.

                              Comment

                              Working...
                              X