madeesse
(madeesse)
October 7, 2020, 10:47am
1
I have made a very simple class in c++
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "MyObject.generated.h"
UCLASS(BlueprintType)
class MYPROJECT2_API UMyObject : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 number = 0;
};
and in blueprint, I made an actor
in this actor,I created a variable
then i try to print the value of this class
but in my world,in the message log,it shows the error of “Accessed None trying to read property”
I want to find a solution but i cannot find one.So how to make this possible?
Thanks for your help in advance !
EvilCleric
(EvilCleric)
October 7, 2020, 11:47am
2
You created a variable but you didn’t instantiated it or assigned any object to it. Therefore, its value is still null.
madeesse
(madeesse)
October 7, 2020, 11:52am
3
Yes,I notice that,but how to initialize an object for my own class.I cannot choose the default value for the class in blueprint. And in c++, i think there are Default constructors for my class,so i think it is the problem of the blueprint.
EvilCleric
(EvilCleric)
October 7, 2020, 12:19pm
4
C++ refresh:
class MyClass {...};
MyClass* obj; // it's just a pointer to a MyClass object. It doesn't call any ctor. It doesn't instantiate any object.
To instantiate an UObject (and others):