Custom Eventを他のBPから実行させる仕組みを調べているのですが、”accessed none trying to read property”となって実行できません。
Test1というActorBPからTest2の持っているPrintString「It’s Box2」を実行させたいのですが、どうすればいいでしょうか?
ohayou
hmm “accessed none” means that the variable is “empty”. you need to set the value.
sometimes through “GetActorOfClass”, but usually a “Soft Object Pointer” is more suitable. i recommend SoftObjectPointer whenever possible.
beware though, that calling functions or triggering events on “BeginPlay” is dangerous. since you don’t know the order in which the actors get initialized. Sometimes BeginPlay could be among several frames (this is a bit advanced).
I recommend to way a frame at least. you can use SetTimerForNextTick or delay for next tick.
from what you are doing, maybe you want to make a “Manager” or “subsystem” class that has events.
What i usually do is
- have a custom game mode
- in the game mode i make sure to obtain a reference to the managers, or spawn them (get actor of class or soft pointers).
- make sure that i initialize things properly. (e.g. wait for the objects to be loaded, or initialize them if i need to).
- have a variable or function that returns the managers. so that other actors can obtain the manager.
im very sorry that my japanese is very bad. i hope this helps.
here’s translated,
おはよう
「accessed none」は変数が「空」であることを意味します。値を設定する必要があります。
「GetActorOfClass」を使う場合もありますが、通常は「Soft Object Pointer」の方が適しています。可能な限りSoftObjectPointerを使用することをお勧めします。
ただし、「BeginPlay」で関数を呼び出したりイベントをトリガーしたりするのは危険です。アクターが初期化される順序がわからないためです。
BeginPlayは複数のフレームにまたがる場合があります(これは少し高度な話です)。 少なくとも1フレームは実行することをお勧めします。
SetTimerForNextTickを使うか、次のティックを遅延させることができます。
あなたのやっていることを考えると、イベントを持つ「Manager」または「subsystem」クラスを作成したいのかもしれません。 私が普段やっているのは、 カスタムゲームモードを用意することです。 ゲームモードでは、マネージャーへの参照を取得するか、マネージャーを生成するようにします(クラスのアクターまたはソフトポインタを取得します)。
適切に初期化するようにしてください。 (例: オブジェクトがロードされるのを待つ、または必要に応じて初期化する)。 マネージャーを返す変数または関数を用意してください。これにより、他のアクターがマネージャーを取得できるようになります。
私の日本語がとても下手で申し訳ありません。お役に立てれば幸いです。