typecasting ;(

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
Typecasting always works like this:

ClassToTypecastTo(ObjectToTypecast).PropertyToAccess

or

ClassToTypecastTo(ThingToGetObjectFrom.ObjectToTypecast).PropertyToAccess
 

Evil-Devil

silence
Jun 17, 2002
74
0
0
41
somewhere in Germany
evil-devil.com
Wormbo said:
Typecasting always works like this:
ClassToTypecastTo(ObjectToTypecast).PropertyToAccess
or
ClassToTypecastTo(ThingToGetObjectFrom.ObjectToTypecast).PropertyToAccess

Just need some little explanation.
I got two classes. One is SC_Crystal and the other SC_Blue_Crystal. The blue crystal one is a subclass of crystal. and two references. one called just crystal, and the other blue_crystal.
no i take a for loop through the navigiationpointlist and check if there is one of my crystals or blue ones

Code:
[...]
// NP is the reference to NavigationPoint
// if...found crystal -> works
Crystal = SC_Crystall(NP);

// if...found blue crystal --> works
Blue_Crystal = SC_Blue_Crystal(NP);

// if found blue crystal (another bsp) -> wont works
Blue_Crystal = SC_Crystal(NP);
[...]

Can i only cast objects which belongs to their reference? cause the third cast doesn´t work as shown in the comment.

Just want to know why.

Evil
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
The cast itself works well, the compiler moans about a different problem: You can only assign objects of the same class or a sbuclass to a variable.
Your Crystal variable can hold any SC_Crystal and any subclass of it, like SC_Blue_Crystal, but you can't assign an SC_Crystal to the Blue_Crystal variable because it's not a subclass of SC_Blue_Crystal.
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
Evil-Devil said:
ok, thats clear to me. but in the first tries i also tried to set Crystal = SC_Blue_Crystal(NP) and it even gives me an access none. weird, isn´t it?
That statement can't give any Accessed Nones directly, only if NP isn't an SC_Blue_Crystal. If NP is an SC_Crystal (i.e. not an SC_Blue_Crystal) the typecasting result is None, which gets assigned to Crystal.