Creation of properties from managed code
See original GitHub issueI have a class deriving from Actor
, with a constructor that looks like:
public class Card : Actor {
public Card(string name = null) : base(name) {
// Set up mesh, material, register events
AddTag("MyTag");
SetInt("MeaningOfLife", 42);
var meaningOfLife = 9001;
var gotIt = GetInt("MeaningOfLife", ref meaningOfLife);
Debug.AddOnScreenMessage(1, 3.0f, Color.Red, $"Meaning of life: {gotIt}; {meaningOfLife}");
}
}
When I play in the editor, it outputs False; 9001
when I’d expect True; 42
.
I’ve played around and moved the GetInt
and SetInt
calls all over, thinking perhaps it was an object lifetime issue, but I can’t seem to get this to ever print out my expectations. Currently I’m instantiating a Card
in OnWorldPostBegin()
. I’ve also tried GetBool
and SetBool
and those didn’t work either – I’m guessing this is broken for all of the method pairs.
The AddTag()
call seems to work – I can see it when I inspect the Details pane with the Card actor selected.
Is this a bug or am I doing something wrong?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:25 (15 by maintainers)
Top Results From Across the Web
Create an Object by Using Managed Code - Configuration ...
Learn how to create a configuration manager object by using managed code, with included examples and links.
Read more >Managed Code Tutorial Example
This tutorial reviews the benefits and advantages of using managed code in .NET applications with Progress DataDirect.
Read more >Python's property(): Add Managed Attributes to Your Classes
In this step-by-step tutorial, you'll learn how to create managed attributes, also known as properties, using Python's property() in your custom classes.
Read more >Can a managed C++ assembly return an object to C#? - ...
I've created a managed C++ assembly which compiles to a DLL. I can call it, with a parameter, from the C# code. It...
Read more >Working with a Managed-Code Action in a Suite/Advanced ...
set_Property—This method sets the value of a new property or changes the value of an existing property in the currently running Suite/Advanced UI...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems that now we have Data Registries which can be used as an intermediate type-safe data storage. It’s introduced in Unreal Engine 5 and 4.27.0, so I’m going to investigate it.
Thank you! I just figured that out on my own. 😃
Is this the recommended way to maintain state on a subclassed Actor? I’d rather not make Blueprint classes that are just property bags, if you will. It doesn’t feel like the native C# way of doing things.
For example, I handle
OnActorBeginCursorOver(ActorReference actor)
and I doactor.ToActor<Card>().SomeProperty
andSomeProperty
is reset to its default value because you’re callingFormatterServices.GetUninitializedObject(...)
, and thus the instance you give me isn’t the same one as I originally instantiated. Do I need to maintain a… dictionary of objects by ID and then take the actor you give me and then just look it up and use that? Or should I actually create blueprint instances for each object and dynamically look up/set properties in C++ land each time?