C++ class Accessed None trying to read property In blueprint

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

317614-actor.png

in this actor,I created a variable

317615-variable.png

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 !

You created a variable but you didn’t instantiated it or assigned any object to it. Therefore, its value is still null.

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.

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):